From bce32db56b5b07fa312449c9004765374220ec82 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 14:58:43 +0000 Subject: [PATCH 1/3] fix(server): an Antigravity thread in Auto asks agy for Auto instead of silently running Supervised When agy's session did not list `auto`, T3 mapped Auto to agy's `default` mode without telling anyone. The thread still said Auto, but every command, even `ls`, waited for approval. T3 now always asks agy for Auto. Where agy does not offer it, agy's refusal (for example "Auto mode is not available: it needs the OS terminal sandbox") reaches the user instead. Co-Authored-By: Claude Opus 5.5 --- .../provider/Drivers/AntigravityDriver.test.ts | 9 +++++++-- .../src/provider/Drivers/AntigravityDriver.ts | 16 ++++++++++++---- .../provider/acp/AntigravityAcpSupport.test.ts | 13 +++++-------- .../src/provider/acp/AntigravityAcpSupport.ts | 18 +++++------------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts index 3c0135f419c66..27d4f2c0bf0d6 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts @@ -421,8 +421,13 @@ it.layer(layerTest)("AntigravityDriver", (it) => { ]); // The agy CLI rejects `yolo` and `auto_edit`; it stays in `default` and T3 answers its requests. + // Auto is asked for even where agy does not list it, so agy can say why it refuses. h.controls.selected = yield* h.makeExecutable("runtime cli", { initialMode: "auto_edit" }); - for (const runtimeMode of ["full-access", "auto-accept-edits"] as const) { + for (const [runtimeMode, sessionMode] of [ + ["full-access", "default"], + ["auto-accept-edits", "default"], + ["auto", "auto"], + ] as const) { const requestsBefore = (yield* h.readRequests).length; const cliThreadId = ThreadId.make(`thread-antigravity-cli-${runtimeMode}`); const cliPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ @@ -457,7 +462,7 @@ it.layer(layerTest)("AntigravityDriver", (it) => { request.params?.configId === "mode", ) .map((request) => request.params?.value), - ).toEqual(["default"]); + ).toEqual([sessionMode]); } }), ); diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.ts b/apps/server/src/provider/Drivers/AntigravityDriver.ts index b0d11b453dc61..add384cbfb89f 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.ts @@ -357,12 +357,20 @@ export const AntigravityDriver: ProviderDriver< }); return { ...runtime, - setMode: (modeId: string) => - runtime.getModeState.pipe( + setMode: (modeId: string) => { + const sessionMode = antigravitySessionMode(modeId); + if (sessionMode !== "auto") return runtime.setMode(sessionMode); + // agy lists Auto only where it can run it; asking anyway returns agy's reason. + return runtime.getModeState.pipe( Effect.flatMap((modeState) => - runtime.setMode(antigravitySessionMode(modeId, modeState)), + modeState?.availableModes.some((mode) => mode.id === "auto") === true + ? runtime.setMode(sessionMode) + : runtime + .setConfigOption("mode", sessionMode, { allowUnlistedValue: true }) + .pipe(Effect.as({})), ), - ), + ); + }, start: () => startCompatible().pipe( Effect.tapError((cause): Effect.Effect => diff --git a/apps/server/src/provider/acp/AntigravityAcpSupport.test.ts b/apps/server/src/provider/acp/AntigravityAcpSupport.test.ts index 7201d1edc0ba0..8055f030d774b 100644 --- a/apps/server/src/provider/acp/AntigravityAcpSupport.test.ts +++ b/apps/server/src/provider/acp/AntigravityAcpSupport.test.ts @@ -91,14 +91,11 @@ describe("Antigravity release gates", () => { describe("Antigravity Auto", () => { it.each([ - { offered: ["default", "accept-edits", "auto", "plan"], expected: "auto" }, - { offered: ["default", "accept-edits", "plan"], expected: "default" }, - ])("runs as $expected when the session offers $offered", ({ offered, expected }) => { - const modeState = { - currentModeId: "default", - availableModes: offered.map((id) => ({ id, name: id })), - }; - expect(antigravitySessionMode("auto", modeState)).toBe(expected); + { requested: "auto", expected: "auto" }, + { requested: "yolo", expected: "default" }, + { requested: "auto_edit", expected: "default" }, + ])("runs $requested as $expected", ({ requested, expected }) => { + expect(antigravitySessionMode(requested)).toBe(expected); }); it.each(["execute", "read"] as const)("asks about the %s requests agy's Auto sends", (kind) => { diff --git a/apps/server/src/provider/acp/AntigravityAcpSupport.ts b/apps/server/src/provider/acp/AntigravityAcpSupport.ts index 4d57305f7e0ec..68805e4c1204f 100644 --- a/apps/server/src/provider/acp/AntigravityAcpSupport.ts +++ b/apps/server/src/provider/acp/AntigravityAcpSupport.ts @@ -28,7 +28,6 @@ import { unknownRecord, type AcpRuntimePolicy, } from "@t3tools/provider-acp/server/clientPolicy"; -import type { AcpSessionModeState } from "@t3tools/provider-acp/server/runtimeModel"; import { T3_MCP_TOOL_NAMES } from "@t3tools/shared/t3McpToolPresentation"; import packageJson from "../../../package.json" with { type: "json" }; import { normalizeAntigravitySessionUpdate } from "./AntigravityProtocol.ts"; @@ -167,19 +166,12 @@ export function antigravityPermissionMode(runtimeMode: RuntimeMode): string { } /** - * The agy CLI rejects `yolo` and `auto_edit`, and sessions without native Auto reject `auto`. - * Those stay in `default`, where it asks before acting and T3 answers from the live runtime - * policy, so permission changes apply on the next turn without a restart. + * The agy CLI rejects `yolo` and `auto_edit`; those stay in `default`, where it asks before acting + * and T3 answers from the live runtime policy, so permission changes apply on the next turn without + * a restart. Auto is always requested: agy explains its refusal, where `default` would ask about + * every command while the thread still says Auto. */ -export function antigravitySessionMode( - modeId: string, - modeState: AcpSessionModeState | undefined, -): string { - if (modeId === "auto") { - return modeState?.availableModes.some((mode) => mode.id === "auto") === true - ? "auto" - : "default"; - } +export function antigravitySessionMode(modeId: string): string { return modeId === "yolo" || modeId === "auto_edit" ? "default" : modeId; } From 37a51fbd95b783082c1c8bcb62d3c9543297f41d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 15:26:18 +0000 Subject: [PATCH 2/3] fix(server): a refused Auto fails the turn with a reason instead of retrying as Supervised When agy refused Auto, the turn start was retried. The retry resolved the permission policy again, by then without Auto, so the prompt ran Supervised and the user saw no reason. An agent's refusal of the policy's session mode is now an AcpPermissionModeError with a message shown to the user, and the turn start does not retry it. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/AcpAdapterV2.test.ts | 52 +++++++++++++++++++ .../ProviderTurnStartService.test.ts | 23 +++++--- .../ProviderTurnStartService.ts | 13 +++-- packages/provider-acp/src/server/adapter.ts | 23 +++++++- packages/provider-core/src/server/failure.ts | 1 + 5 files changed, 100 insertions(+), 12 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index 7815f8d959a2f..235f0f293bc61 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -101,6 +101,7 @@ import { import { appendUserInputAttachmentPaths } from "../../provider/userInputAttachments.ts"; +import { knownProviderFailureMessage } from "@t3tools/provider-core/server/failure"; import { makeGrokAcpAdapterFlavor } from "@t3tools/provider-grok/testing"; import { acpRegistryPromptFailure, @@ -2957,6 +2958,57 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(layerTest)), ); + it.live( + "fails the session open with a permission mode error when the agent refuses the mode", + () => + Effect.gen(function* () { + const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; + const mockAgentPath = yield* bundledMockAgentPath; + const instanceId = ProviderInstanceId.make("acp-test-refused-policy-mode"); + const threadId = ThreadId.make("thread-acp-refused-policy-mode"); + const adapter = yield* makeAcpAdapterV2({ + instanceId, + flavor: { + driver: ACP_TEST_DRIVER, + capabilities: AcpProviderCapabilitiesV2, + sessionModeForPolicy: () => "code", + makeRuntime: makeMockRuntime({ + childProcessSpawner, + mockAgentPath, + environment: { T3_ACP_FAIL_SET_MODE_CONFIG_OPTION: "1" }, + }), + }, + selfInvocation: yield* resolveSelfInvocation(), + }); + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "auto", + interactionMode: "default", + cwd: process.cwd(), + }); + const modelSelection = { instanceId, model: "composer-2" } as const; + const result = yield* Effect.exit( + adapter + .openSession({ + threadId, + providerSessionId: ProviderSessionId.make("provider-session-acp-refused-mode"), + modelSelection, + runtimePolicy, + }) + .pipe( + Effect.flatMap((runtime) => + runtime.ensureThread({ threadId, modelSelection, runtimePolicy }), + ), + ), + ); + const error = Exit.isFailure(result) ? Cause.squash(result.cause) : undefined; + assert.instanceOf(error, ProviderAdapter.ProviderAdapterOpenSessionError); + assert.strictEqual( + knownProviderFailureMessage(error), + 'The agent does not offer its "code" mode in this session. Choose another permission mode, then retry.', + ); + }).pipe(Effect.provide(layerTest)), + ); + it.live("reapplies a selection after a switch away from it failed partway", () => Effect.gen(function* () { const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts index ef9bd2bb32712..a19c9c27cb5c6 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts @@ -3197,14 +3197,28 @@ effectIt.effect("fails rather than starts a fresh thread when a resume outcome i }), ); -effectIt.effect("fails the run without a retry when the provider needs sign-in", () => +const refusedModeMessage = + 'The agent does not offer its "auto" mode in this session. Choose another permission mode, then retry.'; + +effectIt.effect.each([ + { + name: "the provider needs sign-in", + failure: { requiresSignIn: true } as const, + message: "Failed to open antigravity provider session new-provider-session.", + }, + { + name: "the agent refuses the permission mode", + failure: { cause: { _tag: "AcpPermissionModeError", message: refusedModeMessage } }, + message: refusedModeMessage, + }, +])("fails the run without a retry when $name", ({ failure, message }) => Effect.gen(function* () { const harness = makeLocalCommandHarness({ text: "Continue", openFailure: new ProviderAdapter.ProviderAdapterOpenSessionError({ driver: ProviderDriverKind.make("antigravity"), providerSessionId: ProviderSessionId.make("new-provider-session"), - requiresSignIn: true, + ...failure, }), }); @@ -3216,10 +3230,7 @@ effectIt.effect("fails the run without a retry when the provider needs sign-in", { type: "error", status: "failed", - failure: { - class: "provider_error", - message: "Failed to open antigravity provider session new-provider-session.", - }, + failure: { class: "provider_error", message }, }, ]); }), diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 1cb77e387f950..3304787bda0f4 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -986,11 +986,14 @@ export const layer: Layer.Layer< ); if (sessionResult._tag === "Failure") { const failure = sessionResult.failure; - const requiresSignIn = - "cause" in failure && - isProviderAdapterOpenSessionError(failure.cause) && - failure.cause.requiresSignIn === true; - if (input.willRetry === true && !requiresSignIn) return yield* failure; + const openError = + "cause" in failure && isProviderAdapterOpenSessionError(failure.cause) + ? failure.cause + : undefined; + const requiresSignIn = openError?.requiresSignIn === true; + // A retry resolves the policy again and could run a mode the user did not pick. + const refusedMode = Predicate.isTagged(openError?.cause, "AcpPermissionModeError"); + if (input.willRetry === true && !requiresSignIn && !refusedMode) return yield* failure; yield* settleStartFailure({ signal: "provider-session-open-failure", title: "Provider session failed to open", diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 21fe311588906..88206e0a9bf1d 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -307,6 +307,19 @@ class AcpModelSelectionError extends Schema.TaggedError( } } +/** The agent refused the session mode the thread's permission level maps to. */ +class AcpPermissionModeError extends Schema.TaggedError()( + "AcpPermissionModeError", + { + mode: Schema.String, + cause: Schema.Defect(), + }, +) { + override get message(): string { + return `The agent does not offer its "${this.mode}" mode in this session. Choose another permission mode, then retry.`; + } +} + /** A prompt-steered turn spans several prompts, each reporting its own usage. */ function addAcpUsage( total: EffectAcpSchema.Usage | undefined, @@ -8290,7 +8303,15 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( const policyMode = flavor.sessionModeForPolicy?.(runtimePolicy); const modeLocked = flavor.lockSessionModeToPolicy && policyMode !== undefined; if (policyMode !== undefined) { - yield* runtime.setMode(policyMode); + yield* runtime + .setMode(policyMode) + .pipe( + Effect.mapError((error) => + error._tag === "AcpRequestError" && error.code === -32602 + ? new AcpPermissionModeError({ mode: policyMode, cause: error }) + : error, + ), + ); } const modeState = yield* runtime.getModeState; if ( diff --git a/packages/provider-core/src/server/failure.ts b/packages/provider-core/src/server/failure.ts index e7d47cdb2175e..90155d6ca4508 100644 --- a/packages/provider-core/src/server/failure.ts +++ b/packages/provider-core/src/server/failure.ts @@ -129,6 +129,7 @@ function curatedCauseMessages(cause: unknown): { category: categoryMessage(), }; case "AcpModelSelectionError": + case "AcpPermissionModeError": case "ClaudeBackgroundWorkBlocksQueryReplacementError": case "ClaudeAppendSystemPromptFileError": case "ClaudeAppendSystemPromptMissingValueError": From 82c24d4ca20e134eece313e84d6b00d8dce6a5b2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 15:31:24 +0000 Subject: [PATCH 3/3] fix(server): request Antigravity Auto through the normal mode path The unlisted-value write for Auto updated config options but not the cached session mode, so if agy ever accepted it, a later switch back to Supervised was skipped. A refused Auto now reports T3's own permission mode message, so the plain setMode, whose client check rejects an unlisted Auto with the same invalid-params code, gives the same result without that gap. Co-Authored-By: Claude Opus 5.5 --- .../Drivers/AntigravityDriver.test.ts | 36 +++++++++++++++---- .../src/provider/Drivers/AntigravityDriver.ts | 15 +------- .../src/provider/acp/AntigravityAcpSupport.ts | 4 +-- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts index 27d4f2c0bf0d6..d109a6c4f7a66 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts @@ -421,13 +421,8 @@ it.layer(layerTest)("AntigravityDriver", (it) => { ]); // The agy CLI rejects `yolo` and `auto_edit`; it stays in `default` and T3 answers its requests. - // Auto is asked for even where agy does not list it, so agy can say why it refuses. h.controls.selected = yield* h.makeExecutable("runtime cli", { initialMode: "auto_edit" }); - for (const [runtimeMode, sessionMode] of [ - ["full-access", "default"], - ["auto-accept-edits", "default"], - ["auto", "auto"], - ] as const) { + for (const runtimeMode of ["full-access", "auto-accept-edits"] as const) { const requestsBefore = (yield* h.readRequests).length; const cliThreadId = ThreadId.make(`thread-antigravity-cli-${runtimeMode}`); const cliPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ @@ -462,8 +457,35 @@ it.layer(layerTest)("AntigravityDriver", (it) => { request.params?.configId === "mode", ) .map((request) => request.params?.value), - ).toEqual([sessionMode]); + ).toEqual(["default"]); } + // A session without agy's own Auto must not run an Auto thread in `default`. + const autoThreadId = ThreadId.make("thread-antigravity-cli-auto"); + const autoPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: "auto", + interactionMode: "default", + cwd: workspace, + }); + const autoOpen = yield* h.instance.orchestrationAdapter + .openSession({ + threadId: autoThreadId, + providerSessionId: ProviderSessionId.make("provider-session-cli-auto"), + modelSelection, + runtimePolicy: autoPolicy, + }) + .pipe( + Effect.flatMap((autoSession) => + autoSession.ensureThread({ + threadId: autoThreadId, + modelSelection, + runtimePolicy: autoPolicy, + }), + ), + Effect.flip, + ); + expect(knownProviderFailureMessage(autoOpen)).toBe( + 'The agent does not offer its "auto" mode in this session. Choose another permission mode, then retry.', + ); }), ); diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.ts b/apps/server/src/provider/Drivers/AntigravityDriver.ts index add384cbfb89f..d16b7697dd129 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.ts @@ -357,20 +357,7 @@ export const AntigravityDriver: ProviderDriver< }); return { ...runtime, - setMode: (modeId: string) => { - const sessionMode = antigravitySessionMode(modeId); - if (sessionMode !== "auto") return runtime.setMode(sessionMode); - // agy lists Auto only where it can run it; asking anyway returns agy's reason. - return runtime.getModeState.pipe( - Effect.flatMap((modeState) => - modeState?.availableModes.some((mode) => mode.id === "auto") === true - ? runtime.setMode(sessionMode) - : runtime - .setConfigOption("mode", sessionMode, { allowUnlistedValue: true }) - .pipe(Effect.as({})), - ), - ); - }, + setMode: (modeId: string) => runtime.setMode(antigravitySessionMode(modeId)), start: () => startCompatible().pipe( Effect.tapError((cause): Effect.Effect => diff --git a/apps/server/src/provider/acp/AntigravityAcpSupport.ts b/apps/server/src/provider/acp/AntigravityAcpSupport.ts index 68805e4c1204f..5403c004ba8a9 100644 --- a/apps/server/src/provider/acp/AntigravityAcpSupport.ts +++ b/apps/server/src/provider/acp/AntigravityAcpSupport.ts @@ -168,8 +168,8 @@ export function antigravityPermissionMode(runtimeMode: RuntimeMode): string { /** * The agy CLI rejects `yolo` and `auto_edit`; those stay in `default`, where it asks before acting * and T3 answers from the live runtime policy, so permission changes apply on the next turn without - * a restart. Auto is always requested: agy explains its refusal, where `default` would ask about - * every command while the thread still says Auto. + * a restart. Auto is always requested: a session without it fails to open, where `default` would + * ask about every command while the thread still says Auto. */ export function antigravitySessionMode(modeId: string): string { return modeId === "yolo" || modeId === "auto_edit" ? "default" : modeId;