Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): cancel pending questions on stop #7987

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

Problem

Stopping a turn that is blocked on a user question left the question prompt stuck on screen. The UI cleared it optimistically, but nothing durable recorded the resolution, so a reload or another client brought the dead prompt back and any answer to it failed as stale.

Fix

After a successful provider interrupt, the ProviderCommandReactor re-reads the thread's activity log and derives the still-open user-input requests from that fresh snapshot (honoring prior resolutions and stale-response failures), so a resolution the provider appends while handling the interrupt is never followed by a false cancelled duplicate. Each durable user-input.resolved activity marked cancelled: true is stamped with server-side time rather than the stop command's timestamp, so it orders after the request activity even when the stop command carries an older one. The pending-UI derivation in every client then clears the prompt from the event stream itself, with no client-side special casing.

The reactor test covers an open request being cancelled despite an interrupt timestamp older than the request, a question the provider resolved during the interrupt keeping its real resolution untouched, and already-answered or stale-failed requests staying that way.

  • bb49562b1 cancels pending questions after interrupt
  • de3647d8f extends the test coverage

Note

Medium Risk Touches the turn-interrupt path and writes new orchestration activities. Wrong pending-request derivation could cancel live questions or leave dead prompts in the log.

Overview Stopping a turn that is waiting on a user question now records a durable cancellation so the prompt does not come back after reload or on another client.

After a successful provider interrupt, ProviderCommandReactor walks the thread activity log, finds still-open user-input requests (skipping already-resolved ones and stale-response failures), and appends user-input.resolved activities with cancelled: true. Clients already treat that kind as closed, so the prompt clears from the event stream without extra UI logic.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b6e1edf3301754edd93cf70b2ac2c8565b019a3d. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Cancel pending user-input requests on thread.turn.interrupt in ProviderCommandReactor

  • On thread.turn.interrupt-requested, after calling providerService.interruptTurn, the reactor now appends user-input.resolved activities with {cancelled: true} for any still-open user-input requests inferred from the activity log.
  • Adds pendingUserInputRequests to scan sorted thread activities and compute open request IDs, closing them on resolution or when provider.user-input.respond.failed marks the request as stale or unknown.
  • Adds appendCancelledUserInputActivity to append the cancellation activity with summary "User input cancelled", preserving the original turnId and using the interrupt event's createdAt.
  • Behavioral Change: previously-open user-input requests are now resolved as cancelled on interrupt; consumers reading user-input.resolved activities in ProviderCommandReactor.ts should handle the new {cancelled: true} payload.
📊 Macroscope summarized de3647d. 1 file reviewed, 2 issues evaluated, 0 issues filtered, 2 comments posted

🗂️ Filtered Issues

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. 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 Plus

      Run ID: 7f4a0cd4-2f2d-4971-8ba1-fada9a9895d5

      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

      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.
    3. 💡 Codex Review

      Here are some automated review suggestions for this pull request.

      Reviewed commit: b6e1edf330

      ℹ️ About Codex in GitHub

      Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

      • Open a pull request for review
      • Mark a draft as ready
      • Comment "@codex review".

      If Codex has suggestions, it will comment; otherwise it will react with 👍.

      Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

      @@ -1194,3 +1262,7 @@
      11941262
      11951263 // Orchestration turn ids are not provider turn ids, so interrupt by session.
      11961264 yield* providerService.interruptTurn({ threadId: event.payload.threadId });
      1265+ // Some providers discard their callbacks without emitting a matching
      1266+ // resolution event. Close those requests after the interrupt succeeds.
      1267+ yield* Effect.forEach(pendingUserInputRequests(thread.activities), ({ requestId, turnId }) =>
      1268+ appendCancelledUserInputActivity({

      P2 Badge Cancel questions in the session-stop path

      This cleanup runs only for thread.turn-interrupt-requested. When thread.session.stop is dispatched directly—such as archive/settle cleanup or the branch selector—the event instead reaches processSessionStopRequested, which stops the provider and marks the session stopped without appending any user-input.resolved activity. If the session was blocked on a question, reloading or later reopening the thread therefore still restores the now-unanswerable prompt. Apply the same durable cancellation cleanup after a successful session stop.

      Useful? React with 👍 / 👎.

    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). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b6e1edf3301754edd93cf70b2ac2c8565b019a3d. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -1194,3 +1262,13 @@
      11941262
      11951263 // Orchestration turn ids are not provider turn ids, so interrupt by session.
      11961264 yield* providerService.interruptTurn({ threadId: event.payload.threadId });
      1265+ // Some providers discard their callbacks without emitting a matching
      1266+ // resolution event. Close those requests after the interrupt succeeds.
      1267+ yield* Effect.forEach(pendingUserInputRequests(thread.activities), ({ requestId, turnId }) =>
      1268+ appendCancelledUserInputActivity({
      1269+ threadId: event.payload.threadId,
      1270+ requestId,
      1271+ turnId,
      1272+ createdAt: event.payload.createdAt,
      1273+ }),
      1274+ );

      Stale snapshot double-cancels

      Low Severity

      pendingUserInputRequests runs against the thread snapshot taken before interruptTurn. Claude and Cursor already settle open prompts and emit user-input.resolved during interrupt, so the reactor still appends a second user-input.resolved with cancelled: true for requests that are no longer open.

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b6e1edf3301754edd93cf70b2ac2c8565b019a3d. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Skipped

      Macroscope did not run approvability analysis for this PR. Macroscope could not determine whether this PR modifies its approvability configuration, so the PR was not approved automatically. A PR that may change the rules that govern approval is never approved automatically.

      Not approved because:

      • 2 blocking correctness issues found at or above your repo's Minimum Blocking Severity
    6. @@ -1194,3 +1267,10 @@
      11941267
      11951268 // Orchestration turn ids are not provider turn ids, so interrupt by session.
      11961269 yield* providerService.interruptTurn({ threadId: event.payload.threadId });
      1270+ // Some providers discard their callbacks without emitting a matching
      1271+ // resolution event. Close those requests once the interrupt succeeds,
      1272+ // deriving from a fresh read: the provider can append real resolutions
      1273+ // while handling the interrupt. Cancellations get server-side timestamps
      1274+ // so they order after the request activity even when the interrupt
      1275+ // command predates it.
      1276+ const postInterruptThread = yield* resolveThread(event.payload.threadId);
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/ProviderCommandReactor.ts:1276

      The interrupt path can append a user-input.resolved cancellation before the provider's real resolution, leaving a false cancellation and duplicate resolution in the durable activity log. resolveThread at this point may run before the callback fiber resumes and ProviderRuntimeIngestion projects the resolution; coordinate with callback completion or make cancellation resolution idempotent.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/orchestration/Layers/ProviderCommandReactor.ts around line 1276:
      
      The interrupt path can append a `user-input.resolved` cancellation before the provider's real resolution, leaving a false cancellation and duplicate resolution in the durable activity log. `resolveThread` at this point may run before the callback fiber resumes and `ProviderRuntimeIngestion` projects the resolution; coordinate with callback completion or make cancellation resolution idempotent.
      @@ -275,3 +281,8 @@
      275281 return `Stale pending ${requestKind} request: ${requestId}. Provider callback state does not survive app restarts or recovered sessions. Restart the turn to continue.`;
      276282 }
      277283
      284+function pendingUserInputRequests(
      285+ activities: OrchestrationThread["activities"],
      286+): ReadonlyArray<{ readonly requestId: string; readonly turnId: TurnId | null }> {
      287+ const openRequests = new Map<string, TurnId | null>();
      288+ const ordered = [...activities].toSorted(
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/ProviderCommandReactor.ts:288

      When user-input.requested and user-input.resolved share a createdAt timestamp, an ID ordering where the resolution sorts first causes pendingUserInputRequests to delete the request and then reopen it. The function therefore returns an already-resolved question as pending, so an interrupt appends a false cancellation. Use a durable append sequence/order for equal-timestamp lifecycle events instead of activity.id.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/orchestration/Layers/ProviderCommandReactor.ts around line 288:
      
      When `user-input.requested` and `user-input.resolved` share a `createdAt` timestamp, an ID ordering where the resolution sorts first causes `pendingUserInputRequests` to delete the request and then reopen it. The function therefore returns an already-resolved question as pending, so an interrupt appends a false cancellation. Use a durable append sequence/order for equal-timestamp lifecycle events instead of `activity.id`.
    7. Superseded by #9851 (merged) — same fix: dismiss/cancel pending native questions when the turn ends/stops. Tracking issue #7820 is closed.

    8. juliusmarminge closed this

Sign in to join this conversation.