agy-cli 0.1.70: say when Google refuses the account (#3501) instead of a fallback list

Three X reports (16 Nov): "You do not have a valid license of this product
(#3501)", "models can't be fetched", and "magpie's agy proxy stopped
working". agy 1.5.9 gets Google's 403 #3501 on its eligibility check and
fails every command with it (agy models, agy -p). The plugin hid it:
models() fell back to the static catalog as if the account had those
models, usage said only "not eligible", and a request got 400 "model ... is
unavailable to this agy account" because the ACP session offers none.

Now:
- usage.mjs: agyRefusal() reads Google's refusal out of agy's output
  (#3501 first, else the eligibility line), never from agy's own log
  lines or a network failure; usage reports the #3501 text with what to
  do (update agy and sign in again, personal Gmail, unset AGY_ADC_AUTH,
  VPN/region).
- index.mjs: a failed `agy models` records the refusal per agy home;
  models() throws it (magpie shows it as the list error) instead of the
  static catalog, and recovers when agy lists again. A request whose
  session offers no model, or whose turn ends on the refusal, answers 403
  permission_error with the reason (stream and JSON), not 400. After a
  sign-in, magpie shows "agy signed in, but" and the refusal.
- README (zh, en): a Troubleshooting entry for #3501.

Run (mote, HOME=$(mktemp -d)):
- bun test ./packages/agy-cli: 35 pass, 0 fail (110s); bun scripts/check.mjs ok.
- test/usage.mjs with cp-hook preload 6 more times: 0 fail. One earlier
  run had "a direct read that fails leaves the region refusal standing"
  red with "agy usage could not start the CLI" at load ~28; the same red
  shows on the base tree (b35d4b35) in the same run, so it is not this
  change.
- Red on the old code (mica, base b35d4b35 with the new tests): catalog's
  two #3501 tests fail, usage.mjs fails to import agyRefusal.
- Real agy 1.5.9 on WSL (magpie-desktop) against a fake Code Assist that
  answers 403 #3501: before, models() gave the fallback list, chat gave 400
  "unavailable"; after, models() throws the #3501 reason, usage carries
  it, chat answers 403 permission_error with it.

Not tried: a real Google account that gets #3501; macOS and Windows with
real agy; a live ACP turn whose agent error carries #3501 (covered by the
fake agy in catalog.mjs only).
This commit is contained in:
yetone
2026-11-16 10:57:34 +08:00
parent b35d4b35b2
commit 175dfd2555
8 changed files with 192 additions and 7 deletions
+66 -4
View File
@@ -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 { createUsageReader } from "./usage.mjs"
import { agyRefusal, createUsageReader } from "./usage.mjs"
import { storeCatalogRows } from "./model-ids.mjs"
import { backgroundBlocked, cannotSignIn, forgetStoredSignIn, storedEmail, storedSignInNow } from "./signin.mjs"
import { sanitizePatternFields } from "./re2-pattern.mjs"
@@ -349,12 +349,44 @@ async function listAgyModels(agyPath) {
// a listing nobody asked for doesn't run an agy that would start its own
// Google sign-in (signin.mjs); the catalog it has stays
if (await backgroundBlocked()) return null
const { err, stdout, code, timedOut } = await execOnce(agyPath, ["models"], { timeoutMs: 15_000, unrefTimer: true })
const { err, stdout, stderr, code, timedOut } = await execOnce(agyPath, ["models"], { timeoutMs: 15_000, unrefTimer: true })
// null, not FALLBACK_MODELS: a failed listing must not overwrite a dynamic catalog.
if (err || timedOut || code !== 0) return null
if (err || timedOut || code !== 0) {
if (!err && !timedOut) noteRefusal(agyRefusal(`${stderr}\n${stdout}`))
return null
}
noteRefusal("")
return parseAgyModels(stdout)
}
// What the last `agy models` of each account said when Google turned the
// account away at agy's eligibility check (agyRefusal), "" when it listed.
// models() says it instead of serving a fallback list as if agy had
// answered, and a turn that then can't pick its model says it too.
const refusals = new Map()
function noteRefusal(why) {
const home = currentHome() ?? ""
if (why) refusals.set(home, why)
else refusals.delete(home)
}
function refusalOf() {
return refusals.get(currentHome() ?? "") || ""
}
// refusalNow is the account's refusal, asking agy once when no listing of
// it has said yet (a request before the first models()).
async function refusalNow(agyPath) {
if (refusals.has(currentHome() ?? "")) return refusalOf()
if (!agyPath || await backgroundBlocked()) return ""
const { err, stdout, stderr, code, timedOut } = await execOnce(agyPath, ["models"], { timeoutMs: 15_000 })
if (err || timedOut || code === 0) return ""
const why = agyRefusal(`${stderr}\n${stdout}`)
noteRefusal(why)
return why
}
// parseAgyModels reads `agy models` output: one "<id> <name>" per line.
function parseAgyModels(stdout) {
const out = []
@@ -397,6 +429,13 @@ async function probeSignedIn(agy) {
}
return { ok: true }
}
// Google turned the account away (#3501): signing in again took, and
// Google still refuses it; say so, not agy's last line alone
const refused = !probe.err && !probe.timedOut ? agyRefusal(`${probe.stderr}\n${probe.stdout}`) : ""
if (refused) {
noteRefusal(refused)
return { ok: false, why: refused }
}
const why = probe.timedOut
? "`agy models` timed out after 15s"
: `\`agy models\` says: ${(probe.stderr || probe.stdout || "").trim().split(/\r?\n/).filter(Boolean).at(-1) || probe.err?.message || `exit ${probe.code}`}`
@@ -961,6 +1000,9 @@ export function streamErrorOf(error) {
const type = error?.kind || "api_error"
const out = { type, message: String(error?.message ?? error) }
if (type === "invalid_request_error") out.status = 400
// Google refused the account (refusedError): its status, so magpie
// reads it as the account's refusal, not as a failed reply.
if (type === "permission_error") out.status = 403
return out
}
@@ -972,6 +1014,15 @@ class AgentTurnError extends Error {
}
}
// Google refused the account (agyRefusal): a 403 no retry of this request
// fixes, the account's and not the model's.
function refusedError(why) {
const error = new AgentTurnError(`agy bridge: ${why}`, "permission_error")
error.statusCode = 403
error.noRetry = true
return error
}
function shellQuote(value) {
return `'${String(value).replace(/'/g, `'\\''`)}'`
}
@@ -1917,6 +1968,10 @@ class Proc {
await this.conn.request("session/set_model", { sessionId: this.sessionId, modelId: model }, 30_000)
}
} catch (error) {
// Google turned the account away (#3501): agy's session offers no
// model at all, so every model is "unknown". That is the account.
const refused = await refusalNow(this.agyPath).catch(() => "")
if (refused) throw refusedError(refused)
const wrapped = new Error(`agy bridge: model ${model} is unavailable to this agy account: ${error.message}`)
wrapped.statusCode = 400
throw wrapped
@@ -2281,6 +2336,8 @@ class Proc {
"rate_limit_error",
)
}
const refused = agyRefusal(detail)
if (refused) return refusedError(refused)
return new AgentTurnError(`agy bridge: agy stopped the turn because of an error${detail ? ": " + detail : ""}`)
}
@@ -6331,6 +6388,11 @@ export const AntigravityBridgePlugin = async () => {
const agy = findAgy()
// Never force a refresh here: Magpie times models() out after about two seconds.
const catalog = await loadModelCatalog(agy, { probeOffered: true })
// Google turned the account away (#3501): agy lists nothing, and a
// fallback list would read as models this account has. magpie
// keeps the list it had and shows why.
const refused = agy ? refusalOf() : ""
if (refused) throw new Error(refused)
const out = {}
// Not the account's list yet: the static one (no agy, signed out,
// or agy hasn't answered), or Gemini alone while agy acp is still
@@ -6371,7 +6433,7 @@ function jsonError(status, message, code, { extra, headers, noRetry = false } =
return new Response(
JSON.stringify({
type: "error",
error: { type: status === 400 ? "invalid_request_error" : "api_error",
error: { type: status === 400 ? "invalid_request_error" : status === 403 ? "permission_error" : "api_error",
...(code ? { code } : {}), message: String(message || "unknown error"), ...(extra ?? {}) },
}),
{ status, headers: { "Content-Type": "application/json",