Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a setting change no longer detaches a busy session kept from an earlier hand-off #35258

MergedMikaMcFlurry(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/35258/headmerged by juliusmarminge View on GitHub

Problem

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 591188471a with only the production change reverted: 1 failed. The selection was accepted and provider-session.detached was emitted for the Codex session.
  • With the fix: passes. ProviderSwitch.integration.test.ts, Orchestrator.control-reads.test.ts, ProviderSwitchService.test.ts and runtimeLayer.test.ts: 249 passed.
  • vp fmt --check, vp lint on the changed files, and the apps/server typecheck: 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

    2. Approvability

      Verdict: Approved at 3d1847e

      Macroscope'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).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      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.ts
      For 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 to 8b71f

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe 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 checkPassedThe 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 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.
      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

      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.ts
      • apps/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.

    4. tanstack-source added labelsbug

    5. This PR conflicts with main. Rebase it or merge main into it. If it still conflicts after 7 days with no activity, it will be closed automatically.

      See the conflict window.

    6. juliusmarminge added labelstakeover:in-progress

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

      BeforeAfter
      2e331341868b71f74ec6
      Before: retained command lostAfter: retained command preserved
      Accepted; saved devReplay, emptied bindings and killed sleep 900.Refused; kept Claude selection, both session bindings and sleep 900.
      Before recordingAfter 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.

      Head: background command completed naturally

      Completion and retry recording · Runtime transcript including refusal and successful retry

      Settings MCP driver · Synthetic seed script · Browser steps

    8. juliusmarminge added labelstakeover:ready

    9. juliusmarminge removed labelstakeover:in-progress

    10. juliusmarminge merged thisa767d23

    11. juliusmarminge closed this

    12. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.