From 0f97c551aed033b9e9b78d7c0798d2c05fa0b0ad Mon Sep 17 00:00:00 2001 From: mianmian7 <774216442@qq.com> Date: Sun, 22 Nov 2026 23:52:04 +0800 Subject: [PATCH 1/2] fix(antigravity): mid-turn 401 OAuth refresh errors resume once automatically --- .../acp/AntigravityTurnOutcome.test.ts | 44 +++++++++++++++++++ .../provider/acp/AntigravityTurnOutcome.ts | 10 +++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts b/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts index b6094e638285..dcb7afa25974 100644 --- a/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts +++ b/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts @@ -50,6 +50,17 @@ const STATUS_NOT_FOUND_ERROR = Buffer.concat([ '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"}}', ), ]); +const UNAUTHENTICATED_MESSAGE = + "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."; +const UNAUTHENTICATED_ERROR = errorPayload( + `Error 401, Message: ${UNAUTHENTICATED_MESSAGE}, Status: UNAUTHENTICATED, Details: []`, +); +const STATUS_UNAUTHENTICATED_ERROR = Buffer.concat([ + Buffer.from([0x12, 0xec, 0x01]), + Buffer.from( + `UNAUTHENTICATED (code 401): ${UNAUTHENTICATED_MESSAGE}\u001a\u0098\u0005HTTP 401 Unauthorized\n\n{"error":{"code":401,"message":"${UNAUTHENTICATED_MESSAGE}","status":"UNAUTHENTICATED"}}`, + ), +]); // The model's reply quoting the agent's quota notice is an ordinary planner response. const QUOTED_NOTICE = Buffer.from( "Usage Limit Reached\n\nYou have reached your current quota for this period. Your limit will reset in 1 hour.", @@ -177,6 +188,39 @@ describe("watchAntigravityPromptOutcome", () => { ]))?.failure.retryable, false, ); + // A 401 after the turn already reached the model is a transient OAuth refresh race. + for (const error of [UNAUTHENTICATED_ERROR, STATUS_UNAUTHENTICATED_ERROR]) { + assert.deepEqual( + yield* turn([ + [USER_INPUT, input], + [PLANNER_RESPONSE, reply], + [TOOL, reply], + [ERROR_MESSAGE, error], + ]), + { + ...reusable({ + class: "provider_error", + message: UNAUTHENTICATED_MESSAGE, + code: "UNAUTHENTICATED", + retryable: true, + }), + resumeWith: "continue", + }, + ); + } + // A 401 before the model answered is an unauthenticated session, not a mid-turn refresh race. + assert.deepEqual( + yield* turn([ + [USER_INPUT, input], + [ERROR_MESSAGE, STATUS_UNAUTHENTICATED_ERROR], + ]), + reusable({ + class: "provider_error", + message: UNAUTHENTICATED_MESSAGE, + code: "UNAUTHENTICATED", + retryable: false, + }), + ); // A saved thinking block without a valid signature fails every later prompt. for (const error of [MISSING_SIGNATURE_ERROR, INVALID_SIGNATURE_ERROR]) { const outcome = yield* turn([ diff --git a/apps/server/src/provider/acp/AntigravityTurnOutcome.ts b/apps/server/src/provider/acp/AntigravityTurnOutcome.ts index 32eee40f008a..173778ac83cb 100644 --- a/apps/server/src/provider/acp/AntigravityTurnOutcome.ts +++ b/apps/server/src/provider/acp/AntigravityTurnOutcome.ts @@ -179,16 +179,18 @@ function turnFailure( } const [, httpStatus, message, status] = apiError; const rateLimited = httpStatus === "429" || status === "RESOURCE_EXHAUSTED"; - // A 404 before the model answered is an unknown or unentitled model; after, a transient edge error. - const transientNotFound = httpStatus === "404" && step?.reachedModel === true; + // After the model already answered, a 404 is a transient edge error and a 401 is an OAuth refresh race. + const transientMidTurn = + (httpStatus === "404" || httpStatus === "401" || status === "UNAUTHENTICATED") && + step?.reachedModel === true; const failure = makeProviderFailure({ class: rateLimited ? "usage_limit" : "provider_error", message: message!.trim(), code: status ?? null, - retryable: rateLimited || transientNotFound || Number(httpStatus) >= 500, + retryable: rateLimited || transientMidTurn || Number(httpStatus) >= 500, resetAt: resetAtFrom(text, now) ?? null, }); - return transientNotFound + return transientMidTurn ? { failure, threadDisposition: "reusable", resumeWith: "continue" } : reusable(failure); } From 7bd9dee09a83e0a67a095442c6ba64fe7ee2da4d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 22 Nov 2026 16:03:34 +0000 Subject: [PATCH 2/2] refactor(antigravity): match mid-turn 401 by HTTP status and fold its tests into the 404 table Co-Authored-By: Claude Opus 5.5 --- .../acp/AntigravityTurnOutcome.test.ts | 57 ++++--------------- .../provider/acp/AntigravityTurnOutcome.ts | 6 +- 2 files changed, 13 insertions(+), 50 deletions(-) diff --git a/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts b/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts index dcb7afa25974..38fb794126bb 100644 --- a/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts +++ b/apps/server/src/provider/acp/AntigravityTurnOutcome.test.ts @@ -51,10 +51,7 @@ const STATUS_NOT_FOUND_ERROR = Buffer.concat([ ), ]); const UNAUTHENTICATED_MESSAGE = - "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."; -const UNAUTHENTICATED_ERROR = errorPayload( - `Error 401, Message: ${UNAUTHENTICATED_MESSAGE}, Status: UNAUTHENTICATED, Details: []`, -); + "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential."; const STATUS_UNAUTHENTICATED_ERROR = Buffer.concat([ Buffer.from([0x12, 0xec, 0x01]), Buffer.from( @@ -160,8 +157,13 @@ describe("watchAntigravityPromptOutcome", () => { retryable: false, }), ); - // A 404 after the turn already reached the model is a transient edge error, not a bad model. - for (const error of [NOT_FOUND_ERROR, STATUS_NOT_FOUND_ERROR]) { + // After the turn reached the model, a 404 is a transient edge error and a 401 an OAuth + // refresh race; before, they are a bad model and a signed-out session. + for (const [error, message, code] of [ + [NOT_FOUND_ERROR, "Requested entity was not found.", "NOT_FOUND"], + [STATUS_NOT_FOUND_ERROR, "Requested entity was not found.", "NOT_FOUND"], + [STATUS_UNAUTHENTICATED_ERROR, UNAUTHENTICATED_MESSAGE, "UNAUTHENTICATED"], + ] as const) { assert.deepEqual( yield* turn([ [USER_INPUT, input], @@ -170,57 +172,18 @@ describe("watchAntigravityPromptOutcome", () => { [ERROR_MESSAGE, error], ]), { - ...reusable({ - class: "provider_error", - message: "Requested entity was not found.", - code: "NOT_FOUND", - retryable: true, - }), + ...reusable({ class: "provider_error", message, code, retryable: true }), resumeWith: "continue", }, ); - } - // A 404 before the model answered is an unknown or unentitled model. - assert.equal( - (yield* turn([ - [USER_INPUT, input], - [ERROR_MESSAGE, STATUS_NOT_FOUND_ERROR], - ]))?.failure.retryable, - false, - ); - // A 401 after the turn already reached the model is a transient OAuth refresh race. - for (const error of [UNAUTHENTICATED_ERROR, STATUS_UNAUTHENTICATED_ERROR]) { assert.deepEqual( yield* turn([ [USER_INPUT, input], - [PLANNER_RESPONSE, reply], - [TOOL, reply], [ERROR_MESSAGE, error], ]), - { - ...reusable({ - class: "provider_error", - message: UNAUTHENTICATED_MESSAGE, - code: "UNAUTHENTICATED", - retryable: true, - }), - resumeWith: "continue", - }, + reusable({ class: "provider_error", message, code, retryable: false }), ); } - // A 401 before the model answered is an unauthenticated session, not a mid-turn refresh race. - assert.deepEqual( - yield* turn([ - [USER_INPUT, input], - [ERROR_MESSAGE, STATUS_UNAUTHENTICATED_ERROR], - ]), - reusable({ - class: "provider_error", - message: UNAUTHENTICATED_MESSAGE, - code: "UNAUTHENTICATED", - retryable: false, - }), - ); // A saved thinking block without a valid signature fails every later prompt. for (const error of [MISSING_SIGNATURE_ERROR, INVALID_SIGNATURE_ERROR]) { const outcome = yield* turn([ diff --git a/apps/server/src/provider/acp/AntigravityTurnOutcome.ts b/apps/server/src/provider/acp/AntigravityTurnOutcome.ts index 173778ac83cb..1f91d58d3bf9 100644 --- a/apps/server/src/provider/acp/AntigravityTurnOutcome.ts +++ b/apps/server/src/provider/acp/AntigravityTurnOutcome.ts @@ -179,10 +179,10 @@ function turnFailure( } const [, httpStatus, message, status] = apiError; const rateLimited = httpStatus === "429" || status === "RESOURCE_EXHAUSTED"; - // After the model already answered, a 404 is a transient edge error and a 401 is an OAuth refresh race. + // Before the model answered, a 404 is an unknown model and a 401 a signed-out session. After, + // they are a transient edge error and an OAuth token refresh race. const transientMidTurn = - (httpStatus === "404" || httpStatus === "401" || status === "UNAUTHENTICATED") && - step?.reachedModel === true; + (httpStatus === "404" || httpStatus === "401") && step?.reachedModel === true; const failure = makeProviderFailure({ class: rateLimited ? "usage_limit" : "provider_error", message: message!.trim(),