Skip to content

fix(cli): emit single JSON document from session show with sidechains - #61

Merged
zawakin merged 1 commit into
mainfrom
fix/session-show-single-json-doc
Jul 10, 2026
Merged

fix(cli): emit single JSON document from session show with sidechains#61
zawakin merged 1 commit into
mainfrom
fix/session-show-single-json-doc

Conversation

@zawakin

@zawakin zawakin commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

agtrace session show <id> --format json produced invalid JSON when the session contained sidechains (subagent streams). Each stream was rendered as a separate JSON document, with text separators printed between them:

{ ...main stream... }

────────────────────────────────────────
Additional Stream: sidechain:a1da8e6a… (spawned by Turn #2, Step #2)

{ ...sidechain stream... }

Root cause: handlers/session_show.rs looped over streams calling ctx.render() once per stream and println!-ing separators unconditionally — bypassing the format abstraction entirely.

Fix (schema-level redesign)

One session show invocation now produces exactly one view model → one document, in every format:

  • New schema: SessionDetailViewModel { session, streams[] } replaces the per-stream SessionAnalysisViewModel/SessionHeader. Session-scoped metadata (id, provider, project, log files) appears once; each stream carries its own stream_id, spawned_by (raw 0-based indices), status, context_summary, and turns.
  • Presenter (present_session_detail) takes all assembled streams, orders them Main-first, and attaches subagent children to the main stream.
  • View (SessionDetailView) owns the text-mode stream separators/headings that the handler previously printed — the handler no longer prints anything itself.
  • agtrace-sdk now re-exports SpawnContext so the CLI can consume it through the SDK boundary.

Verification

  • Regression test: 3-stream view model serializes to a single parseable JSON document.
  • E2E on the exact session that produced the broken dump (main + 3 sidechains): output is now one valid JSON document with content.streams[4], each sidechain carrying structured spawned_by. Text mode still renders per-stream sections with separators.
  • cargo test: all pass. Clippy is clean on 1.90.0 (the 6 pre-existing warnings visible on newer local toolchains also exist on main).

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zawakin zawakin self-assigned this Jul 10, 2026
@zawakin
zawakin merged commit 9c2094f into main Jul 10, 2026
8 checks passed
@zawakin
zawakin deleted the fix/session-show-single-json-doc branch July 10, 2026 07:39
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