Clear pending requests whose provider session is gone #4598
main fromrefs/pull/4598/head·opened View on GitHubWhat Changed#
ProviderCommandReactor now records a terminal failure detail when an approval or
user-input response arrives for a thread whose provider session is gone, instead of a
bespoke string no pending-request accounting recognizes.
No active provider session is bound to this thread. Stale pending user-input request:
<id>. Provider callback state does not survive app restarts or recovered sessions.
Restart the turn to continue.
This reuses the existing stalePendingRequestDetail(...) text rather than adding a new
marker, so every consumer that already clears stale requests clears this one too — no
matcher changes, and already-shipped clients get the fix without rebuilding.
Applied to both processUserInputResponseRequested and processApprovalResponseRequested;
approvals had the identical bug. The turn-interrupt path keeps its plain message — it
gates no prompt.
Why#
A pending AskUserQuestion (or approval) request can only be answered through the live
provider session holding its callback — a Deferred in the adapter's in-memory
pendingUserInputs map. Once that session is gone the request is permanently
unanswerable; starting a new session cannot re-bind the dead tool call.
The reactor already refused to send those responses. But whether an open request is
still answerable is decided independently by four consumers, each scanning activities
and clearing on a *.respond.failed whose detail carries a known terminal marker:
derivePendingApprovals/derivePendingUserInputs—apps/web/src/session-logic.ts- the same pair in
apps/mobile/src/lib/threadActivity.ts hasOpenBlockingRequest— the decider's settle/snooze guardderivePendingUserInputCountFromActivitiesand the pending-approval projector inProjectionPipeline
"No active provider session is bound to this thread." matched none of them, so the
request stayed open forever. In practice: the question card kept rendering as answerable,
each Submit appended another identical Provider user input response failed row — I hit
seven of them stacked in one thread before diagnosing this — and the thread could no
longer be settled or snoozed.
The decider's own comment already states the constraint this change satisfies: "The clearing rules MUST match ProjectionPipeline's pending accounting … or settle would be rejected on threads whose shell flags read as clear."
Scope note: this covers the case where the session is already gone — an app restart,
where nothing had a chance to emit user-input.resolved. #4096 covers the complementary
case, cancelling pending prompts during a graceful stopSession. Neither subsumes the
other, and this change touches no file that #4096 modifies outside a test.
UI Changes#
No frontend source change — the only web file touched is a test. The user-visible effect
is that the question card now disappears after one failed submit instead of persisting;
that behavior lives entirely in derivePendingUserInputs, which is unchanged and
already covered by unit tests.
Validation#
vp test run src/orchestration # apps/server, 192 passed (2 new)
vp test run --project unit src/session-logic.test.ts # apps/web, 60 passed (1 new)
tsgo --noEmit # apps/server + apps/web, clean
vp lint --report-unused-disable-directives <changed files> # clean
vp fmt --check <changed files> # clean
Both new reactor tests were confirmed to fail against the pre-fix detail string and
pass after, so they pin the behavior rather than restating it. The new session-logic
test locks the emitted detail to actual clearing, so a future reword of the server-side
string breaks loudly instead of silently reopening this bug.
Per AGENTS.md I kept verification focused rather than running repo-wide vp check /
vp run typecheck, and did not run an integrated browser pass — the diff contains no
frontend source changes.
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes — n/a, no frontend source change
- I included a video for animation/interaction changes — n/a, no motion
Note
Low Risk Low risk: localized failure-detail formatting in the orchestration reactor with regression tests; no auth or data-model changes, and existing clients benefit without matcher updates.
Overview
When approval or user-input responses arrive on a thread with no active provider session, ProviderCommandReactor still refused to call the provider but recorded a failure detail that pending-request accounting did not treat as terminal—so question/approval cards stayed answerable and each submit stacked another identical failure.
Server: Adds noActiveSessionRequestDetail, which prefixes the existing no-session message with the same stale pending request text from stalePendingRequestDetail. That string is used for both provider.approval.respond.failed and provider.user-input.respond.failed when hasSession is false (turn interrupt keeps its plain message).
Tests: Two reactor tests assert the provider is not called and the failure payload includes both markers; one session-logic test locks that derivePendingUserInputs clears the prompt when it sees the combined detail—no web UI source changes required because matchers already key off the stale substring.
Note
Clear pending requests when no active provider session is bound to a thread#
- When a
thread.user-input.respondorthread.approval.respondevent arrives but no provider session is active, the resulting failure activity now includes both a no-active-session message and a stale pending request marker in itspayload.detail. - A new
noActiveSessionRequestDetailhelper in ProviderCommandReactor.ts formats this combined detail string. derivePendingUserInputsin session-logic.test.ts is verified to return an empty list when it sees the stale pending marker, so the UI clears the pending request.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved
Straightforward bug fix that updates error message content to include a stale-request marker, triggering existing UI cleanup logic. The code change is minimal (one helper function, two call sites), and the PR includes comprehensive test coverage.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Closing in favor of #2829 (orchestration V2).
#2829 deletes the V1 orchestration layer this PR builds on —
apps/server/src/orchestration/**,provider/Layers/*Adapter.tsandprovider/Services/**are removed and replaced byapps/server/src/orchestration-v2/**, with the IPC surface renamed toORCHESTRATION_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.juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
52b8eea9-4e0b-4080-8322-3b64618db976You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.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.
❤️ Share