fix(server): resolve Claude user input prompts on stop#4096
Conversation
- Cancel pending AskUserQuestion requests when a Claude session stops. - Emit user-input.resolved so projected threads no longer stay trapped in stale prompts. - Add ClaudeAdapter coverage for stopping while user input is pending.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f7f07cf. Configure here.
| payload: { answers }, | ||
| }, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Missing resolved after abort then stop
Medium Severity
When an AskUserQuestion wait is cancelled via the SDK AbortSignal, onAbort removes the request from pendingUserInputs before session teardown runs. If stopSessionInternal then sets context.stopped with an empty map, no user-input.resolved is emitted, and the handler skips emission for cancelled resolutions while stopped—so projected threads can keep a stale user-input prompt.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit f7f07cf. Configure here.
ApprovabilityVerdict: Needs human review An unresolved review comment identifies a potential race condition where abort-before-stop could leave stale user-input prompts. This potential bug in the fix warrants human review. You can customize Macroscope's approvability policy. Learn more. |


Closes #4060.
Summary
user-input.resolvedduring session stop so projected threads clear stale user-input prompts.Verification
corepack pnpm exec vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.tscorepack pnpm exec vp run typecheckcorepack pnpm exec vp check(passes with existing warnings outside this change)Note
Low Risk
Scoped to Claude AskUserQuestion lifecycle and session teardown; behavior change is intentional cancellation with test coverage and no auth or data-model changes.
Overview
Fixes stale AskUserQuestion prompts when a Claude session ends while the UI is still waiting for answers.
ClaudeAdapter now tracks pending user input with a tagged answered / cancelled resolution instead of a bare answers deferred. Session stop cancels every open prompt (mirroring pending approvals): it completes the wait, emits
user-input.resolvedwith empty answers so projected threads clear, and the SDKcanUseToolpath returns deny with a cancel message rather than allowing empty answers. Abort while waiting uses the same cancelled resolution;user-input.resolvedis not emitted twice when stop already published the cancel event.Adds a test that
stopSessionduring an in-flight AskUserQuestion produces the resolved event and deny permission result.Reviewed by Cursor Bugbot for commit f7f07cf. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Resolve pending Claude user input prompts with cancellation on session stop
PendingUserInputResolutiondiscriminated union (answered|cancelled) to replace the raw answersDeferredinPendingUserInput.stopSessionInternalnow iterates pending user-input requests, fulfills each with acancelledresolution, emits auser-input.resolvedevent with empty answers, and clears the map.AskUserQuestionhandler, a cancelled resolution returns a denyPermissionResultwith the message'User cancelled tool execution.'and skips emitting a duplicateuser-input.resolvedevent if the session already emitted one on stop.respondToUserInputnow tags fulfilled resolutions asansweredbefore resolving the deferred.Macroscope summarized f7f07cf.