Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): close sessions when provider turns abort #8859

Closedhahasagined(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8859/headopened View on GitHub

Problem

An interrupted provider turn can emit canonical turn.aborted without a following turn.completed. Runtime ingestion already recorded the abort and cleared plan progress, but it did not close the durable thread-session lifecycle. The session could remain running with a dangling activeTurnId, leaving the UI stuck on “Working” and refusing settlement even after Stop succeeded.

Fixes #8802.

Fix

Treat an authoritative turn.aborted as a lifecycle-closing event:

  • accept it only when its turn ID exactly matches the currently active turn, so delayed, duplicate, untargeted, and conflicting aborts cannot overwrite newer lifecycle state;
  • move the still-live provider session to ready, clear activeTurnId, and clear the previous error through the existing ready-state path;
  • finalize buffered assistant output and proposed plans through the existing turn-completion path;
  • clear plan progress only when the abort passes the same lifecycle guard.

This is provider-agnostic. ready is intentional because the provider session remains alive and reusable after the turn is interrupted.

Verification

  • Repeated the original OpenCode/Z.AI insufficient-balance reproduction against this source build using the existing live environment data. After the same retry/failure sequence, Stop succeeded, “Working” cleared, and the persisted session no longer remained active.
  • Confirmed the canonical turn.aborted in the provider event log and the durable projections: active_turn_id = null, the session was no longer running, and the turn projected as interrupted.
  • vp test run across runtime ingestion, provider command reactor, ProviderService, and OpenCodeAdapter: 6 files, 224 tests passed.
  • Server typecheck exited successfully; targeted lint, formatting, and git diff --check passed.
  • #6018 covers the same missing ingestion transition with broader ordering/projection coverage and different interrupted session semantics. This PR keeps the live provider session reusable as ready and is limited to the incident path plus stale-abort guards.
  • #8813 concerns the OpenCode adapter interrupt path. On current main, the adapter already emits turn.aborted; this change consumes that event in orchestration.
  • #7368 and #4524 involve abort failures rather than a successful abort whose lifecycle event was not applied.

Prepared with GPT-5.6 Sol using the Codex harness in T3 Code.


Note

Medium Risk Changes orchestration session lifecycle and turn-settlement paths; guards limit blast radius, but incorrect abort matching could still affect thread readiness or UI “working” state.

Overview Fixes threads that stayed running with a dangling activeTurnId when a provider emitted turn.aborted instead of turn.completed after interrupt (e.g. OpenCode), which blocked Stop/settle and left the UI on “Working”.

Provider runtime ingestion now treats an authoritative turn.aborted like turn settlement: session → ready, activeTurnId cleared, partial assistant text and proposed plans finalized, and plan progress cleared. The provider session is left reusable (ready, not stopped).

Guards apply lifecycle updates only when the abort’s turn id matches the active turn, so wrong-turn, duplicate, or post-session.exited aborts cannot overwrite newer state.

Regression tests cover the happy path and stale/late abort behavior.

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

Note

Fix turn.aborted to close active session and finalize messages in ProviderRuntimeIngestion

  • turn.aborted now transitions the session to ready, clears activeTurnId, and finalizes the assistant message and proposed plan — matching the existing turn.completed handling.
  • A lifecycle guard via shouldApplyThreadLifecycle ensures only aborts whose turnId matches the current activeTurnId are processed; stale or duplicate aborts no longer modify the session or clear plan progress.
  • Adds tests in ProviderRuntimeIngestion.test.ts covering both the active-turn abort path and the stale-abort rejection path.
  • Risk: late turn.aborted events arriving after session.exited are now ignored; any out-of-tree logic relying on stale aborts clearing plan progress will no longer see that effect.
Macroscope summarized 891ab7d.
    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 Plus

      Run ID: 72db25ac-bb51-43d9-be55-cbe871efbf31

      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

      Warning

      Your free Security trial is over. An organization admin can activate Security or dismiss this notice.


      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. 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 39a142e5cc17fdbdbcf2fccea3c1b2d1bcbc12e3. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 891ab7d

      Macroscope's review found this PR approvable — This is a focused server bug fix that closes only the currently active session turn on a matching provider abort, while ignoring stale or late aborts. The behavior is covered by targeted lifecycle regression tests and introduces no schema, configuration, deployment, or sensitive-area changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. mInrOz(GitHub profile, opens in a new tab)commented

      Independent reproduction on 2026-09-02 with OpenCode on t3 0.0.38 (Linux x64, Node 24, systemd service, web client).

      Stop succeeded end to end:

      • interruptTurn and opencode.session.abort spans exited successfully
      • OpenCode emitted session.error MessageAbortedError, then session.status idle and session.idle
      • the adapter emitted canonical turn.aborted with the turn id at 18:38:14.714Z

      The durable session state did not follow:

      • the turn projected as interrupted
      • projection_thread_sessions stayed running with that active_turn_id for 41 minutes
      • eight further interrupt requests were accepted with no effect
      • thread.settle was rejected with OrchestrationThreadSettleBlockedError
      • no thread.session-set was persisted between the running transition and the session.exited that a manual SIGTERM produced

      Affected builds: the same lifecycle list without turn.aborted is present in the 0.0.34-nightly.20260821.1153 and 0.0.39-nightly.20260902.1256 bundles.

      Verification: merged this branch onto main aab404964 locally. Ingestion suite 52/52, ProviderCommandReactor 51/51, server typecheck clean. The new lifecycle test fails on unpatched main.

      Also relates to #4713.

      Written by: Fable 5.1

    6. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      This note is part of an automated cleanup pass.

      Carryover from #6018 at 7c52a7c4a7: retain the event-ordering cases for unscoped, stale, duplicate, and post-terminal aborts, plus later session state, completion, and exit events after an interrupt. Its projection rebuild case compares persisted interrupted lifecycle and pending approval/user-input requests. Keep those invariants alongside this PR's buffered text and proposed-plan finalization. The large fixture expansion is a source of cases, not code claimed to have been copied or run.

    7. Closing as superseded by merged PR #9653.

      Retested the original OpenCode/Z.AI insufficient-balance reproduction on the published 0.0.39-nightly.20260906.1293, without this PR's patch. Stop now clears the running UI state, and the persisted session transitions to interrupted with activeTurnId = null 42 ms after the interrupt request. A separate subscription with credits completed normally and returned “Pong”.

      Full verification, UTC timestamps, and test limits: https://github.com/pingdotgg/t3code/issues/8802#issuecomment-5559362626

      #8802 is now closed as completed for that original reproduction. This does not claim the broader cases in #4713 are resolved. No rebase or merge of this PR is needed for the verified case.

Sign in to join this conversation.