@devries-cameron20 / t3code-1 / commits / f68d36d8aa
Fork 0

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

fix(antigravity): a mid-turn 404 shows its error and is retryable (#39869)

Julius Marminge committed Nov 20, 2026 at 13:27 UTC f68d36d8aa9ca83eff811f285c4d20fc31e1a3bd
4 files changed +232 -13
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+111
@@ -1527,6 +1527,117 @@ describe("AcpAdapterV2", () => {
1527 );
1528 }).pipe(Effect.provide(layerTest)),
1529 );
1530 + it.live("resends a resumable outcome failure's prompt once before failing the turn", () =>
1531 + Effect.gen(function* () {
1532 + const instanceId = ProviderInstanceId.make("acp-test-prompt-resume");
1533 + const threadId = ThreadId.make("thread-acp-prompt-resume");
1534 + const notFound = {
1535 + class: "provider_error",
1536 + message: "Requested entity was not found.",
1537 + code: "NOT_FOUND",
1538 + retryable: true,
1539 + } as const;
1540 + const promptTexts: Array<string> = [];
1541 + // Checks 1, 3 and 4 fail: turn 1 resumes and completes, turn 2 fails after one resume.
1542 + let checks = 0;
1543 + const adapter = yield* makeAcpAdapterV2({
1544 + instanceId,
1545 + selfInvocation: yield* resolveSelfInvocation(),
1546 + flavor: {
1547 + driver: ACP_TEST_DRIVER,
1548 + capabilities: AcpProviderCapabilitiesV2,
1549 + steersWithPrompt: () => true,
1550 + watchPromptOutcome: () =>
1551 + Effect.sync(() => {
1552 + checks += 1;
1553 + const outcome =
1554 + checks === 2
1555 + ? undefined
1556 + : {
1557 + failure: notFound,
1558 + threadDisposition: "reusable" as const,
1559 + resumeWith: "continue",
1560 + };
1561 + return () => Effect.succeed(outcome);
1562 + }),
1563 + makeRuntime: makeMockRuntime({
1564 + childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
1565 + mockAgentPath: yield* bundledMockAgentPath,
1566 + wrapRuntime: (runtime) => ({
1567 + ...runtime,
1568 + prompt: (payload) =>
1569 + Effect.sync(() => {
1570 + promptTexts.push(
1571 + payload.prompt
1572 + .flatMap((block) => (block.type === "text" ? [block.text] : []))
1573 + .join("\n"),
1574 + );
1575 + return { stopReason: "end_turn" as const };
1576 + }),
1577 + }),
1578 + }),
1579 + },
1580 + });
1581 + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1582 + runtimeMode: "full-access",
1583 + interactionMode: "default",
1584 + cwd: process.cwd(),
1585 + });
1586 + const modelSelection = { instanceId, model: "default" } as const;
1587 + const runtime = yield* adapter.openSession({
1588 + threadId,
1589 + providerSessionId: ProviderSessionId.make("provider-session-acp-prompt-resume"),
1590 + modelSelection,
1591 + runtimePolicy,
1592 + });
1593 + const providerThread = yield* runtime.ensureThread({
1594 + threadId,
1595 + modelSelection,
1596 + runtimePolicy,
1597 + });
1598 + const runTurn = (ordinal: number) =>
1599 + Effect.gen(function* () {
1600 + yield* runtime.startTurn(
1601 + makeTurnInput({
1602 + threadId,
1603 + providerThread,
1604 + instanceId,
1605 + runtimePolicy,
1606 + now: yield* DateTime.now,
1607 + ordinal,
1608 + }),
1609 + );
1610 + return Array.from(
1611 + yield* runtime.events.pipe(
1612 + Stream.takeUntil((event) => event.type === "turn.terminal"),
1613 + Stream.runCollect,
1614 + ),
1615 + );
1616 + });
1617 + const retryTitles = (events: ReadonlyArray<ProviderAdapter.ProviderAdapterV2Event>) =>
1618 + events.flatMap((event) =>
1619 + event.type === "turn_item.updated" &&
1620 + event.turnItem.type === "error" &&
1621 + event.turnItem.retry !== undefined
1622 + ? [event.turnItem.title]
1623 + : [],
1624 + );
1625 +
1626 + const resumed = yield* runTurn(1);
1627 + const completed = resumed.at(-1);
1628 + assert.equal(completed?.type === "turn.terminal" ? completed.status : null, "completed");
1629 + assert.deepEqual(promptTexts.slice(1), ["continue"]);
1630 + assert.deepEqual(retryTitles(resumed), ["Provider retry", "Provider recovered"]);
1631 +
1632 + const failedEvents = yield* runTurn(2);
1633 + const failed = failedEvents.at(-1);
1634 + if (failed?.type !== "turn.terminal" || failed.status !== "failed") {
1635 + return assert.fail("expected a failed terminal");
1636 + }
1637 + assert.deepEqual(failed.failure, notFound);
1638 + assert.deepEqual(promptTexts.slice(3), ["continue"], "a turn resumes only once");
1639 + }).pipe(Effect.provide(layerTest)),
1640 + );
1641 it.live("retains returned usage when Stop finalizes before the prompt callback", () =>
1642 Effect.gen(function* () {
1643 const instanceId = ProviderInstanceId.make("acp-test-prompt-usage-stop");
apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts
+38
@@ -40,6 +40,16 @@ const MISSING_SIGNATURE_ERROR = errorPayload(
40 const INVALID_SIGNATURE_ERROR = errorPayload(
41 'Error 400, Message: {"type":"error","error":{"type":"invalid_request_error","message":"messages.3.content.0: Invalid `signature` in `thinking` block"}}, Status: INVALID_ARGUMENT, Details: []',
42 );
43 +const NOT_FOUND_ERROR = errorPayload(
44 + "Error 404, Message: Requested entity was not found., Status: NOT_FOUND, Details: []",
45 +);
46 +// Antigravity 1.5 with a Google account writes "STATUS (code NNN): message", then the HTTP body.
47 +const STATUS_NOT_FOUND_ERROR = Buffer.concat([
48 + Buffer.from([0x12, 0x37]),
49 + Buffer.from(
50 + 'NOT_FOUND (code 404): Requested entity was not found.\u001a\u0080\u0001HTTP 404 Not Found\n\n{"error":{"code":404,"message":"Requested entity was not found.","status":"NOT_FOUND"}}',
51 + ),
52 +]);
53 // The model's reply quoting the agent's quota notice is an ordinary planner response.
54 const QUOTED_NOTICE = Buffer.from(
55 "Usage Limit Reached\n\nYou have reached your current quota for this period. Your limit will reset in 1 hour.",
@@ -139,6 +149,34 @@ describe("watchAntigravityPromptOutcome", () => {
149 retryable: false,
150 }),
151 );
152 + // A 404 after the turn already reached the model is a transient edge error, not a bad model.
153 + for (const error of [NOT_FOUND_ERROR, STATUS_NOT_FOUND_ERROR]) {
154 + assert.deepEqual(
155 + yield* turn([
156 + [USER_INPUT, input],
157 + [PLANNER_RESPONSE, reply],
158 + [TOOL, reply],
159 + [ERROR_MESSAGE, error],
160 + ]),
161 + {
162 + ...reusable({
163 + class: "provider_error",
164 + message: "Requested entity was not found.",
165 + code: "NOT_FOUND",
166 + retryable: true,
167 + }),
168 + resumeWith: "continue",
169 + },
170 + );
171 + }
172 + // A 404 before the model answered is an unknown or unentitled model.
173 + assert.equal(
174 + (yield* turn([
175 + [USER_INPUT, input],
176 + [ERROR_MESSAGE, STATUS_NOT_FOUND_ERROR],
177 + ]))?.failure.retryable,
178 + false,
179 + );
180 // A saved thinking block without a valid signature fails every later prompt.
181 for (const error of [MISSING_SIGNATURE_ERROR, INVALID_SIGNATURE_ERROR]) {
182 const outcome = yield* turn([
apps/server/src/provider/acp/AntigravityTurnOutcome.ts
+34 -11
@@ -15,10 +15,14 @@ import { antigravityManagedPath, antigravityProfileRoot } from "./AntigravityPro
15
16 // CORTEX_STEP_TYPE_ERROR_MESSAGE in the native trajectory.
17 const ERROR_STEP_TYPE = 17;
18 +// CORTEX_STEP_TYPE_PLANNER_RESPONSE: the model answered within this turn.
19 +const PLANNER_RESPONSE_STEP_TYPE = 15;
20 // The harness error text leads the payload; a Go stack trace follows it.
21 const MAX_ERROR_PAYLOAD_BYTES = 16_384;
22 // The Go harness's rendering of a Google API error, as the agent's api_errors.py reads it.
23 const API_ERROR = /Error (\d{3}), Message: (.+?), Status: ([A-Z_]+)/s;
24 +// Antigravity 1.5 with a Google account writes "STATUS (code NNN): message".
25 +const STATUS_ERROR = /(?<![A-Z_])([A-Z_]+) \(code (\d{3})\): (\P{Cc}+)/u;
26 const QUOTA_EXHAUSTED = /\breason:QUOTA_EXHAUSTED\b/;
27 // Claude rejects a saved thinking block without a valid signature. It sits in the native
28 // history, so every later prompt to that session fails the same way.
@@ -44,6 +48,7 @@ const NATIVE_SESSION_ID = /^[\w-]+$/;
48 interface LastStep {
49 readonly type: number;
50 readonly payload: Uint8Array | null;
51 + readonly reachedModel: boolean;
52 }
53
54 class AntigravitySessionLogError extends Schema.TaggedError<AntigravitySessionLogError>()(
@@ -90,7 +95,15 @@ const lastStepAfter =
95 )
96 .get(MAX_ERROR_PAYLOAD_BYTES, index);
97 if (typeof row?.type !== "number") return undefined;
93 - return { type: row.type, payload: row.payload instanceof Uint8Array ? row.payload : null };
98 + const reachedModel =
99 + database
100 + .prepare("SELECT 1 FROM steps WHERE idx > ? AND step_type = ? LIMIT 1")
101 + .get(index, PLANNER_RESPONSE_STEP_TYPE) !== undefined;
102 + return {
103 + type: row.type,
104 + payload: row.payload instanceof Uint8Array ? row.payload : null,
105 + reachedModel,
106 + };
107 };
108
109 function resetAtFrom(text: string, now: DateTime.Utc): string | undefined {
@@ -106,6 +119,12 @@ function resetAtFrom(text: string, now: DateTime.Utc): string | undefined {
119 return delayMs > 0 ? DateTime.formatIso(DateTime.add(now, { milliseconds: delayMs })) : undefined;
120 }
121
122 +// Reorders STATUS_ERROR's groups to API_ERROR's: HTTP status, message, status name.
123 +function statusError(text: string) {
124 + const match = STATUS_ERROR.exec(text);
125 + return match === null ? null : ([match[0], match[2], match[3], match[1]] as const);
126 +}
127 +
128 function turnFailure(
129 stopReason: EffectAcpSchema.StopReason,
130 step: LastStep | undefined,
@@ -114,6 +133,7 @@ function turnFailure(
133 | {
134 readonly failure: OrchestrationV2ProviderFailure;
135 readonly threadDisposition: "reusable" | "broken";
136 + readonly resumeWith?: string;
137 }
138 | undefined {
139 const errorText =
@@ -123,7 +143,7 @@ function turnFailure(
143 // The agent maps only the SDK's QUOTA_EXHAUSTED stop reason to `refusal`.
144 if (errorText === undefined && stopReason !== "refusal") return undefined;
145 const text = errorText ?? "";
126 - const apiError = API_ERROR.exec(text);
146 + const apiError = API_ERROR.exec(text) ?? statusError(text);
147 const reusable = (failure: OrchestrationV2ProviderFailure) =>
148 ({ failure, threadDisposition: "reusable" }) as const;
149 if (stopReason === "refusal" || QUOTA_EXHAUSTED.test(text)) {
@@ -159,15 +179,18 @@ function turnFailure(
179 }
180 const [, httpStatus, message, status] = apiError;
181 const rateLimited = httpStatus === "429" || status === "RESOURCE_EXHAUSTED";
162 - return reusable(
163 - makeProviderFailure({
164 - class: rateLimited ? "usage_limit" : "provider_error",
165 - message: message!.trim(),
166 - code: status ?? null,
167 - retryable: rateLimited || Number(httpStatus) >= 500,
168 - resetAt: resetAtFrom(text, now) ?? null,
169 - }),
170 - );
182 + // A 404 before the model answered is an unknown or unentitled model; after, a transient edge error.
183 + const transientNotFound = httpStatus === "404" && step?.reachedModel === true;
184 + const failure = makeProviderFailure({
185 + class: rateLimited ? "usage_limit" : "provider_error",
186 + message: message!.trim(),
187 + code: status ?? null,
188 + retryable: rateLimited || transientNotFound || Number(httpStatus) >= 500,
189 + resetAt: resetAtFrom(text, now) ?? null,
190 + });
191 + return transientNotFound
192 + ? { failure, threadDisposition: "reusable", resumeWith: "continue" }
193 + : reusable(failure);
194 }
195
196 const conversationSegments = ["antigravity-acp", "conversations"];
packages/provider-acp/src/server/adapter.ts
+49 -2
@@ -371,6 +371,8 @@ export function acpPerTurnPromptUsage(
371 interface AcpPromptOutcomeFailure {
372 readonly failure: OrchestrationV2ProviderFailure;
373 readonly threadDisposition: "reusable" | "broken";
374 + /** The native session can carry on: the turn resends this prompt once before failing. */
375 + readonly resumeWith?: string;
376 }
377
378 export interface AcpAdapterV2Flavor {
@@ -1673,6 +1675,8 @@ interface ActiveAcpTurn {
1675 foregroundIdle: Deferred.Deferred<void>;
1676 /** Counts the turn's prompts; only the latest one settles the turn. */
1677 promptSequence: number;
1678 + /** The turn already resent a prompt after a resumable outcome failure. */
1679 + outcomeResumed: boolean;
1680 /** Clock millis just before `session/prompt` was handed to the runtime. */
1681 promptSentAt: number | null;
1682 /** Completed when an update after dispatch matches `cancelAfterPromptStarts.isStart`. */
@@ -8968,7 +8972,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8972 readonly promptParts: Effect.Success<ReturnType<typeof resolvePromptParts>> | null;
8973 readonly compactSession: AcpAdapterV2Flavor["compactSession"];
8974 },
8971 - ) => {
8975 + ): Effect.Effect<void> => {
8976 const sequence = ++context.promptSequence;
8977 const superseded = () => context.promptSequence !== sequence;
8978 return prompt(superseded).pipe(
@@ -9035,6 +9039,43 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9039 result.stopReason === "cancelled"
9040 ? undefined
9041 : yield* settle.checkPromptOutcome(result);
9042 + const resumeWith = hiddenFailure?.resumeWith;
9043 + if (
9044 + hiddenFailure !== undefined &&
9045 + resumeWith !== undefined &&
9046 + steersWithPrompt &&
9047 + !context.outcomeResumed
9048 + ) {
9049 + context.outcomeResumed = true;
9050 + yield* reportProviderRetry({
9051 + sessionId: context.nativeThreadId,
9052 + failure: hiddenFailure.failure,
9053 + });
9054 + yield* steerWithPrompt({
9055 + threadId: context.input.threadId,
9056 + runId: context.input.runId,
9057 + providerThread: context.input.providerThread,
9058 + providerTurnId: context.providerTurnId,
9059 + message: { ...context.input.message, text: resumeWith, attachments: [] },
9060 + }).pipe(
9061 + Effect.catchCause(() =>
9062 + runRuntimeCallbackAtGeneration(
9063 + settle.generation,
9064 + Effect.gen(function* () {
9065 + if (context.finalized || context.interrupted) return;
9066 + yield* Ref.set(runtimeRestartRequired, true);
9067 + yield* terminalizeOpenForegroundTools(context, "failed");
9068 + yield* finalizeTurn(context, "failed", hiddenFailure.failure, {
9069 + childTurnsContinue: hasSurvivingBackgroundWork(context),
9070 + threadDisposition: hiddenFailure.threadDisposition,
9071 + });
9072 + }),
9073 + ),
9074 + ),
9075 + Effect.forkIn(sessionScope),
9076 + );
9077 + return;
9078 + }
9079 if (hiddenFailure !== undefined) {
9080 yield* Ref.set(runtimeRestartRequired, true);
9081 }
@@ -9105,7 +9146,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9146 error.success._tag === "AcpRequestError" &&
9147 error.success.code === -32800);
9148 const failure = Cause.squash(cause);
9108 - if (!interrupted && flavor.restartRuntimeAfterPromptError?.(failure) === true) {
9149 + // A resumed prompt stands in for an outcome failure, which always restarts.
9150 + if (
9151 + !interrupted &&
9152 + (context.outcomeResumed ||
9153 + flavor.restartRuntimeAfterPromptError?.(failure) === true)
9154 + ) {
9155 yield* Ref.set(runtimeRestartRequired, true);
9156 }
9157 // An agent that answered with an error may still finish tools it started,
@@ -9322,6 +9368,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9368 promptDispatched,
9369 foregroundIdle: yield* Deferred.make<void>(),
9370 promptSequence: 0,
9371 + outcomeResumed: false,
9372 promptSentAt: null,
9373 promptStarted,
9374 promptUsage: undefined,