Stabilize AgentRunWorktreeStartTests production-capture selection race (#420)#430
Open
moonray wants to merge 1 commit into
Open
Stabilize AgentRunWorktreeStartTests production-capture selection race (#420)#430moonray wants to merge 1 commit into
moonray wants to merge 1 commit into
Conversation
repoprompt#420) The production source-capture drift guard re-validates the canonical selection after its async work. testProductionCapturePreservesBoundStoredSelectionInsteadOfCanonicalUI deliberately keeps the active UI selection diverged (empty) from canonical (storedSelection) to prove capture serves the stored selection. A debounced token-count recount flushed that divergent UI selection into canonical during the capture's await window (requiredLookupContext / freezePromptGitReviewContext), falsely tripping the guard ("launching selection changed while its frozen review capability was being created"). In normal use the selection mirror suppresses these flushes during sensitive operations; the test bypassed it via mirrorToUIIfActive:false and ran the capture outside that protection. Wrap the capture call in withApplyingSelectionMirror to hold the production flush suppression across the capture window, keeping canonical stable while the frozen review capability is built. Test-only; assertions unchanged. Repro on base (27064af): focused test failed 6/25 (24%) with the exact issue signature. After fix: focused 50/50 pass; full AgentRunWorktreeStartTests 38/38. Closes repoprompt#420
This was referenced Jul 8, 2026
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
Fixes the intermittent CI flake in
AgentRunWorktreeStartTests/testProductionCapturePreservesBoundStoredSelectionInsteadOfCanonicalUI(app shard 4). Closes #420.Root cause
captureAgentRunOracleReviewSourcere-validates the canonical tab selection after its async work (requiredLookupContext+freezePromptGitReviewContext) via theagentRunOracleReviewLaunchSelectionStillMatchesguard. This test deliberately keeps the active UI selection diverged (empty) from the canonical tab selection (storedSelection) to prove capture serves the stored selection rather than the UI.The divergence is created with
mirrorToUIIfActive: false, so noDeferredUISelectionFenceprotects canonical. A debouncedTokenCountingViewModelrecount — armed by the test'sapplyStoredSelection(StoredSelection())— fires during the capture's await window and readsactiveSelectionSnapshot(flushPendingUI: true), flushing the divergent empty UI into canonical. That bumpsselectionRevisionForMCPand flips the canonical identity, falsely tripping the guard:In normal production use the selection mirror suppresses these flushes during sensitive operations; the test bypassed the mirror and ran the capture outside that protection. This matches the precedent in
6f32dcf7(Stabilize full-suite MCP worktree tests), which introduced the identity-based comparison for exactly this class of mirror/re-commit churn.Fix
Test-only (+14/−4). Wrap the capture call in
window.selectionCoordinator.withApplyingSelectionMirror { … }to hold the production flush suppression across the capture window, keeping canonical stable while the frozen review capability is built. No production code changed; assertions unchanged.Validation
27064af8, an ancestor of currentmain): focused test failed 6/25 (24%) with the exact issue signature.AgentRunWorktreeStartTestsclass: 38/38 pass, 0 fail.--strict: 0 violations.commitandpushmodes both passed.maindo not touch the test, the capture guard, the selection coordinator, or token counting (only unrelated Sentry telemetry + formatting inMCPServerViewModel), so the fix applies unchanged.Notes
🤖 Generated with Claude Code