Skip to content

fix: live trace streaming, final-output capture, and root-span duration#2

Merged
XinweiHe merged 1 commit into
mainfrom
fix/live-streaming-output-and-root-duration
Jul 1, 2026
Merged

fix: live trace streaming, final-output capture, and root-span duration#2
XinweiHe merged 1 commit into
mainfrom
fix/live-streaming-output-and-root-duration

Conversation

@XinweiHe

@XinweiHe XinweiHe commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

One wave of fixes for the Codex tracing plugin, all surfaced during prod e2e testing.

What this fixes

  • Live streaming — a running turn no longer emits a completed root span, so the backend keeps the live SSE stream open instead of treating the trace as finished on the first hook. Traces now update in the UI without a manual refresh. The "Codex Turn" title is preserved during the live window via the span-path attribute.
  • Final output capture — the turn's final output is now read from the agent_message event, which Codex writes before the terminal task_complete (which lands just after the Stop hook fires). Live runs previously showed empty output; task_complete still refines it when present.
  • Root span duration — the root span's end time is computed from the latest step/tool activity, so aborted or live-snapshot turns span their children instead of rendering a 0ms bar.
  • README install steps — corrected to codex plugin marketplace add + codex plugin add, and features.hooks.

Verification

  • pnpm typecheck clean, 72 unit tests pass, dist bundle rebuilt (drift guard in sync).
  • Validated against prod: live SSE stays open mid-turn and completes on Stop; output captured on a real run; 0ms → real duration on a multi-subagent run; three of the fixes confirmed on live traces.

Screenshots

Screenshot 2026-06-30 at 11 03 01 PM

Notes

  • No new release/tag required — the plugin installs from the default branch and runs the committed dist/index.mjs directly; merging updates it.

Tracked by traceroot-ai/traceroot#1401


Summary by cubic

Fixes live trace streaming, final output capture, and root span duration in the Codex tracing plugin so traces update live without refresh and show accurate data. Improves reliability and correctness in production.

  • Bug Fixes
    • Live streaming: emit the root span only on Stop to keep the SSE stream open; added traceroot.span.path so the trace stays titled "Codex Turn" while live.
    • Final output: capture from agent_message; task_complete still refines when present.
    • Root duration: set end time to the latest step/tool activity to avoid 0ms roots on aborted/snapshot turns.
    • Docs: corrected install steps to codex plugin marketplace add + codex plugin add, and enabling features.hooks.

Written for commit dc94e00. Summary will update on new commits.

Review in cubic

…ration

- Defer the root span to the Stop hook so a running turn leaves no completed
  root in ClickHouse — the backend keeps the live SSE stream open instead of
  treating the trace as done on the first hook (no more manual refresh). The
  "Codex Turn" title is preserved during the live window via traceroot.span.path.
- Capture the turn's final output from the agent_message event (Codex writes it
  before the terminal task_complete, which lands just after the Stop hook fires),
  so live runs no longer show empty output; task_complete still refines it.
- Compute the root span end from the latest step/tool activity so aborted or
  live-snapshot turns span their children instead of rendering a 0ms bar.
- Fix the README install steps (codex plugin add + features.hooks).

Verified against prod and with unit tests (72 pass). Rebuilt dist bundle.

Refs traceroot-ai/traceroot#1401

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 8 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="plugins/tracing/src/spans.ts">

<violation number="1" location="plugins/tracing/src/spans.ts:91">
P2: Root end time still ignores nested subagent spans. Parent trace roots can render too short whenever a child rollout outlives the parent turn's own steps/tools.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

// render as a 0ms bar. Cover the turn's own steps and tool calls (including
// wait_agent, which ends when a spawned subagent finishes) so the root always
// spans its children — and grows correctly across live hooks.
let rootEnd = turn.endTime;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Root end time still ignores nested subagent spans. Parent trace roots can render too short whenever a child rollout outlives the parent turn's own steps/tools.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At plugins/tracing/src/spans.ts, line 91:

<comment>Root end time still ignores nested subagent spans. Parent trace roots can render too short whenever a child rollout outlives the parent turn's own steps/tools.</comment>

<file context>
@@ -71,14 +82,31 @@ export function planTurnSpans(sessionMeta: SessionMeta, turn: Turn, ctx: EmitCtx
+  // render as a 0ms bar. Cover the turn's own steps and tool calls (including
+  // wait_agent, which ends when a spawned subagent finishes) so the root always
+  // spans its children — and grows correctly across live hooks.
+  let rootEnd = turn.endTime;
+  for (const step of turn.steps) {
+    if (step.endTime > rootEnd) rootEnd = step.endTime;
</file context>

@XinweiHe
XinweiHe merged commit 77343e2 into main Jul 1, 2026
6 checks passed
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