Skip to content

fix(agent): restore Turn timing in conversation history - #6787

Merged
Astro-Han merged 2 commits into
rust-previewfrom
fix/agent-turn-timing
Nov 11, 2026
Merged

Astro-Han merged 2 commits into
rust-previewfrom
fix/agent-turn-timing

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#6713 removed the event-log transcript index that supplied each history row's Turn timing (platform/event-log/src/transcript/timing.rs) and left the new history projection writing timing: None. Since then the Workbench has had no Turn boundaries: a running Turn reads Working… however long it runs, and a finished Turn shows only its activity counts (7 thoughts · 25 tools) instead of Worked for 5m 12s · …, Stopped after … or Failed after ….

Timing is now derived from canonical facts that both history sources already hold. A Turn is one Run: it starts at the Run's admission and ends at its RunTerminated fact, whose Terminal gives the outcome.

  • Live history finds the termination through the existing agent_session_history run/kind index.
  • Snapshots seek the Run's run_terminated entry through the existing agent_history_snapshot_metrics_attempt index. Every readable snapshot has passed ensure_metrics_metadata, so fact_kind is set.
  • The row projection caches the timing with the Run source it already loads. A page costs one extra lookup per Run and never replays or scans a Run's facts.
  • Every fragment of a row keeps its Turn's timing, as before feat(agent): add durable execution and interruption recovery #6713. fragment_metadata had started clearing it after the first fragment, and the Workbench takes each fragment's timing as the row's, so a long answer read from its tail still lost its duration.

No new table, index or migration, and the wire contract and the Workbench are unchanged.

Verification

  • cargo nextest run -p maka-agent-native -E 'test(history_shows_only_the_final_model_failure) | test(named_cell_tools_survive_receipt_only_pages_and_frozen_history)': 2 passed.
    • The first now asserts that a running Turn has a start and no end, and that the same Turn later reports a completed or failed end at or after its start, on every row of the page.
    • It also freezes a snapshot after termination and expects the same timing from it.
    • The second asserts that a snapshot frozen while the Run is still running reports the same unfinished timing as live history.
    • Both fail on the base, where every row has no timing.
  • cargo clippy -p maka-agent-state -p maka-agent-native --tests --no-deps -- -D warnings and cargo fmt --all -- --check: clean.
  • Not run locally: the full workspace suites. Left to CI.

Completed Turn in the native desktop test renderer (desktop_lists_a_scripts_tool_calls_in_place_of_the_script), 960×640 dark, same tree with the base's plugins/agent on the left and this PR on the right:

Completed Turn header, before and after

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code (Claude Opus 5.5) traced the regression to #6713, implemented the fix and the test assertions, and ran the checks above. An adversarial review by GPT-6.1-Sol (Codex CLI) found the fragment clearing and the snapshot scan, both fixed here. The commits carry a Generated-by trailer.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

#6713 removed the event-log transcript index that supplied each history
row's Turn timing and left the new projection writing `timing: None`.
The Workbench then lost every duration: a running Turn read "Working…"
forever and a finished one showed only its activity counts, without
"Worked for", "Stopped after" or "Failed after".

Timing is now derived from the canonical facts both history sources
already hold: a Turn starts at its Run's admission and ends at its
RunTerminated fact, whose Terminal gives the outcome. Live history finds
that fact through the existing run/kind index; snapshots scan the Run's
step-less facts, since their fact_kind column may not be backfilled. The
row projection caches the result with the Run source, so a page costs
one extra lookup per Run and never replays a Run's facts.

The history service tests now assert timing for running, completed and
failed Turns and that a frozen snapshot reports the same timing as live
history, so dropping it again fails CI.

Generated-by: Claude Code (Claude Opus 5.5)
Turn timing describes the whole Turn at the page's fence, not a text
offset, but `fragment_metadata` cleared it on every fragment after the
first. The Workbench takes each fragment's timing as the row's, so a
long answer read from its tail, or extended by later fragments, still
lost its duration. Every fragment now keeps it, as before #6713.

A snapshot found a Run's termination by decoding each of its step-less
facts, which include every executor output delta, so a page could decode
a long Run's whole output. Every readable snapshot has passed
`ensure_metrics_metadata`, so `fact_kind` is always set; the lookup now
seeks `run_terminated` through the existing per-attempt index and
decodes one fact.

The completed and failed Turn test now also freezes a snapshot after
termination and expects the same timing as live history.

Generated-by: Claude Code (Claude Opus 5.5)
@Astro-Han
Astro-Han marked this pull request as ready for review November 11, 2026 08:32
@Astro-Han
Astro-Han merged commit e1a2404 into rust-preview Nov 11, 2026
@Astro-Han
Astro-Han deleted the fix/agent-turn-timing branch November 11, 2026 08:32
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