fix(server): stop threads without resolving a run #22052
main fromrefs/pull/22052/head·merged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHubProblem#
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
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
juliusmarminge added labelsmacroscope-review
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.tsapps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsapps/server/src/orchestration-v2/testkit/OrchestratorScenario.tspackages/client-runtime/src/operations/commands.test.tspackages/client-runtime/src/operations/commands.tspackages/contracts/src/environment.test.tspackages/contracts/src/environment.tspackages/contracts/src/orchestrationV2.test.tspackages/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
threadStopenvironment capability and a client-dispatchablethread.stopcommand. When the capability is enabled, thread interruption without a run ID dispatchesthread.stopinstead 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.tsThe environment schema adds optional threadStop. The public command union addsthread.stopwith 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.tsThe server advertises threadStop. When no run ID is supplied and the capability is enabled, the client dispatchesthread.stopwithout a projection request. Tests also cover direct run interruption usingrun.interrupt.Thread-stop orchestration coverage
apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts,apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsThe scenario test kit includes the target thread when collecting projections for thread.stop. The adapter test usesthread.stopto 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:
4-
Check name Status Explanation Title check The title clearly and concisely describes the primary change: stopping threads without resolving a run. Description check The 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 check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check 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
-
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 4.9 KiB −23 B (−0.5%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB −23 B (−1.9%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.8 KiB −41 B (−0.2%) 29.3 KiB ✅ Codex Live turn messages 2 1 −1 (−50.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB −24 B (−0.5%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB −24 B (−2.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB −41 B (−0.2%) 29.3 KiB ✅ Claude Live turn messages 2 1 −1 (−50.0%) 8 ✅ Baseline:
d5fdfdc· PR result:8662eb6· Source CI: successScenario 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.
Yash-Singh1(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — This PR promotes the existing internal
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).thread.stopcommand 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.