Skip to content

feat(o11y): track ingest version in session metrics + type safety and test coverage#57

Merged
iscekic merged 10 commits intomainfrom
write-ingest-version-to-ae
Feb 8, 2026
Merged

feat(o11y): track ingest version in session metrics + type safety and test coverage#57
iscekic merged 10 commits intomainfrom
write-ingest-version-to-ae

Conversation

@iscekic
Copy link
Copy Markdown
Contributor

@iscekic iscekic commented Feb 7, 2026

Summary

  • Add ingestVersion field to session metrics to track which version of the ingestion system processed each session
  • Tighten IngestMetaKey and writeIngestMetaIfChanged types for compile-time safety
  • Add unit tests across both cloudflare-o11y and cloudflare-session-ingest workers

Changes

Feature: ingest version tracking

  • Add ingestVersion to SessionMetricsParamsSchema
  • Store ingestVersion in ingest_meta table during session initialization
  • Pass ingestVersion through to metrics emission
  • Map ingestVersion to double11 in Analytics Engine

Rolling deploy safety

  • ingestVersion defaults to 0 in the Zod schema so older cloudflare-session-ingest workers that don't send the field won't fail RPC validation when cloudflare-o11y is deployed first

Refactor: IngestMetaKey type safety

  • Expand IngestMetaKey to be the authoritative union of all 9 keys in the ingest_meta table
  • Introduce ExtractableMetaKey for the 4 item-extracted metadata keys (title, parentId, platform, orgId)
  • Narrow writeIngestMetaIfChanged to require key: IngestMetaKey and incomingValue: string | null (no more undefined)
  • Filter undefined values at call sites before invoking the helper

Tests added

  • cloudflare-o11y: computeBurnRate, dimensionKey, rowsToMap, effectiveSeverity (exported and tested)
  • cloudflare-o11y: ingestVersion defaults to 0 when omitted from RPC params
  • cloudflare-session-ingest:
    • Ingest meta extractors (title, parentId, platform, orgId normalization)
    • getItemIdentity (all 8 item types + unknown type error)
    • buildSharedSessionSnapshot (empty input, message ordering, part buffering)
    • withDORetry (success, retryable/non-retryable errors, fresh stubs, exhaustion)
    • computeSessionMetrics edge cases (negative duration clamping, TTFR with missing messages, last-wins semantics)

Add ingestVersion field to session metrics to track which version of the ingestion system processed each session. The version is persisted in the SessionIngestDO metadata and included in all metrics emissions.

- Add ingestVersion to SessionMetricsParams schema
- Store ingestVersion in ingest_meta table during session initialization
- Pass ingestVersion through to metrics emission
- Map ingestVersion to double11 in Analytics Engine
- Update tests to include ingestVersion field
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Feb 7, 2026

Code Review Summary

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 4
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
cloudflare-o11y/src/session-metrics-schema.ts 38 Ensure ingestVersion optionality/defaulting matches RPC/service-binding expectations
cloudflare-session-ingest/src/dos/SessionIngestDO.ts 123 ingestVersion is persisted as a string without normalization (can allow unexpected values)
cloudflare-session-ingest/src/dos/SessionIngestDO.ts 302 closeReason loaded from ingest_meta is not validated before being treated as TerminationReason
cloudflare-session-ingest/src/dos/SessionIngestDO.ts 303 ingestVersion loaded from ingest_meta can be negative
Files Reviewed (12 files)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an ingestVersion field to emitted session metrics so downstream Analytics Engine data points can be attributed to the ingest version that processed the session.

Changes:

  • Add ingestVersion to the o11y RPC/session metrics schema and AE datapoint mapping (double11).
  • Persist ingestVersion in SessionIngestDO metadata and include it in metrics emission (including alarm recovery).
  • Update o11y unit tests to include/assert the additional double.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cloudflare-session-ingest/src/o11y-binding.d.ts Extends the service binding RPC param type with ingestVersion.
cloudflare-session-ingest/src/dos/SessionIngestDO.ts Persists ingestVersion in ingest_meta and passes it through to ingestSessionMetrics.
cloudflare-o11y/src/session-metrics-schema.ts Adds ingestVersion to the validated session metrics payload schema.
cloudflare-o11y/src/session-metrics-analytics.ts Appends ingestVersion into the AE doubles array as double11.
cloudflare-o11y/test/index.spec.ts Updates test fixtures and expected AE datapoint doubles to include ingestVersion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cloudflare-o11y/src/session-metrics-schema.ts
…Changed types

Expand IngestMetaKey to cover all 9 keys stored in ingest_meta table,
introduce ExtractableMetaKey for the 4 item-extracted keys, and narrow
writeIngestMetaIfChanged to reject undefined values and require typed keys.
Export and test computeBurnRate, dimensionKey, rowsToMap, and
effectiveSeverity — pure functions that were previously module-private
and untested.
Cover extractNormalizedTitleFromItem, extractNormalizedParentIdFromItem,
extractNormalizedPlatformFromItem, and extractNormalizedOrgIdFromItem
including normalization edge cases (empty, whitespace, null, non-string).
Cover all 8 item types and the unknown-type error path.
Cover empty input, session info, message ordering, part attachment,
buffered parts arriving before their message, mixed ordering, and
silently ignored item types.
Cover first-try success, retryable error with eventual success, fresh
stub per attempt, all attempts exhausted, non-retryable immediate throw,
non-Error wrapping, and maxAttempts config.
Cover negative duration clamping, undefined timeToFirstResponseMs when
only user or only assistant messages exist, last-wins for multiple
kilo_meta and session items, and TTFR clamping when assistant precedes
user.
@iscekic iscekic changed the title feat(o11y): track ingest version in session metrics feat(o11y): track ingest version in session metrics + type safety and test coverage Feb 7, 2026
Comment thread cloudflare-session-ingest/src/dos/SessionIngestDO.ts
Comment thread cloudflare-session-ingest/src/dos/SessionIngestDO.ts
Comment thread cloudflare-session-ingest/src/dos/SessionIngestDO.ts
@iscekic iscekic merged commit b2bfa09 into main Feb 8, 2026
11 checks passed
@iscekic iscekic deleted the write-ingest-version-to-ae branch February 8, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants