Skip to content

fix: keep TTFT and output rate after a turn settles - #3706

Merged
bobleer merged 4 commits into
openBitFun:mainfrom
bobleer:bob/persist-round-timing
Nov 3, 2026
Merged

bobleer merged 4 commits into
openBitFun:mainfrom
bobleer:bob/persist-round-timing

Conversation

@bobleer

@bobleer bobleer commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Flow chat lost the per-turn output rate (TPS) after a turn finished, and for single-round turns lost TTFT as well. The cause is how the durable turn record gets its round timing; the provider's stream and usage are fine.

The runtime rebuilds the durable turn's rounds from the generation journal at completion, and it took round timing only from the client's checkpoint of ModelRoundCompleted. For the last round, that checkpoint routinely lands after the completion write, so the round was stored with durationMs: 0 and no TTFT. Settled-turn reconcile then replaced the live projection with that record. getTurnOutputDurationMs refuses partial timing, so the rate disappeared; TTFT disappeared too whenever the first round was also the last.

Observed on a real session (vLLM-backed OpenAI-compatible model, which returns usage normally): round 0 (tool call) had durationMs=3250, ttftMs=1444, while the final text round had durationMs=0 and no ttftMs/attemptCount.

Type and Areas

Type: bug fix

Areas: Rust core (agentic execution/session persistence), web UI (flow chat store)

Motivation / Impact

  • Runtime: accepted-attempt round timing (duration_ms, first_chunk_ms, first_visible_output_ms, stream_duration_ms, ttft_ms, attempt_count) now rides on the assistant message's model_execution.timing metadata, so the durable round no longer depends on a client checkpoint winning a race. Durable round building and the completion merge prefer it; the client checkpoint remains the fallback for journals written before this field. Unknown durations are now recorded as unknown rather than 0.
  • Runtime: projected Turn saves (save_persisted_dialog_turn → merge_runtime_owned_turn_facts) keep the persisted round timing for any round the client projection leaves unmeasured, so a window that missed ModelRoundCompleted cannot erase it afterwards.
  • Web UI: settled-turn reconcile and Peer snapshot adoption keep live ModelRoundCompleted timing when the incoming record lacks it, which covers a newer controller attached to an older Peer or remote host. The runtime replay shell is still adopted as is.

Users see TTFT and output rate stay visible after a turn settles, including after reload. Turns already persisted with 0 cannot be recovered.

Verification

  • cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git --lib -- product_runtime::tests::projected_turn agentic::session agentic::persistence — 273 passed (includes new projected_turn_saves_keep_runtime_round_timing).
  • cargo test --locked -p openbitfun-core --no-default-features --features agent-runtime,git --lib -- agentic::session agentic::persistence agentic::coordination agentic::execution::round_executor — 579 passed (includes new completion_merge_keeps_runtime_round_timing_over_stale_client_checkpoint, plus the extended legacy round-trip in ptc_specs_and_routed_execution_metadata_round_trip_together_with_legacy_defaults).
  • pnpm --dir src/web-ui run test:run src/flow_chat/store/FlowChatStore.test.ts src/flow_chat/utils/turnUsageMetrics.test.ts — 305 passed (new settled-reconcile and Peer-adoption tests); the reconcile test fails with the guard removed.
  • pnpm run type-check:web — clean.
  • Not exercised manually in the running app, nor in remote workspace / remote control / Peer Device / Detached Dispatch scenarios. The runtime change sits in the shared persistence path those scenarios read from.

Reviewer Notes

Upgrade compatibility: timing is optional with serde defaults on both the struct and every field; legacy messages without it deserialize unchanged (covered by test). Older readers ignore the extra field. Rounds whose attempts were retried (attemptCount > 1) still intentionally show no rate.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable. (No user-facing string changes.)

The durable Turn rebuilds its rounds from the generation journal at
completion and took round timing only from the client checkpoint of
ModelRoundCompleted. For the last round that checkpoint routinely lands
after the completion write, so the round was stored with duration 0 and
no TTFT. Settled-turn reconcile then replaced the live projection and the
flow chat lost its output rate (and TTFT for single-round turns).

Carry the accepted-attempt timing on the assistant message's
model_execution metadata and prefer it when building and merging durable
rounds. The client checkpoint stays as the fallback for journals written
before this field existed; unknown durations are no longer recorded as 0.
Hosts that predate journal-carried round timing persist the last round of
a Turn without it. Keep the timing this window already received from
ModelRoundCompleted when reconciling against such a record, so TTFT and
output rate stay visible against older Peer or remote hosts.
A client may save its projection of a Turn after the Runtime has written
it, from a window that missed or had not yet applied a round's
ModelRoundCompleted. The projected-save merge took that projection
wholesale, so it could erase the round timing the Runtime recorded.
Keep persisted timing for any round the projection leaves unmeasured.
Peer snapshot refresh replaced settled Turns wholesale, with the same
loss as settled-turn reconcile against a host that predates
journal-carried round timing. Route both replacements through the same
guard; the runtime replay shell is still adopted as is.
@bobleer
bobleer merged commit b475a68 into openBitFun:main Nov 3, 2026
13 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