fix(core): correct turn-latency metrics and idle-window bg status visibility - #6292
Merged
Conversation
bug-ops
enabled auto-merge (squash)
July 14, 2026 18:53
…etrics tick MetricsBridge::WATCHED_SPANS watched the bare llm.chat span, but every tool-enabled turn dispatches through chat_with_tools() (llm.chat_with_tools) instead, so the turn-latency panel showed llm:0ms even when the real call took 25+ seconds. Auxiliary bare llm.chat calls in the same turn (self-check, compaction probe, magic docs, etc.) were also silently overwriting the correct manually-tracked duration. Now watches llm.chat_with_tools, accumulates across a turn's multi-round tool loop, and scopes accumulation to spans nested under the main turn's llm.turn_call span so concurrent sub-agent and scheduler chat_with_tools calls can no longer inflate or corrupt the main turn's llm_chat_ms. The bg: N enrich, M telem status segment only refreshed at the start of the next turn, so it stayed stale during the entire idle window after a response while background enrichment/telemetry extraction was actually running. Added a periodic BgMetricsTick to the existing Agent::next_event select! loop that reuses reap_background_tasks_and_update_metrics between turns, so the TUI reflects real in-flight background work continuously. Uses interval_at to defer the first tick and avoid racing the pre-existing channel-closed shutdown path. Closes #6275 Closes #6279
bug-ops
force-pushed
the
fix/6279-tui-metrics-observability
branch
from
July 14, 2026 18:56
b10617d to
61fd32d
Compare
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
MetricsBridge::WATCHED_SPANSwatched the barellm.chatspan instead ofllm.chat_with_tools, the span every tool-enabled turn (essentially all of them) actually dispatches through — the turn-latency panel showedllm:0mseven when the real LLM call took 25+ seconds. Auxiliary barellm.chatcalls in the same turn (self-check, compaction probe, etc.) were also silently overwriting the correct manually-tracked duration.llm.chat_with_tools, accumulating across a turn's multi-round tool loop (instead of overwriting), and scoping accumulation to spans nested under the main turn'sllm.turn_callspan so concurrent in-process sub-agent and schedulerchat_with_toolscalls can't inflate or corrupt the main turn'sllm_chat_ms(found during review).bg: N enrich, M telemTUI status segment only refreshed at the start of the next turn, so it stayed stale/invisible during the entire idle window after a response — exactly when background enrichment/telemetry extraction is actually running. Added a periodicBgMetricsTickto the existingAgent::next_eventtokio::select!loop (no newtokio::spawn), usinginterval_atto defer the first tick and avoid racing the pre-existing channel-closed shutdown path (found during testing).Closes #6275
Closes #6279
Test plan
cargo +nightly fmt --checkcargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warningscargo clippy --profile ci -p zeph-core --all-targets --features "profiling,scheduler" -- -D warnings(metrics_bridge.rs is profiling-gated, not covered by the CI feature matrix)cargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins(13636 passed)RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler"metrics_bridge.rs,agent/utils.rs,agent/tests/bg_metrics_tick_race_tests.rs,agent/tests/agent_tests/lifecycle_tests.rs--tuisession confirmation per updated playbooks (metrics-bridge-watched-spans.mdScenario 2/2b/2c,bg-supervisor-phase2.mdS9) — deferred to next live-testing cycle,coverage-status.mdrows leftPartial