Skip variants trait-restore when session was explicitly stopped#116
Merged
obj-p merged 1 commit intocli-mcp-parityfrom Apr 16, 2026
Merged
Skip variants trait-restore when session was explicitly stopped#116obj-p merged 1 commit intocli-mcp-parityfrom
obj-p merged 1 commit intocli-mcp-parityfrom
Conversation
Follow-up audit from PR #113's deferred items. Walked every MCP handler looking for concurrent-modification races. Summary: No new bugs found — PreviewSession is an actor so within-session state transitions are serialized, and the `preview_snapshot` hole for missing sessions is already fixed in #112. One defensive improvement worth landing: when a concurrent `preview_stop` fires mid-variants-loop, the trait-restore-at-end block would fire against a now-stopped session, producing a misleading "Warning: failed to restore original traits" message for a user who explicitly asked for the stop. Skip the restore when the session is no longer in the registry (iosState for iOS, App.host.allSessions for macOS). No user-visible change for the happy path; the spurious warning goes away for the concurrent-stop case. Documented the remaining concurrent-modification caveat on `handlePreviewVariants`: a second client mutating the same session via preview_configure / preview_switch while variants is mid-loop will interleave its trait change into our capture stream. The daemon intentionally does not hold a per-session lock across tool calls (that's a more invasive architectural change); callers that want deterministic variants should own the session for the duration. All 14 variants integration tests pass unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Wave 1-C from the deferred-items list on #113: race-condition audit across every MCP handler.
Audit findings
No new bugs found.
PreviewSessionis an actor so within-session state transitions are serialized, and thepreview_snapshothole for missing sessions is already fixed in #112.One defensive improvement landed
When a concurrent
preview_stopfires mid-variants-loop, the trait-restore-at-end block would fire against a now-stopped session, producing a misleading "Warning: failed to restore original traits" message for a user who explicitly asked for the stop. Skip the restore when the session is no longer in the registry (iosStatefor iOS,App.host.allSessionsfor macOS). No user-visible change for the happy path; the spurious warning goes away for the concurrent-stop case.Documented caveat
Added a doc comment on
handlePreviewVariantsspelling out the remaining concurrent-modification limitation: a second client mutating the same session viapreview_configure/preview_switchwhile variants is mid-loop will interleave its trait change into our capture stream. The daemon intentionally does not hold a per-session lock across tool calls (more invasive architectural change); callers that want deterministic variants should own the session for the duration.Test plan
swift buildswift test --filter VariantsCommandTests— 14 integration tests pass unchanged (~60s)🤖 Generated with Claude Code