fix(server): a setting change no longer detaches a busy session kept from an earlier hand-off #35258
main fromrefs/pull/35258/head·merged by juliusmarminge View on GitHubProblem#
A queued hand-off keeps a source session that still has background work attached. Example: a queued Codex→Claude hand-off keeps the busy Codex session. After the Claude run completes, selecting a third instance (Grok) releases that Codex session. #35029's background-work check probed only providerContext.providerThreads, which holds just the active (Claude) and target threads. Codex probes per provider thread, found none of its own, reported no work, and the busy session was detached.
Change#
In Orchestrator.ts, when a command would detach a live session, the check now loads the thread's provider threads (getThreadRecords(threadId, ["providerThreads"], { omitSettledSubagentRecords: true }), the filter the queued hand-off probe uses) and probes against them. The extra read happens only when a live session would be detached. #35029's rules are unchanged: a failed probe counts as busy, archive and settle are exempt, and the refusal message is the same. No contract or client changes.
Scope and approval#
Bug fix: a gap in #35029's protection. One problem.
Verification#
New regression in testkit/ProviderSwitch.integration.test.ts: a queued Codex→Claude hand-off keeps busy Codex, Claude completes, and thread.model-selection.set to Grok must be refused with #35029's message while Codex stays attached. Once the work ends, the selection succeeds and Codex is released.
- On
591188471awith only the production change reverted: 1 failed. The selection was accepted andprovider-session.detachedwas emitted for the Codex session. - With the fix: passes.
ProviderSwitch.integration.test.ts,Orchestrator.control-reads.test.ts,ProviderSwitchService.test.tsandruntimeLayer.test.ts: 249 passed. vp fmt --check,vp linton the changed files, and theapps/servertypecheck: clean.
Worktree changes go through the same check, but there is no committed test for them. Not checked: the full server suite, live Codex or Claude CLIs.
Written by Claude Opus 5.5 in Claude Code (T3 Code), reviewed by GPT-6.1 Sol.
🤖 Generated with Claude Code
- 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
No actionable comments were generated in the recent review.
Walkthrough
-
The orchestrator now checks all provider threads, excluding settled subagent records, for background work before eligible thread mutations. An integration test verifies that a busy Codex session blocks a provider switch until its background work clears.
Changes: Provider session guard
Layer / File(s) Summary Check retained sessions before provider changes
apps/server/src/orchestration-v2/Orchestrator.ts,apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.tsFor mutations other than archive and settle, the orchestrator checks all provider threads when live sessions exist. The integration test verifies that pending Codex background work blocks a switch to Grok, then allows it after the work clears. Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge,t3dotgg
Merge Risk:
Minimal · up to8b71f-
This fix keeps a busy session from an earlier hand-off attached when a provider setting changes. The change is narrow and has a targeted regression test, so merge risk is minimal.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: a setting (provider/model selection) change no longer detaches a busy session kept from an earlier queued hand-off. The raw summary and PR objectives both describe a b… Description check The description follows the template's sections: Problem, Change, Scope, and Verification. The Problem section explains the bug and the cause. The Change section explains the fix in Orchestrator.ts an… 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. Full details: Title check
-
Explanation
The title names the main change: a setting (provider/model selection) change no longer detaches a busy session kept from an earlier queued hand-off. The raw summary and PR objectives both describe a background-work check in Orchestrator.ts that now loads all provider threads before detaching a live session, and a regression test for this case. The title is specific and follows the conventional commit format from the template.
Full details: Description check
-
Explanation
The description follows the template's sections: Problem, Change, Scope, and Verification. The Problem section explains the bug and the cause. The Change section explains the fix in Orchestrator.ts and states that no contract or client changes are needed. The Scope section calls this a bug fix and links to the prior change
#35029, but it does not link a bug issue or explain why no issue is needed. The Verification section lists the regression test, the revert check with its observed failure, and the passing test counts, and it states what was not checked. The Scope gap is minor, so the description is mostly complete.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 2e33134
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a73ead48-b5f5-402a-98ae-74cba21895bb
Commits-
Reviewing files that changed from the base of the PR and between 3d1847e2a50c66d855d712a4ce8e0dcdf9a92389 and 8b71f74ec66bac340458246da5372468c781b139.
Files selected for processing: 2-
apps/server/src/orchestration-v2/Orchestrator.tsapps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
tanstack-source added labelsbug
This PR conflicts with
main. Rebase it or mergemaininto it. If it still conflicts after 7 days with no activity, it will be closed automatically.See the conflict window.
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
juliusmarminge added labelstakeover:in-progress
Evidence#
Real web app, Chromium, light theme, 1280×800 CSS viewport, fresh synthetic databases on both commits. Started the background sleep and foreground sleep with Codex GPT-6-Astra, queued Claude Haiku 5.5 with Ctrl+Enter, waited for the handoff, selected Replay/Showcase without sending, then called t3_thread_configure with devReplay/showcase.
Before After 2e33134186 8b71f74ec6 

Accepted; saved devReplay, emptied bindings and killed sleep 900. Refused; kept Claude selection, both session bindings and sleep 900. Before recording After recording Head subsequently completed the original command naturally with exit 0 and output bg-done. The identical settings retry then succeeded and detached the idle sessions.

Completion and retry recording · Runtime transcript including refusal and successful retry
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged thisa767d23
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.
Approvability#
Verdict: Approved at
3d1847eMacroscope's review found this PR approvable — Settings changes now check retained sessions for background work before detaching them, preventing interruptions after earlier provider hand-offs. The change is narrowly scoped and preserves existing archive and settle behavior.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).