fix(runtime): close turn-lifecycle cancellation contract gaps#189
Merged
Conversation
A real session showed the agent silently "hanging": the goal-continuation consistency gate ran on EVERY turn (not just continuations), swallowing real user input; turn cancellation had multiple entry points with no shared invariant; and the loop detector keyed only on tool input, so a tool re-reading a mutating path (ReadImage on an overwritten screenshot) was falsely aborted. Root causes addressed: - A. Continuation gate now keys on TurnTrigger::is_goal_continuation(), so non-continuation turns always reach the LLM. Stale continuations are skipped observably (ContinuationSkipped) and rewound by identity (current_turn_index), not by len-1 position. - B. All user-level cancellation funnels through finalize_turn_cancellation: pairs the open tool batch, resets continuation state, notifies governance on_turn_cancelled, emits TurnCancelled, ends the record. end_turn_record is pub(crate) so Cancelled construction is single-sourced; the two intentional bypasses (compaction host, governance abort) are documented. - C. LoopDetector counts CONSECUTIVE identical (input, output) in on_after_tools, hashing content + is_error + image content_key + metadata; resets on on_turn_cancelled / task boundary / compaction. A cancelled turn no longer emits both TurnCompleted and TurnCancelled, and no longer feeds the degeneration/loop detectors. Every fix carries unit + e2e regression coverage.
yishuiliunian
added a commit
that referenced
this pull request
Jun 3, 2026
…191) * fix(tui): show "Compacting" status during compaction instead of Idle #190 made AgentStatus backend-only and declared compact_banner the sole signal for compacting, but the unified status line never consumed it. Manual /compact runs as a control command in the idle phase, so status stays WaitingForInput and the decision tree fell through to Idle with a frozen spinner — covering auto-compaction and resume-rehydrate too. Extract the status-label decision into a pure pick_label() and add a Compacting tier (after Thinking, before Streaming). Feed it compact_banner.is_some(), and add the same flag to is_agent_active so the spinner animates for the whole compaction rather than freezing after the 750ms activity grace. Presentation-layer only: no AgentStatus mutation, no protocol change, so it does not reintroduce the #189/#190 turn-lifecycle desync risk. * fix: address CI failure - rustfmt struct-update layout in tests rustfmt expands single-line `ActivityInputs { field: x, ..base() }` to multi-line; apply the canonical formatting.
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
Changes
turn.rsTurnTrigger::is_goal_continuation();goal_consistency.rs仅 continuation turn 走闸门 +ContinuationSkipped可观测 + 按current_turn_index()身份 rewind;event_payload.rs新增ContinuationSkipped。turn_cancel_finalize.rs(finalize + wire 映射);end_turn_record→pub(crate);ingest.rs/turn_observer_dispatch.rs/turn_telemetry.rs统一;event_payload.rs新增TurnCancelled;cancelled turn 不再双 emit、不再喂 governance。loop_detector.rs改on_after_tools按 (input,output) 连续相同计数,hash content+is_error+image content_key+metadata;image.rscontent_key();on_turn_cancelled重置。loopal-session/loopal-view-state/loopal-acp。Test plan
bazel build //... --config=clippy零警告 +bazel test //...94/94 通过