fix(dashboard): span-close turn aggregator + active-session State pick#158
Merged
fix(dashboard): span-close turn aggregator + active-session State pick#158
Conversation
Two OTEL dashboard bugs from the 2026-04-24 playtest
(sq-playtest-pingpong lines 582, 598).
Bug 1 — Turns counter stuck at 0, Timeline / Timing / Prompt / Lore
empty. Root cause: the aggregator only counted the semantic
`turn_complete` event, which stopped reaching the stream in live
traffic. OTEL span closes (`orchestrator.process_action`,
`turn.agent_llm.inference`, `narrator.canonical_leak_audit`) kept
flowing — Console + Subsystems tabs filled while every per-turn tab
stayed empty.
Fix: treat `agent_span_close { name: "orchestrator.process_action" }`
as the canonical turn boundary. Accumulate `turn_id` / `player_id` /
genre / world from `narrator.canonical_leak_audit` (carries
`turn_id=<genre>:<world>:<player>:<N>`) and inference duration from
`turn.agent_llm.inference`, then synthesize a `turn_complete`
WatcherEvent on the `orchestrator.process_action` close. Dedupe by
`turn_id` so a late semantic `turn_complete` replaces the synthesized
entry rather than double-counting.
Bug 2 — State tab reads the first session from /api/debug/state,
which with multiple saves was usually the OLDEST save instead of the
active one. StateTab now picks the session with the largest
`last_activity_ts` (new field on `SessionStateView`; server-side sort
is handled in the paired server PR).
Wiring tests:
- increments Turns counter when orchestrator.process_action closes
(feeds the exact 3-event sequence seen in playtest console logs)
- does not double-count when a real turn_complete follows a
synthesized one for the same turn_id
- State tab picks the most-recently-touched session by last_activity_ts
- State tab falls back to first entry when last_activity_ts absent
(back-compat with un-deployed servers)
Paired with sidequest-server PR #39 for the server-side sort +
`?session_key=` filter, plus the local_dm JSON extraction fix.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two OTEL dashboard bugs from the 2026-04-24 playtest (
sq-playtest-pingponglines 582, 598).turn_completeevent that stopped arriving in live traffic. Span closes kept flowing, so Console + Subsystems worked while every per-turn tab stayed empty. The reducer now treatsagent_span_close { name: "orchestrator.process_action" }as the canonical turn boundary, accumulatingturn_id/player_id/ genre / world fromnarrator.canonical_leak_auditand duration fromturn.agent_llm.inference, then synthesizing aturn_completeon the process-action close. A late semanticturn_completefor the sameturn_idreplaces the synthesized entry instead of double-counting.debugState[0]landed on the oldest save. StateTab now picks the entry with the largestlast_activity_ts(new optional field onSessionStateView; the paired server PR populates it).Test plan
npx vitest run src/components/Dashboard— 19 tests pass (4 new)/#/dashboard; header Turns counter increments; Timeline populates with a row; Timing p95 leaves—Wiring tests added:
DashboardApp-event-parsing.test.tsx— span-close sequence increments Turns; dedupe on late semanticturn_completeStateTab.test.tsx— picks bylast_activity_ts; falls back to index 0 when field absent (back-compat with un-deployed servers)Paired with sidequest-server PR slabgorb/sidequest-server#39 for the server-side mtime sort,
?session_key=filter, and local_dm JSON extraction fix.🤖 Generated with Claude Code