Repository navigation
fix: keep TTFT and output rate after a turn settles - #3706
Merged
Merged
Conversation
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.
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
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 withdurationMs: 0and no TTFT. Settled-turn reconcile then replaced the live projection with that record.getTurnOutputDurationMsrefuses 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 haddurationMs=0and nottftMs/attemptCount.Type and Areas
Type: bug fix
Areas: Rust core (agentic execution/session persistence), web UI (flow chat store)
Motivation / Impact
duration_ms,first_chunk_ms,first_visible_output_ms,stream_duration_ms,ttft_ms,attempt_count) now rides on the assistant message'smodel_execution.timingmetadata, 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 than0.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 missedModelRoundCompletedcannot erase it afterwards.ModelRoundCompletedtiming 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
0cannot 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 newprojected_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 newcompletion_merge_keeps_runtime_round_timing_over_stale_client_checkpoint, plus the extended legacy round-trip inptc_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.Reviewer Notes
Upgrade compatibility:
timingis 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