@devries-cameron20 / t3code Mirror · read-only / commits / 0b127678b1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 17:15 UTC

fix(server): ACP threads accept a model change after their session detaches (#35951)

Julius Marminge committed Nov 12, 2026 at 20:37 UTC 0b127678b125520080eaef5ddc4f53b311430b3b
2 files changed +26 -5
apps/server/src/orchestration-v2/ProviderSwitchService.test.ts
+18
@@ -252,6 +252,24 @@ it.effect.each(["stopped", "error"] as const)(
252 ),
253 );
254
255 +it.effect("applies a model change on next turn after a settled thread's session detached", () =>
256 + Effect.gen(function* () {
257 + const service = yield* ProviderSwitch.ProviderSwitchServiceV2;
258 + const result = yield* service.plan({
259 + projection: { ...deadNativeThreadProjection("stopped"), providerSessions: [] },
260 + targetModelSelection: { instanceId: currentInstanceId, model: "gpt-5.2-codex" },
261 + });
262 + assert.equal(result.transition.type, "switch_model_in_session");
263 + assert.deepEqual(result.releaseProviderSessionIds, []);
264 + }).pipe(
265 + Effect.provide(
266 + layerTest({ [currentInstanceId]: { continuationKey: "codex:account:primary" } }, (input) =>
267 + Effect.succeed(acpSelectionTransition(input)),
268 + ),
269 + ),
270 + ),
271 +);
272 +
273 it.effect("rejects a model change the dead record never negotiated support for", () =>
274 Effect.gen(function* () {
275 const service = yield* ProviderSwitch.ProviderSwitchServiceV2;
apps/server/src/orchestration-v2/ProviderSwitchService.ts
+8 -5
@@ -104,11 +104,14 @@ export const layer: Layer.Layer<
104 Option.isSome(targetAdapter) &&
105 Option.isSome(currentInstance) &&
106 (currentSession !== undefined || currentProviderThread !== undefined)
107 - ? yield* targetAdapter.value.planSelectionTransition({
108 - current,
109 - target: targetModelSelection,
110 - sessionCapabilities: negotiatedCapabilities ?? currentInstance.value.capabilities,
111 - })
107 + ? negotiatedCapabilities === undefined
108 + ? // No session record left to switch in place; the next session starts with it.
109 + ({ type: "apply_on_next_turn" } as const)
110 + : yield* targetAdapter.value.planSelectionTransition({
111 + current,
112 + target: targetModelSelection,
113 + sessionCapabilities: negotiatedCapabilities,
114 + })
115 : undefined;
116 const transition =
117 Option.isNone(targetInstance) || Option.isNone(targetAdapter)