Repository navigation
Conversation
…itor continuation A continuation attaches its turn under the SDK message lock and then replays the wake buffer, which can suspend on workflow transcript reads. Claude can ask for a later wake's tool meanwhile, and canUseTool took the attached turn at once, so the approval landed in the Monitor run while the tool stayed buffered for the later wake's own continuation. When the attached turn's session still has a wake buffer, canUseTool now waits for the lock (or the request's withdrawal), and denies as before if the tool's tool_use is still buffered after the replay.
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — The adapter now waits for wake replay before assigning tool approvals, keeping later buffered wake requests out of a paused Monitor continuation. Existing approval policies remain unchanged, and unmatched requests use the existing deny path. You can add or adjust custom eligibility rules. Learn more. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Problem
When Claude wakes on its own, the adapter buffers the wake and asks for a continuation run. That run takes the SDK message lock, attaches its turn, and replays the buffer. Since #36339, a Monitor-event continuation replays only its own wake and leaves a later wake buffered for a continuation of its own. The replay can suspend on workflow transcript reads, and the SDK calls
canUseToolfrom its own read loop, so Claude can ask for the later wake's tool during that pause.canUseToolEffecttook the attached turn at once, so the approval appeared in the Monitor run while the tool itself later appeared in the later wake's run.Change
When a turn is attached and its Claude session still has a wake buffer,
canUseToolwaits for the replay (the SDK message lock, raced against the request's withdrawal), then reads the active turn again. If the request'stool_useis still buffered, it belongs to a wake this turn did not replay, and the request is denied as it would be with no active turn. The lock is released before the approval is raised or awaited. With no wake buffer for the session, nothing changes.Scope
No separate issue: CodeRabbit found this race while reviewing #36740 (#36740 (comment)), and it is on main independently of that PR. The new test reproduces it deterministically. #36740 adds the same two small helpers (
awaitAbortSignal,isToolUseBuffered) with identical bodies, so whichever lands second has a trivial conflict. This PR does not depend on #36740.Verification
ClaudeAdapterV2.test.tscase: a workflow finishes inside a Monitor event wake, and a later wake's Bashtool_usewaits behind it. The Monitor continuation's replay is paused throughWorkflowAgentTranscriptReadObserver, and Claude asks for the Bash approval during the pause. On main, the approval request is raised in the Monitor run (the test fails at theruntime_request.updatedassertion). With the fix, the request is denied, and the Bash item appears only in the later wake's own continuation run.ClaudeAdapterV2.test.tspass (375).vp run check:changedpasses;ClaudeAutomaticDelivery.integration.test.ts,RestartContinuation.test.ts, the Claude replay fixtures andProviderSwitch.integration.test.tspass.Written with Claude Opus 5.5 in Claude Code, reviewed by gpt-6.1-sol in Codex; I checked the evidence and the change.