Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): stop threads without resolving a run #22052

MergedYash-Singh1(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/22052/headmerged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHub

Problem

A stop request can hang when a running background command belongs to an earlier turn outside the paginated thread history. The client cannot find its run ID, so it cannot interrupt the command.

Change

Add a thread.stop command that resolves the active work by thread ID. Servers advertise support through the threadStop capability, and capable clients use this command when they do not have a run ID. Older servers keep the existing projection lookup behavior.

Scope and approval

This is a focused fix for the stop command hanging when the run is missing from the client's history window. The server already supports stopping a thread without resolving a run ID, so the change exposes that behavior through the client contract.

Verification

Added focused coverage for decoding the command, advertising the capability, dispatching a stop without fetching the thread projection, and stopping a completed run's background command. Tests were not run.

Closes #16586

    1. juliusmarminge added labelsmacroscope-review

    2. Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This PR promotes the existing internal thread.stop command to the client-facing protocol and enables it by default, changing the no-run interrupt path to a full server-side stop that can hold queues and cancel active or orphaned work. The default-enabled, cross-layer runtime behavior warrants human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 55ad9e14-5554-43af-9594-88f232d1bc4e
      📥 Commits

      Reviewing files that changed from the base of the PR and between d5fdfdcf05330680c2947bbb458772f63dba964f and 8662eb622f2db940caa139aa48ee10f5eabea982.

      📒 Files selected for processing: 9
      • apps/server/src/environment/ServerEnvironment.ts
      • apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
      • apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts
      • packages/client-runtime/src/operations/commands.test.ts
      • packages/client-runtime/src/operations/commands.ts
      • packages/contracts/src/environment.test.ts
      • packages/contracts/src/environment.ts
      • packages/contracts/src/orchestrationV2.test.ts
      • packages/contracts/src/orchestrationV2.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

      📝 Walkthrough

      The change adds the optional threadStop environment capability and a client-dispatchable thread.stop command. When the capability is enabled, thread interruption without a run ID dispatches thread.stop instead of resolving a run from the projection.

      Changes: Thread-scoped stop

      Layer / File(s)Summary
      Stop command and capability contracts
      packages/contracts/src/environment.ts, packages/contracts/src/environment.test.ts, packages/contracts/src/orchestrationV2.ts, packages/contracts/src/orchestrationV2.test.ts
      The environment schema adds optional threadStop. The public command union adds thread.stop with a command ID, thread ID, and optional reason, and removes it from the server-only internal command union. Tests cover capability decoding and the minimal command shape.
      Capability-based client dispatch
      apps/server/src/environment/ServerEnvironment.ts, packages/client-runtime/src/operations/commands.ts, packages/client-runtime/src/operations/commands.test.ts
      The server advertises threadStop. When no run ID is supplied and the capability is enabled, the client dispatches thread.stop without a projection request. Tests also cover direct run interruption using run.interrupt.
      Thread-stop orchestration coverage
      apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts, apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
      The scenario test kit includes the target thread when collecting projections for thread.stop. The adapter test uses thread.stop to stop a completed run’s background command without a client-supplied run ID.

      Priority: ⬇️ Low

      Estimated code review effort: 2 (Simple) | ~15 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge, t3dotgg

      Merge Risk: ⚪ Minimal · up to 8662e

      The new thread-stop path preserves queued-work handling and does not appear to prevent an otherwise available interruption. No merge-blocking issue is established.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary change: stopping threads without resolving a run.
      Description checkPassedThe description includes all required sections, explains the problem and implementation, links issue #16586, and gives focused verification details, including that tests were not run.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    4. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB4.9 KiB−23 B (−0.5%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB−23 B (−1.9%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.8 KiB−41 B (−0.2%)29.3 KiB✅
      CodexLive turn messages21−1 (−50.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB−24 B (−0.5%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−24 B (−2.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB−41 B (−0.2%)29.3 KiB✅
      ClaudeLive turn messages21−1 (−50.0%)8✅

      Baseline: d5fdfdc · PR result: 8662eb6 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

Sign in to join this conversation.