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 23, 01:45 UTC
fix(server): Claude follow-ups no longer fail in Auto on models without Auto (#15687)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Guillermo Casanova committed
Oct 19, 2026 at 15:05 UTC
598298cc3c56ef6943301944d6986578f6b7d587
2 files changed
+92
-3
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+75
@@ -4546,6 +4546,71 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4546
),
4547
);
4548
4549
+ it.effect.each(["claude-haiku-4-5-20251001", "claude-sonnet-4-6"])(
4550
+ "renegotiates auto only when switching API models after fallback to default: %s",
4551
+ (nextModel) =>
4552
+ Effect.gen(function* () {
4553
+ const harness = yield* makeWakeHarnessWithOptions({ freshQueueOnReopen: true });
4554
+ const modelSelection = {
4555
+ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
4556
+ model: "claude-haiku-4-5-20251001",
4557
+ };
4558
+ const turnInput = {
4559
+ threadId: harness.threadId,
4560
+ providerThread: harness.providerThread,
4561
+ now: yield* DateTime.now,
4562
+ attachments: [],
4563
+ modelSelection,
4564
+ runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
4565
+ ...CLAUDE_TEST_RUNTIME_POLICY,
4566
+ runtimeMode: "auto",
4567
+ }),
4568
+ };
4569
+ yield* harness.runtime.startTurn(
4570
+ makeClaudeTestTurnInput({
4571
+ ...turnInput,
4572
+ attemptId: RunAttemptId.make("attempt-claude-auto-fallback-1"),
4573
+ text: "Hello.",
4574
+ }),
4575
+ );
4576
+ const openedOptions = harness.getOpenedOptions();
4577
+ assert.equal(openedOptions?.permissionMode, "auto");
4578
+ yield* harness.offerAndWait(claudeSdkFrame({ ...wakeTurnInit, permissionMode: "default" }));
4579
+ yield* Queue.offer(harness.sdkMessages, turnOneResult);
4580
+ yield* Queue.take(harness.terminalReceipts);
4581
+
4582
+ yield* harness.runtime.startTurn(
4583
+ makeClaudeTestTurnInput({
4584
+ ...turnInput,
4585
+ modelSelection: { ...modelSelection, model: nextModel },
4586
+ attemptId: RunAttemptId.make("attempt-claude-auto-fallback-2"),
4587
+ providerTurnOrdinal: 2,
4588
+ text: "Continue.",
4589
+ }),
4590
+ );
4591
+ if (nextModel === modelSelection.model) {
4592
+ assert.strictEqual(harness.getOpenedOptions(), openedOptions);
4593
+ assert.lengthOf(harness.processQueues, 1);
4594
+ } else {
4595
+ const resumedOptions = harness.getOpenedOptions();
4596
+ assert.notStrictEqual(resumedOptions, openedOptions);
4597
+ assert.equal(resumedOptions?.model, nextModel);
4598
+ assert.equal(resumedOptions?.resume, WAKE_NATIVE_SESSION);
4599
+ assert.isUndefined(resumedOptions?.sessionId);
4600
+ assert.equal(resumedOptions?.permissionMode, "auto");
4601
+ assert.lengthOf(harness.processQueues, 2);
4602
+ }
4603
+ assert.lengthOf(harness.offeredMessages, 2);
4604
+ assert.deepEqual(harness.permissionModeChanges, []);
4605
+ assert.deepEqual(harness.liveSelectionChanges, []);
4606
+ }).pipe(
4607
+ Effect.scoped,
4608
+ Effect.provide(
4609
+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
4610
+ ),
4611
+ ),
4612
+ );
4613
+
4614
it.effect("preserves typed Claude plans and todos through generic tool completion", () =>
4615
Effect.scoped(
4616
Effect.gen(function* () {
@@ -4627,6 +4692,9 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4692
harness.sdkMessages,
4693
toolResults("00000000-0000-4000-8000-000000000502", ["tool-todo-1"]),
4694
);
4695
+ yield* harness.offerAndWait(
4696
+ claudeSdkFrame({ ...wakeTurnInit, permissionMode: "bypassPermissions" }),
4697
+ );
4698
yield* Queue.offer(
4699
harness.sdkMessages,
4700
claudeSdkFrame({
@@ -4638,6 +4706,13 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4706
session_id: WAKE_NATIVE_SESSION,
4707
}),
4708
);
4709
+ yield* harness.offerAndWait(
4710
+ claudeSdkFrame({
4711
+ ...wakeTurnInit,
4712
+ uuid: "00000000-0000-4000-8000-000000000509",
4713
+ permissionMode: "plan",
4714
+ }),
4715
+ );
4716
yield* Queue.offer(
4717
harness.sdkMessages,
4718
makeResultFrame({
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+17
-3
@@ -3101,7 +3101,9 @@ interface ClaudeLiveQueryContext {
3101
// ("early") or only on its result. "acknowledged": the CLI confirmed it took a prompt's uuid
3102
// before any echo, so it echoes, but a resume's own turns can still run ahead of that prompt.
3103
promptEchoMode: "unknown" | "acknowledged" | "early" | "result_only";
3104
- readonly openedPermissionMode: PermissionMode;
3104
+ // The CLI may fall back from the requested mode on its first init frame.
3105
+ openedPermissionMode: PermissionMode;
3106
+ receivedInit: boolean;
3107
permissionMode: PermissionMode;
3108
stopping: boolean;
3109
readonly subagentsFromEarlierProcesses: ReadonlySet<ActiveClaudeSubagent>;
@@ -8455,7 +8457,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8457
existing.queryPolicyKey === queryPolicyKey &&
8458
!existing.stopping &&
8459
existing.selection.queryIdentity !== compiledSelection.queryIdentity &&
8458
- canApplyClaudeSelectionLive(existing.selection, compiledSelection)
8460
+ canApplyClaudeSelectionLive(existing.selection, compiledSelection) &&
8461
+ (existing.selection.apiModelId === compiledSelection.apiModelId ||
8462
+ existing.openedPermissionMode === queryPolicy.permissionMode)
8463
) {
8464
const live = existing;
8465
yield* live.query.setModel(compiledSelection.apiModelId).pipe(
@@ -8478,7 +8482,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8482
) {
8483
// Claude can switch its own mode mid-session (EnterPlanMode), and
8484
// a denied ExitPlanMode leaves it there. Put the live process back
8481
- // in the thread's mode before the next prompt.
8485
+ // in its initial mode before the next prompt.
8486
if (existing.permissionMode !== existing.openedPermissionMode) {
8487
yield* existing.query.setPermissionMode(existing.openedPermissionMode);
8488
existing.permissionMode = existing.openedPermissionMode;
@@ -8585,6 +8589,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8589
lastTurn: null,
8590
promptEchoMode: "unknown",
8591
openedPermissionMode: queryOptions.permissionMode,
8592
+ receivedInit: false,
8593
permissionMode: queryOptions.permissionMode,
8594
stopping: false,
8595
subagentsFromEarlierProcesses: new Set(
@@ -8598,6 +8603,15 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
8603
Stream.runForEach((message) =>
8604
sdkMessageLock.withPermits(1)(
8605
Effect.suspend(() => {
8606
+ if (
8607
+ message.type === "system" &&
8608
+ message.subtype === "init" &&
8609
+ !context.receivedInit
8610
+ ) {
8611
+ context.openedPermissionMode =
8612
+ message.permissionMode ?? context.openedPermissionMode;
8613
+ context.receivedInit = true;
8614
+ }
8615
if (
8616
message.type === "system" &&
8617
(message.subtype === "init" || message.subtype === "status") &&