From 83a677177bc3ec8e72f2de24a81259749fa9fa6d Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 16 Nov 2026 23:04:00 +0800 Subject: [PATCH] agy-cli 0.1.81: agy's "Verification Required" is a 403 that says how to verify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kidgpt on X (Windows 11, Claude Code in VS Code, gemini-3.8-flash) got the bare text "Verification Required" as the model's answer. agy 1.5.9 turns Google's 403 VALIDATION_REQUIRED into that line (utils.CustomUserErrorMessageFromHTTPError, read from the binary) and ends the turn with "\n⚠ Verification Required\n", which the bridge didn't know, so it went out as a successful reply. - The ending is a sixth agent-error marker. The turn fails as a no-retry 403 permission_error (stream error event and HTTP 403 with x-should-retry: false, as #1201's banned account), in the words magpie's gateway reads as Google verification ("this Google account needs to be verified: open in a browser"), so magpie rests the account as needing verification and shows the link. - The link comes from agy's log for the turn (validation_link / validation_url, or the "in your browser to continue:" line) when there is one; otherwise the message says to open the Antigravity app or run agy signed in to the account. - Sibling: agy's eligibility refusal for the same cause ("Please verify your account in your browser to continue:\n", "Verification required. Please complete verification…", from AuthStatus.EligibilityError / IneligibilityFromResult) got the region/VPN advice and lost the URL in agyRefusal (models, sign-in probe). It now gets the same verify message with agy's link. - A model quoting the line with more text after it keeps its text. Run (mote, temp HOME): node --test test/repeat-batch.mjs test/usage.mjs 95 pass; bun test packages/agy-cli 37 pass 0 fail (smoke.mjs included); bun scripts/check.mjs agy-cli ok. Windows (xiaomi-gpu, win-run): repeat-batch, usage, windows-nc, platform 120 pass 0 fail. Red on the old code: with origin/main's index.mjs and usage.mjs the two new ending tests fail (a 200 reply) and the agyRefusal test gets the VPN advice. Not tried: a real account Google wants verified; the exact log line agy writes for a VALIDATION_REQUIRED turn (the fixture follows Google's JSON error's validation_url). --- packages/agy-cli/README.en.md | 4 +- packages/agy-cli/README.md | 3 +- packages/agy-cli/index.mjs | 25 +++++++++--- packages/agy-cli/package.json | 2 +- packages/agy-cli/test/repeat-batch.mjs | 55 ++++++++++++++++++++++++++ packages/agy-cli/test/usage.mjs | 31 ++++++++++++++- packages/agy-cli/usage.mjs | 44 +++++++++++++++++++++ 7 files changed, 155 insertions(+), 9 deletions(-) diff --git a/packages/agy-cli/README.en.md b/packages/agy-cli/README.en.md index 457bda1..716d664 100644 --- a/packages/agy-cli/README.en.md +++ b/packages/agy-cli/README.en.md @@ -348,7 +348,9 @@ off unless you turn it on. latter as a rate limit), and its `⚠ API error (attempt N)` retry lines are dropped. An ending that says "This service has been disabled in this account for violation of Terms of Service" is returned as a no-retry - `permission_error` with 403 semantics, not as normal reply text. + `permission_error` with 403 semantics, not as normal reply text. So is the + "Verification Required" ending (Google wants the account verified), with + the link to verify it at when agy logged one, else where to verify it. - **HTTP 409 saying tool results do not match the history**: usually the client rewrote the history or tool IDs mid-conversation. When the plugin can work out the correct match it rebuilds the session; when it cannot, it refuses rather diff --git a/packages/agy-cli/README.md b/packages/agy-cli/README.md index cb877f8..85b7a4f 100644 --- a/packages/agy-cli/README.md +++ b/packages/agy-cli/README.md @@ -249,7 +249,8 @@ agy 自己的系统提示词,只剩插件的一行工具说明和客户端的 too low to continue." 也一样(后者按额度不足报错);`⚠ API error (attempt N)` 这类 重试中的提示行会被去掉。若结尾是 "This service has been disabled in this account for violation of Terms of Service",会按禁止重试的 403 语义 `permission_error` 返回,而不是 - 当成正常正文。 + 当成正常正文。结尾是 "Verification Required"(Google 要求先验证这个账号)时也一样, + 并带上 agy 记下的验证链接;没有链接时说明去哪里验证。 - **HTTP 409,提示工具结果与历史对不上**:通常是客户端在对话中途改写了历史或工具 ID。 能确定对应关系时插件会重建会话;无法确定时直接拒绝,不做猜测。 Hermes Agent 会把一次批量的 `tool_call({"calls": [...]})` 在自己的历史里拆成每项一次调用, diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 028b0d6..24341ae 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -7,7 +7,7 @@ import net from "node:net" import os from "node:os" import path from "node:path" import { fileURLToPath } from "node:url" -import { agyRefusal, createUsageReader } from "./usage.mjs" +import { agyRefusal, createUsageReader, verifyLinkIn, verifyRefused } from "./usage.mjs" import { storeCatalogRows } from "./model-ids.mjs" import { backgroundBlocked, cannotSignIn, forgetStoredSignIn, storedEmail, storedSignInNow } from "./signin.mjs" import { sanitizePatternFields } from "./re2-pattern.mjs" @@ -125,9 +125,14 @@ const AGENT_ERROR_MARKERS = [ "\n⚠ Your AI credits balance is too low to continue.\n", "\n⚠ RESOURCE_EXHAUSTED (code 429): Resource has been exhausted (e.g. check quota).\n", "\n⚠ PERMISSION_DENIED (code 403): This service has been disabled in this account for violation of Terms of Service. Please submit an appeal to continue using this product.\n", + // Google's 403 VALIDATION_REQUIRED on a model call, in agy's words + // (CustomUserErrorMessageFromHTTPError): the account must be verified + // first. Answered as text, it was the whole reply (kidgpt on X, 11-16). + "\n⚠ Verification Required\n", ] const AGENT_ERROR_CORES = AGENT_ERROR_MARKERS.map((marker) => marker.trim()) const CREDITS_CORE = AGENT_ERROR_CORES[2] +const VERIFY_CORE = AGENT_ERROR_CORES[5] // agy 1.5.8 writes each failed attempt of a model call into the reply as one // line, then tries again in the same turn (#1136). The line is agy's. const ATTEMPT_CORE = "⚠ API error (attempt " @@ -2414,6 +2419,11 @@ class Proc { async #agentError(turn) { const core = turn.agentErrorCore + if (core === VERIFY_CORE) { + // the link, when agy logged Google's error whole; the reply has none + const logged = await logTail(this.logPath, turn.logOffset) + return refusedError(verifyRefused(verifyLinkIn(`${turn.attemptDetail || ""}\n${logged}`))) + } // A failed connection is in the reply's last attempt line, not the log's // executor error (#1136). const detail = await lastAgentError(this.logPath, turn.logOffset) || turn.attemptDetail || @@ -2867,9 +2877,8 @@ async function fileSize(file) { try { return (await fs.promises.stat(file)).size } catch { return 0 } } -// agy writes the real upstream error only to its log; read what this turn added. -async function lastAgentError(file, offset) { - let text = "" +// What agy logged since offset, its last LOG_TAIL_BYTES at most. +async function logTail(file, offset) { try { const handle = await fs.promises.open(file, "r") try { @@ -2877,13 +2886,19 @@ async function lastAgentError(file, offset) { const start = Math.max(offset || 0, size - LOG_TAIL_BYTES) const buffer = Buffer.alloc(Math.max(0, size - start)) await handle.read(buffer, 0, buffer.length, start) - text = buffer.toString("utf8") + return buffer.toString("utf8") } finally { await handle.close() } } catch { return "" } +} + +// agy writes the real upstream error only to its log; read what this turn added. +async function lastAgentError(file, offset) { + const text = await logTail(file, offset) + if (!text) return "" let found = "" for (const line of text.split("\n")) { const match = /\] (?:agent executor error|failed to construct executor|inference connection failed[^:]*): (.+)$/.exec(line) || diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index 865528c..aba778d 100644 --- a/packages/agy-cli/package.json +++ b/packages/agy-cli/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-agy-cli-auth", - "version": "0.1.80", + "version": "0.1.81", "description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI", "type": "module", "main": "./opencode.mjs", diff --git a/packages/agy-cli/test/repeat-batch.mjs b/packages/agy-cli/test/repeat-batch.mjs index 296af89..5932597 100644 --- a/packages/agy-cli/test/repeat-batch.mjs +++ b/packages/agy-cli/test/repeat-batch.mjs @@ -1086,6 +1086,61 @@ test("#1201: the model quoting the banned-account ending with more text after ke }) }) +// kidgpt on X (11-16, Windows 11, Claude Code in VS Code, gemini-3.8-flash): +// Google's 403 VALIDATION_REQUIRED on a model call reaches agy 1.5.9 as +// "Verification Required" (CustomUserErrorMessageFromHTTPError), which it +// ends the reply with, and the client got that bare line as the answer. +const VERIFY = "\n⚠ Verification Required\n" + +function agyLogOf(kit) { + const args = kit.acpSpawns.at(-1).args + return args[args.indexOf("--log-file") + 1] +} + +test("agy's Verification Required ending fails the stream as a no-retry 403 that says how to verify", async () => { + await withKit({}, async (kit) => { + markerAgent(kit, [VERIFY.slice(0, 9), VERIFY.slice(9)]) + const response = await kit.request(baseBody({ metadata: { user_id: "verify-end" }, + messages: [{ role: "user", content: "hello" }] })) + const text = await response.text() + const error = sseError(text) + assert.equal(error.type, "permission_error") + assert.equal(error.status, 403) + assert.equal(error.noRetry, true) + assert.match(error.message, /this Google account needs to be verified: open the Antigravity app, or run `agy` in a terminal/) + assert.ok(!text.includes("⚠"), "no banner reaches the client") + }) +}) + +test("agy's Verification Required ending carries the link agy logged, as a non-stream HTTP 403", async () => { + const link = "https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv" + await withKit({}, async (kit) => { + kit.defaultPrompt = async (agent) => { + fs.appendFileSync(agyLogOf(kit), `E1116 21:03:11.120000 6120 errorreport.go:224] agent executor error: generating and executing: PERMISSION_DENIED (code 403): Verify your account to continue. validation_url: ${link.replace(/&/g, "\\u0026")}\n`) + await agent.text(VERIFY) + return { stopReason: "end_turn" } + } + const response = await kit.request(baseBody({ metadata: { user_id: "verify-json" }, + messages: [{ role: "user", content: "hello" }], stream: false })) + const body = await response.json() + assert.equal(response.status, 403) + assert.equal(response.headers.get("x-should-retry"), "false") + assert.equal(body.error.type, "permission_error") + assert.ok(body.error.message.includes(`this Google account needs to be verified: open ${link} in a browser`), body.error.message) + }) +}) + +test("the model quoting the Verification Required ending with more text after keeps it", async () => { + const chunks = ["agy said\n⚠ Verification", " Required\nThat line is agy's, not mine."] + await withKit({}, async (kit) => { + markerAgent(kit, chunks) + const parsed = await readSse(await kit.request(baseBody({ metadata: { user_id: "verify-quoted" }, + messages: [{ role: "user", content: "what did agy print?" }] }))) + assert.equal(parsed.error, null) + assert.equal(replyText(parsed), chunks.join("")) + }) +}) + test("#1151: the model quoting the 429 ending with more text after keeps it", async () => { const chunks = ["agy ended with\n⚠ RESOURCE_EXHAUSTED (code 429): Resource has", " been exhausted (e.g. check quota).\nThat line is agy's, not mine."] await withKit({}, async (kit) => { diff --git a/packages/agy-cli/test/usage.mjs b/packages/agy-cli/test/usage.mjs index 221409d..780c59d 100644 --- a/packages/agy-cli/test/usage.mjs +++ b/packages/agy-cli/test/usage.mjs @@ -6,7 +6,7 @@ import fs from "node:fs/promises" import os from "node:os" import path from "node:path" import { test } from "node:test" -import { agyRefusal, createUsageReader, fetchUsage, parseUsageReport, quotaUserAgent, readQuotaDirect } from "../usage.mjs" +import { agyRefusal, createUsageReader, fetchUsage, parseUsageReport, quotaUserAgent, readQuotaDirect, verifyLinkIn } from "../usage.mjs" import http from "node:http" import { modelsInGroup, storeCatalogRows } from "../model-ids.mjs" import { forgetStoredSignIn } from "../signin.mjs" @@ -990,3 +990,32 @@ test("agyRefusal: Google turning the account away, never a network failure or ag "This service has been disabled in this account for violation of Terms of Service.", ]) assert.equal(agyRefusal(other), "", other) }) + +// Google's VALIDATION_REQUIRED at agy's eligibility check, in agy 1.5.9's +// words (AuthStatus.EligibilityError, IneligibilityFromResult): the link +// agy prints goes to the user whole, in the words magpie's gateway reads as +// a verification (provider.verifyAdvice, verifyLink), never the VPN advice. +test("agyRefusal: an account Google wants verified gets the link agy printed, or where to verify", () => { + const link = "https://accounts.google.com/signin/continue?sarp=1&scc=1&continue=https://developers.google.com/gemini-code-assist/auth/auth_success_gemini&plt=AKgnsbv" + const linked = `Error: Eligibility check failed: Verify your account to continue.\n\nPlease verify your account in your browser to continue:\n${link}\n` + const said = agyRefusal(linked) + assert.ok(said.includes(`this Google account needs to be verified: open ${link} in a browser`), said) + assert.doesNotMatch(said, /VPN/) + assert.equal(verifyLinkIn(linked.replace(/\n/g, "\r\n")), link) + for (const bare of [ + "Error: Eligibility check failed: Verification required. Please complete verification in your browser to continue.", + "Error: Eligibility check failed: Verify your account to continue.", + ]) { + const why = agyRefusal(bare) + assert.match(why, /this Google account needs to be verified: open the Antigravity app, or run `agy` in a terminal/, bare) + assert.doesNotMatch(why, /https:/) + } +}) + +test("verifyLinkIn: Google's validation link from a logged error, validation_link first, https only", () => { + const body = '{"error":{"code":403,"message":"Verify your account to continue.","status":"PERMISSION_DENIED","details":[{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"VALIDATION_REQUIRED","metadata":{"validation_url":"https://accounts.google.com/signin/continue?sarp=1\\u0026x=2","validation_link":"https://accounts.google.com/v?a=1\\u0026b=2"}}]}}' + assert.equal(verifyLinkIn(body), "https://accounts.google.com/v?a=1&b=2") + assert.equal(verifyLinkIn(body.replace(/,"validation_link":"[^"]+"/, "")), "https://accounts.google.com/signin/continue?sarp=1&x=2") + assert.equal(verifyLinkIn('validation_url: "http://example.com/x"'), "") + assert.equal(verifyLinkIn("Verification Required"), "") +}) diff --git a/packages/agy-cli/usage.mjs b/packages/agy-cli/usage.mjs index 4a3ae04..ff301ad 100644 --- a/packages/agy-cli/usage.mjs +++ b/packages/agy-cli/usage.mjs @@ -67,6 +67,49 @@ export const ACCOUNT_DISABLED_REFUSED = "Google has disabled this account's acce "for violating the Terms of Service (HTTP 403: \"This service has been disabled in this account " + "for violation of Terms of Service\"). Submit an appeal with Google before using this account again." +// Google asks for the account to be verified (Cloud Code's 403 +// VALIDATION_REQUIRED). agy 1.5.9 words it three ways: a turn's model call +// ends the reply with "⚠ Verification Required" alone (kidgpt on X, 11-16: +// that bare line was the whole answer in Claude Code), and its eligibility +// check says "…\n\nPlease verify your account in your browser to +// continue:\n", or "Verification required. Please complete +// verification in your browser to continue." when Google gave no link. +const VERIFY_REFUSAL = /please verify your account in your browser to continue|verification required\. please complete verification|verify your account to continue/i + +// The words magpie's gateway reads as Google's verification refusal +// (provider.verifyAdvice), and its link in them (provider.verifyLink): it +// rests the account as "verify" and shows Verify with the link, as it does +// for the Antigravity and Gemini CLI routes. +export const VERIFY_ADVICE = "this Google account needs to be verified" + +// verifyLinkIn is the https link agy's output or log gives to verify the +// account at, "" when it gives none: taken as Gemini CLI takes it, the +// validation_link before the validation_url, else the link agy prints after +// "continue:", else an accounts.google.com one. +export function verifyLinkIn(output) { + const said = String(output ?? "").replace(/\\u0026/g, "&").replace(/&/g, "&") + const named = (key) => new RegExp(`"?${key}"?\\s*[:=]\\s*"?(https://[^\\s"'\\\\<>]+)`, "i").exec(said)?.[1] + const link = named("validation_?link") || named("validation_?url") || + /in your browser to continue:\s*(https:\/\/[^\s"'\\<>]+)/i.exec(said)?.[1] || + /(https:\/\/accounts\.google\.com\/[^\s"'\\<>]+)/i.exec(said)?.[1] || "" + const trimmed = link.replace(/[).,;\]}]+$/, "") + try { + const u = new URL(trimmed) + return u.protocol === "https:" && u.host ? trimmed : "" + } catch { + return "" + } +} + +// verifyRefused is what the agent is told when Google wants the account +// verified: with the link to do it at when agy gave one, else where to go. +export function verifyRefused(link) { + const said = "Google wants this account verified before Antigravity serves it again (agy: \"Verification Required\")" + return link + ? `${said} — ${VERIFY_ADVICE}: open ${link} in a browser signed in to it, verify it, then try again` + : `${said} — ${VERIFY_ADVICE}: open the Antigravity app, or run \`agy\` in a terminal, signed in to it and do what it asks, then try again` +} + // agyRefusal is what to tell the user when agy's output says Google turned // the account away at its eligibility check, or "" when it doesn't: the // license refusal (#3501), or any other refusal of the check that isn't a @@ -77,6 +120,7 @@ export function agyRefusal(output) { const said = withoutDiagnostics(String(output ?? "")) if (LICENSE_REFUSAL.test(said)) return LICENSE_REFUSED if (ACCOUNT_DISABLED_REFUSAL.test(said)) return ACCOUNT_DISABLED_REFUSED + if (VERIFY_REFUSAL.test(said)) return verifyRefused(verifyLinkIn(said)) if (!ELIGIBILITY.test(said) || NETWORK.test(said)) return "" const line = said.split(/\r?\n/).map(l => l.trim().replace(/^error:\s*/i, "")).find(l => ELIGIBILITY.test(l)) || "" return `Google refuses this account for Antigravity: ${line.slice(0, 400)}. agy itself gets the same answer. ` +