Skip to content

FE-2419: Show reasoning time, reply timing and cost per step in Brunch's turn diagnostics - #10705

Draft
lunelson wants to merge 7 commits into
mainfrom
ln/fe-2419-turn-diagnostics
Draft

lunelson wants to merge 7 commits into
mainfrom
ln/fe-2419-turn-diagnostics

Conversation

@lunelson

@lunelson lunelson commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🌟 Purpose

Brunch's diagnostics can't say where a model step's time goes. diagnose and the run packet each report one wait before a step's first output, and that figure mixes time inside a reasoning block, tool arguments the provider delivers in one burst, and everything else. diagnose's "time until the response started" is the time to the provider's HTTP response, so it reads about half a second however long the model then takes.

A staging or production turn is also harder to read than a local run: reasoning and cost were kept only in the conversation's stored records, which diagnose doesn't read.

This PR makes the per-submission chronology log line, diagnose and the run packet report, per model step, the time spent in reasoning blocks, when the reply text streamed, tokens with reasoning apart, and the catalogue cost estimate. It makes diagnose --submission work for a submission older than seven days. And it stops a persona run losing the spans of its last turn when its launcher stops the server.

🔍 Changes

  • Chronology log line (observe-turn-chronology.ts): each step gains the time in reasoning blocks and their count, the reply text's first and last delta, cache-write tokens, reasoning tokens and Pi's catalogue cost estimate. The content policy is unchanged: ids, counts, durations and classifications only. Reasoning tokens come from the message_end observation, which carries Pi's raw usage; Flue's turn usage drops the count.
  • Readback (telemetry-readback/): reads the new fields, cache-read tokens and each tool call's name. Lines from before the new fields read as null. It still leaves out what diagnose doesn't show.
  • diagnose:
    • a table of where each step's time went, naming the tools each step called;
    • the figure that was called "first event" is now "HTTP response", because Pi emits its start event when the response headers arrive;
    • a tool-execution table read from execute_tool spans. The issue asked for each tool call's execution time. Calls in one step whose time ranges overlap are instead shown as one row, timed once: every call in a batch the panel runs closes when the batch returns, so one row per call would repeat the batch's time sixteen times for sixteen calls. A server tool that overlaps such a batch shares its row;
    • steps the log line has but Tempo has no span for are named.
  • Old submissions: the span search used the whole --since window, which Tempo refuses beyond 168 hours. It now searches from the submission's first step to its settlement. With no log line to place the search and a window over 168 hours, it reports Tempo's limit and stops.
  • Run packet (version 4): beforeOutputMs divides into reasoning-block time before the first output and the rest, which add to it exactly. Each tool call says whether its arguments arrived in one burst (first and last delta under 50 ms apart), and steps, exchanges and the summary total those characters, because their generation falls inside the wait. reasoningSummaryMs is unchanged. On 50 ms: of 849 tool calls with over 50 argument characters in five sessions, 765 spanned 0 ms, 8 spanned 1–49 ms, 3 spanned 50–199 ms and 73 spanned 200 ms or more.
  • A persona run's last spans were lost for two reasons, both fixed, plus a setting that makes the loss unlikely even without them:
    • the launcher signalled the whole process group. yarn workspace passes every SIGTERM it receives on to vite, and vite handles only the first, so the second killed it mid-close. The launcher now signals each service's leader and still polls, and force-kills, the group;
    • the dev server's SQLite store closed without sending the telemetry held in the batch processors; only the Postgres runner's close did. The SQLite close now flushes spans and metrics. It flushes and does not shut down, because a source change reloads the dev app and closes the old store while the server and its exporters run on;
    • the launcher sets OTEL_BSP_SCHEDULE_DELAY=200 for the server it starts.

Checked on live turns exported to a local collector: diagnose --submission, reading Loki and Tempo only, and the run packet, reading the conversation database, agree per step to within 5 ms on reasoning time and 2 ms on reply-text time, with identical cost and reasoning tokens. A dev server stopped by the launcher's code 0 ms after its turn settled, with the export delay forced to 5 s, still delivered the turn's span.

⚠️ Known issues

  • Log records written in the last second before a stop can still be lost, the chronology line among them: the flush reaches spans and metrics through the OpenTelemetry API, and the log provider is not reachable that way. A flush exposed by the shared setup in @local/hash-backend-utils would cover them. A persona run keeps its own server log, which has the line.
  • If the collector is down when the dev server stops, the flush rejects and Flue logs Application shutdown failed, beside the exporter's own error.
  • The run packet's per-call execution time rises through a browser batch, since each call closes when the batch returns, so the category table's "Execution (summed per call)" overcounts.
  • packet.md rounds each figure on its own, so a line can read 13 s (2.0 s + 11 s). packet.json sums exactly.

🤖 Generated with Claude Code

…gnostics

The chronology line now carries, per model step, the time in reasoning
blocks and their count, the reply text's first and last delta, cache-write
and reasoning tokens, and Pi's catalogue cost estimate. The readback keeps
these and the fields it used to drop; `diagnose` shows them per step, reads
each submission's execute_tool spans (a browser batch timed once), and
searches Tempo around the submission's own logged time so submissions older
than seven days read without a 400.
A step's beforeOutputMs now divides into the time inside reasoning blocks
before its first output and the rest of the wait, which add to it exactly.
Each tool call says whether its arguments arrived in one burst (first and
last delta under 50 ms apart), and each step, exchange and the summary total
the burst calls' argument characters, null without a chronology line.
packet.md shows the split in its summary table and exchange table, and the
packet's version goes to 4.
…ans in Brunch's diagnose

Also search further back for spans of a line without step start times, and
stop the chronology observer holding state for events that arrive after
their submission settled.
@lunelson lunelson self-assigned this Dec 3, 2026
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
petrinaut Ready Ready Preview Dec 3, 2026 1:36pm UTC
3 Skipped Deployments
Project Deployment Actions Updated
hash Ignored Ignored Preview Dec 3, 2026 1:36pm UTC
hashdotdesign-tokens Ignored Ignored Preview Dec 3, 2026 1:36pm UTC
petrinaut-docs Skipped Skipped Dec 3, 2026 1:36pm UTC

Request Review

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – petrinaut — 7e78c380 Deployed Dec 3, 2026 by vercel[bot]
Preview – petrinaut-docs — 7e78c380 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps area/infra Relates to version control, CI, CD or IaC (area)

Development

Successfully merging this pull request may close these issues.

1 participant