[Bug]: ClaudeAdapter leaks pending AskUserQuestion requests on session teardown — thread becomes unanswerable and unsettleable #5119
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Summary#
If a Claude session dies while an AskUserQuestion card is pending — mine died from running out of inference credits mid-turn — the thread deadlocks permanently:
- The card can't be answered. Every submit fails with
No active provider session is bound to this thread. - Switching the model doesn't help. Same error.
- The thread can't be settled or snoozed.
canSettlerefuses whilehasPendingUserInputis true, and nothing left alive can clear it.
Cause: ClaudeAdapter.stopSessionInternal settles pending approvals on teardown but not pending user inputs. The other adapters settle both.
Steps to reproduce#
- Start a thread on the Claude provider.
- Get the agent to call
AskUserQuestionso the card renders in the composer. - Kill the session while the card is pending — running out of credits does it;
adapter.stopSessionreproduces it directly. - Answer the card → error. Switch model, answer again → same error. Try to settle the thread → refused.
Expected behavior#
Killing a session settles its pending user-input requests, the same way it already settles pending approvals. The card resolves, the thread unblocks, and a normal message restarts the session on the selected model.
Actual behavior#
The request stays open forever. It cannot be answered, dismissed, or settled around.
Impact#
Blocks work completely
Version or commit#
0.0.31 (e6987965f659) — T3 Code (Alpha), desktop
Environment#
macOS 26.1 (25B5042k), Apple M1 Pro (arm64), T3 Code (Alpha) desktop 0.0.31, provider: Claude / Fable, trigger: inference credits exhausted mid-turn
Logs or stack traces#
Provider user input response failed
No active provider session is bound to this thread.
Root cause#
apps/server/src/provider/Layers/ClaudeAdapter.ts:3029-3055 — teardown drains one map and not the other:
for (const [requestId, pending] of context.pendingApprovals) {
yield* Deferred.succeed(pending.decision, "cancel");
// ... emits request.resolved
}
context.pendingApprovals.clear();
// context.pendingUserInputs (declared :191, populated :3268) is never touched.
That strands the request because handleAskUserQuestion parks on Deferred.await(answersDeferred) at :3284, and the user-input.resolved emit that clears the projection is at :3288 — after the await. An interrupt fires the abort handler at :3271, the deferred resolves, :3288 runs, the request clears (already tested at ClaudeAdapter.test.ts:3793). A session stop never touches the deferred, so the fiber is interrupted while parked and no user-input.resolved is ever emitted.
Adapter parity:
| Adapter | Settles approvals | Settles user inputs |
|---|---|---|
CursorAdapter.ts:463-464 | ✅ | ✅ |
GrokAdapter.ts:514-515 | ✅ | ✅ |
CodexSessionRuntime.ts:819-834 | ✅ | ✅ |
ClaudeAdapter.ts:3037 | ✅ | ❌ this bug |
(OpenCodeAdapter uses a different mechanism — pendingQuestions replied over the wire at :1594 — and its stopSession at :1602 doesn't settle those either. Possibly the same deadlock by another route; I haven't traced it.)
Cursor also has the regression tests this needs, at CursorAdapter.test.ts:1093 and :1136. ClaudeAdapter.test.ts has no equivalent — the missing test and the missing loop are the same hole.
Fix#
Give PendingUserInput a cancel handle and call it from stopSessionInternal, reusing the abort path's existing semantics. 9 added lines, no deletions, verified red → green locally against a new test ported from CursorAdapter.test.ts:1093. Happy to open the PR.
Workaround#
None found — the thread stays blocked and unsettleable.
AaronAbuUsama(GitHub profile, opens in a new tab) changed the title
juliusmarminge closed this
Sign in to join this conversation.
Cloned the repo and traced this further. The root cause is narrower and more obvious than what I wrote above:
ClaudeAdapteris the only adapter that doesn't settle pending user-input requests when a session tears down.apps/server/src/provider/Layers/ClaudeAdapter.ts:3029-3055—stopSessionInternaldrainscontext.pendingApprovalsand emitsrequest.resolvedfor each:context.pendingUserInputs(declared on the context at:191, populated at:3268) is simply leaked. TheAskUserQuestionhandler is parked onDeferred.await(answersDeferred)at:3284; theuser-input.resolvedemit that clears the projection lives at:3288, after that await. Session teardown interrupts the fiber, the await never returns, the resolved event never fires — sohasPendingUserInputstays true forever and the thread is neither answerable nor settleable.The abort path at
:3271-3278handles this correctly for interrupts (it resolves the deferred with{}, so:3288runs and the request clears). It just isn't wired to session stop.The other four adapters already do it. This is a missing-symmetry bug with three reference implementations in-tree:
CursorAdapter.ts:463-464—settlePendingApprovalsAsCancelled(ctx.pendingApprovals)andsettlePendingUserInputsAsEmptyAnswers(ctx.pendingUserInputs)(helpers at:143-167)GrokAdapter.ts:514-515— same pair (settlePendingUserInputsAsCancelled, helpers at:124-140)CodexSessionRuntime.ts:819-834— same pair overpendingApprovalsRef/pendingUserInputsRefSo the fix is the Cursor helper, copied:
Correction to the original report: I wrote that
processApprovalResponseRequestedwas "presumably stuck the same way". It isn't — approvals are cancelled on teardown at:3037, which is exactly why only user-input requests strand. Pending approvals are fine.The two orchestration-level observations still stand and are worth fixing as defence in depth, since an adapter that dies without running its teardown reproduces the same deadlock:
ProjectionPipeline.ts:164-173—"No active provider session is bound to this thread."isn't in the allowlist that clears an open request id.ProviderCommandReactor.ts:1189— the user-input response path never restarts a session, andthread.user-input.respond(orchestration.ts:742-749) carries nomodelSelection, so switching models before answering a pending card is a no-op. Worth carrying the model selection on that command and routing throughbuildSendTurnRequestForThread(ProviderCommandReactor.ts:669) when the session is gone — the resume cursor is already persisted per thread+instance (ProviderService.ts:562-567), so a restart keeps the conversation.