Skip to content

feat(util-genai): streaming Event Log → Trace conversion (TurnStreamSession)#58

Open
fangxiu-wf wants to merge 1 commit into
mainfrom
feat/streaming-turn-conversion
Open

feat(util-genai): streaming Event Log → Trace conversion (TurnStreamSession)#58
fangxiu-wf wants to merge 1 commit into
mainfrom
feat/streaming-turn-conversion

Conversation

@fangxiu-wf

Copy link
Copy Markdown
Collaborator

Summary

  • Add createTurnStreamSession / TurnStreamSession: incremental per-turn conversion where ENTRY/AGENT stay open and each complete step converts + exports (then frees) its child spans as it finalizes, closed at end() with turn-level aggregates. Memory decouples from the number of steps in a turn, bounding the OOM risk on very long turns (thousands of ReAct steps).
  • graceSteps (default 2) look-back window tolerates bounded out-of-order emission; lateDroppedRecordCount + LATE_STEP_DROP warning make overflow observable; pendingRecordCount probe exposes buffered retention.
  • SPEC §2.5 documents the step-ordering expectation for streaming consumers (batch conversion stays order-independent).
  • Extract shared accumulateResponseUsage / usageFieldsFromAcc so batch buildInvokeAgentInvocation and the streaming session use one token aggregation; export parseInputMessages / parseOutputMessages.
  • Batch convertEventLogToTrace / convertTurn unchanged — streaming is an independent API.
  • Bump 0.1.0-beta.11.

Test plan

  • npm run build passes
  • npm test green — 222 tests (221 passed + 1 skipped; the skipped heap test runs under NODE_OPTIONS=--expose-gc)
  • New turn-stream.test.ts: incremental export, subagent nesting across fragmented pushes, grace-window tolerance of distance-1 cross-batch interleaving, late-drop counting/warning, parent_span_id linkage, trace_id resolution, strict mode, and per-span equivalence vs convertEventLogToTrace (structure / AGENT tokens / LLM input.messages / startTime / warnings)
  • New turn-stream.memory.test.ts: pendingRecordCount bounded and independent of turn size (N=1000 vs 5000); heap bounded under production config (BatchSpanProcessor + async)

🤖 Generated with Claude Code

…ession)

Add createTurnStreamSession/TurnStreamSession for incremental per-turn
conversion: ENTRY/AGENT are opened on first push and kept open, each
complete step converts and exports (then frees) its child spans as it
finalizes, and ENTRY/AGENT close on end() with turn-level aggregates.
Memory decouples from the number of steps in a turn (bounds the OOM risk
on very long turns with thousands of ReAct steps).

- graceSteps (default 2) look-back window tolerates bounded out-of-order
  emission; lateDroppedRecordCount + LATE_STEP_DROP warning make overflow
  observable; pendingRecordCount probe exposes buffered retention.
- SPEC §2.5 documents the step-ordering expectation for streaming
  consumers (batch conversion remains order-independent).
- Extract shared accumulateResponseUsage/usageFieldsFromAcc so batch
  buildInvokeAgentInvocation and the streaming session share one token
  aggregation; export parseInputMessages/parseOutputMessages.
- Batch convertEventLogToTrace/convertTurn unchanged; streaming is an
  independent API validated by per-span equivalence tests.
- bump 0.1.0-beta.11

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@fangxiu-wf
fangxiu-wf force-pushed the feat/streaming-turn-conversion branch from f910a5c to bfcc26d Compare July 21, 2026 08:59
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.

1 participant