Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): resolve Claude user input prompts on stop #4096

ClosednateEc(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/4096/headopened View on GitHub

Closes #4060.

Summary

  • Cancel pending Claude AskUserQuestion requests when the provider session stops.
  • Emit user-input.resolved during session stop so projected threads clear stale user-input prompts.
  • Keep SDK permission results as deny/cancel instead of allowing an empty answer payload.

Verification

  • corepack pnpm exec vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts
  • corepack pnpm exec vp run typecheck
  • corepack pnpm exec vp check (passes with existing warnings outside this change)

Note

Medium Risk Touches Claude SDK permission callbacks and session teardown ordering, but behavior is narrowly scoped to user-input lifecycle with broad new tests.

Overview Fixes stale AskUserQuestion prompts by ensuring pending Claude user-input requests always get a single terminal outcome and the chat UI stops showing them once the provider session is gone.

Claude adapter adds settlePendingUserInput so each prompt is settled exactly once: it waits for user-input.requested before emitting user-input.resolved, handles races (abort vs stopSession vs provider exit), and returns deny with empty answers on cancel instead of allowing the tool. Session teardown (stopSession / stopAll) and abort listeners now route through this helper; duplicate respondToUserInput calls fail with ProviderAdapterRequestError; canUseTool denies when the session is missing or already stopped.

Web passes session status into derivePendingUserInputs so prompts are hidden when status is stopped, including legacy threads that never got a resolved event.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e8dc20dfe160b4e3545d1d98c81d0a84e8afdb76. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Resolve pending Claude AskUserQuestion prompts when a session stops

  • When a Claude session stops, all pending AskUserQuestion requests are now cancelled and emit a user-input.resolved event with empty answers and a deny result of 'User cancelled tool execution.'
  • A new settlePendingUserInput helper in ClaudeAdapter.ts ensures each request resolves exactly once, ordering the resolved event after the corresponding requested event.
  • canUseTool and handleAskUserQuestion now immediately deny with 'Claude session context is unavailable or stopped.' when called after session stop or with an already-aborted signal.
  • Duplicate respondToUserInput calls for the same request now return a ProviderAdapterRequestError instead of silently succeeding.
  • derivePendingUserInputs in session-logic.ts returns an empty list when session status is 'stopped', clearing stale prompts from the UI.
Macroscope summarized e8dc20d.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 0a9b1d75-6b94-42d7-965c-a2c8fab498f7

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR introduces significant runtime behavior changes for handling pending user input prompts when Claude sessions stop, including new concurrency handling logic for race conditions. An unresolved review comment identifies inconsistent deny messages between abort and session-stop paths.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      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](https://cursor.com/bugbot) for commit e8dc20dfe160b4e3545d1d98c81d0a84e8afdb76. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -3193,0 +3264,21 @@
      3264+ requestId: asRuntimeRequestId(requestId),
      3265+ payload: { questions },
      3266+ providerRefs: nativeProviderRefs(context, {
      3267+ providerItemId: callbackOptions.toolUseID,
      3268+ }),
      3269+ raw: {
      3270+ source: "claude.sdk.permission",
      3271+ method: "canUseTool/AskUserQuestion",
      3272+ payload: {
      3273+ toolName: "AskUserQuestion",
      3274+ input: toolInput,
      3275+ },
      3276+ },
      3277+ }).pipe(Effect.ensuring(Deferred.succeed(requestedDeferred, undefined)));
      3278+ return true;
      3279+ }).pipe(Effect.uninterruptible);
      3280+ if (!didRegister) {
      3281+ return {
      3282+ behavior: "deny",
      3283+ message: "Claude session context is unavailable or stopped.",
      3284+ } satisfies PermissionResult;

      Abort deny uses stopped message

      Medium Severity

      Registration treats an already-aborted signal the same as a stopped session and returns deny with Claude session context is unavailable or stopped. That path never settles as cancelled, so the SDK sees a session-dead reason instead of the usual User cancelled tool execution. cancel deny when only the tool call was aborted.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e8dc20dfe160b4e3545d1d98c81d0a84e8afdb76. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Closing in favor of #2829 (orchestration V2).

      #2829 deletes the V1 orchestration layer this PR builds on — apps/server/src/orchestration/**, provider/Layers/*Adapter.ts and provider/Services/** are removed and replaced by apps/server/src/orchestration-v2/**, with the IPC surface renamed to ORCHESTRATION_V2_WS_METHODS. The files this PR touches either no longer exist or are rewritten, so it can't be rebased — it would need reimplementing against the V2 adapters.

      This is not a judgement on the change itself. Several of these are real gaps we still want fixed; the base just moved out from under them.

      Once #2829 merges, please rebase onto main, port the change to the V2 equivalent, and reopen (or open a fresh PR). Ping me and I'll prioritise the review.

    6. juliusmarminge closed this

Sign in to join this conversation.