agy-cli 0.1.78: a banned account's ending is a no-retry 403, not an answer (#1214)

agy 1.5.9 writes a banned account's "PERMISSION_DENIED (code 403): This
service has been disabled in this account for violation of Terms of
Service…" ending into the reply as text, and the bridge answered it as
an end_turn 200 (#1201). The exact ending is now one of the end-of-turn
markers (split across chunks too), agyRefusal names it, and it ends the
turn as permission_error 403 with no retry: x-should-retry: false on a
non-stream reply, status 403 + noRetry in a started stream's error
event. A generic PERMISSION_DENIED, or the sentence quoted mid-answer,
is not reclassified. By yetihan.

Run at the reviewed head f4e82352 (mica, temp HOME):
- node --test test/repeat-batch.mjs 54 pass; test/usage.mjs 36 pass.
- bun test packages/agy-cli 37 pass; bun scripts/check.mjs agy-cli ok.
Broken by hand: origin/main's index.mjs and usage.mjs with the new
tests: the two #1201 bridge tests and the agyRefusal test fail.

Not tried: a real banned account.
This commit is contained in:
zhou.han
2026-11-16 17:27:10 +08:00
committed by GitHub
parent fe19854bd7
commit 9720caa468
7 changed files with 73 additions and 7 deletions
+3 -1
View File
@@ -342,7 +342,9 @@ off unless you turn it on.
1.5.8's "There was a network issue connecting to the server" and "Your AI
credits balance is too low to continue." end the turn the same way (the
latter as a rate limit), and its `⚠ API error (attempt N)` retry lines are
dropped.
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.
- **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
+3 -1
View File
@@ -245,7 +245,9 @@ agy 自己的系统提示词,只剩插件的一行工具说明和客户端的
从 agy 的日志中取出真实原因,并以错误结束本轮,不会当作正常回复输出。agy 1.5.8 的
"There was a network issue connecting to the server" 和 "Your AI credits balance is
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` 返回,而不是
当成正常正文。
- **HTTP 409,提示工具结果与历史对不上**:通常是客户端在对话中途改写了历史或工具 ID。
能确定对应关系时插件会重建会话;无法确定时直接拒绝,不做猜测。
Hermes Agent 会把一次批量的 `tool_call({"calls": [...]})` 在自己的历史里拆成每项一次调用,
+4 -4
View File
@@ -124,6 +124,7 @@ const AGENT_ERROR_MARKERS = [
"\n⚠ There was a network issue connecting to the server, please try again.\n",
"\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",
]
const AGENT_ERROR_CORES = AGENT_ERROR_MARKERS.map((marker) => marker.trim())
const CREDITS_CORE = AGENT_ERROR_CORES[2]
@@ -1034,6 +1035,7 @@ export function streamErrorOf(error) {
// 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
if (error?.noRetry) out.noRetry = true
return out
}
@@ -6195,7 +6197,7 @@ async function jsonResponseFromStream(stream, fallbackModel, fallbackId) {
const status = streamError.status || (streamError.type === "rate_limit_error" ? 429 : 502)
return new Response(JSON.stringify({ type: "error", error: streamError }), {
status,
headers: { "Content-Type": "application/json" },
headers: { "Content-Type": "application/json", ...(streamError.noRetry ? NO_RETRY_HEADERS : {}) },
})
}
return new Response(JSON.stringify(message), {
@@ -6209,9 +6211,7 @@ function streamResponse(proc, turn, body, signal) {
const step = turn.registerResponse(body)
const msgId = "msg_" + randomUUID().replace(/-/g, "").slice(0, 24)
const stream = makeAnthropicStream(proc, turn, body, msgId, signal, step)
if (body.stream === false) {
return jsonResponseFromStream(stream, body.model, msgId)
}
if (body.stream === false) return jsonResponseFromStream(stream, body.model, msgId)
return new Response(stream, {
status: 200,
headers: {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-agy-cli-auth",
"version": "0.1.77",
"version": "0.1.78",
"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",
+51
View File
@@ -917,6 +917,11 @@ function replyText(parsed) {
return parsed.content.filter((block) => block.type === "text").map((block) => block.text).join("")
}
function sseError(text) {
const line = text.split("\n").findLast((item) => item.startsWith("data:"))
return JSON.parse(line.slice(5)).error
}
test("#1052: the model quoting agy's error marker mid-reply does not end a healthy turn", async () => {
for (const chunks of [
["agy prints `⚠ Agent execution terminated due to error.` when a turn fails;", " the real cause is in its log."],
@@ -1035,6 +1040,52 @@ test("#1136, #1151: agy's network, credit and 429 endings fail the turn", async
}
})
// #1201: agy 1.5.9 passes a banned account's Google 403 through as the reply.
const BANNED = "\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"
test("#1201: agy's banned-account ending fails the stream as no-retry permission error", async () => {
await withKit({}, async (kit) => {
markerAgent(kit, [BANNED.slice(0, 63), BANNED.slice(63)])
const response = await kit.request(baseBody({ metadata: { user_id: "banned-end" },
messages: [{ role: "user", content: "hello" }] }))
const text = await response.text()
assert.equal(response.status, 200)
assert.equal(response.headers.get("x-should-retry"), null)
const error = sseError(text)
assert.equal(error.type, "permission_error")
assert.equal(error.status, 403)
assert.equal(error.noRetry, true)
assert.match(error.message, /disabled this account's access[\s\S]*Terms of Service[\s\S]*appeal/)
assert.ok(!text.includes("⚠"), "no banner reaches the client")
})
})
test("#1201: agy's banned-account ending fails a non-stream request as a no-retry HTTP 403", async () => {
await withKit({}, async (kit) => {
markerAgent(kit, [BANNED.slice(0, 63), BANNED.slice(63)])
const response = await kit.request(baseBody({ metadata: { user_id: "banned-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.match(body.error.message, /disabled this account's access[\s\S]*Terms of Service[\s\S]*appeal/)
assert.ok(!JSON.stringify(body).includes("⚠"), "no banner reaches the client")
})
})
test("#1201: the model quoting the banned-account ending with more text after keeps it", async () => {
const chunks = [BANNED.slice(0, 40), BANNED.slice(40) + "That line is agy's, not mine."]
await withKit({}, async (kit) => {
markerAgent(kit, chunks)
const parsed = await readSse(await kit.request(baseBody({ metadata: { user_id: "banned-quoted" },
messages: [{ role: "user", content: "what did agy print?" }] })))
assert.equal(parsed.error, null)
assert.equal(parsed.stopReason, "end_turn")
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) => {
+5
View File
@@ -973,8 +973,11 @@ test("only a region refusal reads the quota directly", async t => {
test("agyRefusal: Google turning the account away, never a network failure or agy's own log lines", () => {
const license = "Error: Eligibility check failed: PERMISSION_DENIED (code 403): You do not have a valid license of this product. ... (#3501). Please log out (/logout) and log back in (/login)."
const disabled = "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."
assert.match(agyRefusal(license), /#3501/)
assert.match(agyRefusal("error: something (#3501)"), /#3501/)
assert.match(agyRefusal(disabled), /disabled this account's access[\s\S]*Terms of Service[\s\S]*appeal/)
assert.match(agyRefusal(disabled.replace(" This service", "\nThis service")), /disabled this account's access/)
assert.match(agyRefusal("Error: Eligibility check failed: Your current account is not eligible for Antigravity, because it is not currently available in your location."), /not currently available in your location[\s\S]*VPN/)
for (const other of [
"",
@@ -983,5 +986,7 @@ test("agyRefusal: Google turning the account away, never a network failure or ag
"Error: You are not logged into Antigravity.",
// a background poll agy logged failing, while the command itself failed otherwise
"E1116 10:34:12.084405 248 errorreport.go:307] Failed to poll ListExperiments: PERMISSION_DENIED (code 403): You do not have a valid license of this product. (#3501)\nError: something else",
"PERMISSION_DENIED (code 403): Request had invalid credentials.",
"This service has been disabled in this account for violation of Terms of Service.",
]) assert.equal(agyRefusal(other), "", other)
})
+6
View File
@@ -62,6 +62,11 @@ export const LICENSE_REFUSED = "Google refuses this Google account for Antigravi
"with a personal Google account (@gmail.com) rather than a Workspace one; unset AGY_ADC_AUTH " +
"if it is set; and turn off a VPN or proxy that puts you in a region Antigravity isn't offered in."
const ACCOUNT_DISABLED_REFUSAL = /PERMISSION_DENIED \(code 403\):\s*This\s+service\s+has\s+been\s+disabled\s+in\s+this\s+account\s+for\s+violation\s+of\s+Terms\s+of\s+Service\.\s*Please\s+submit\s+an\s+appeal\s+to\s+continue\s+using\s+this\s+product\./
export const ACCOUNT_DISABLED_REFUSED = "Google has disabled this account's access to Antigravity " +
"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."
// 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
@@ -71,6 +76,7 @@ export const LICENSE_REFUSED = "Google refuses this Google account for Antigravi
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 (!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. ` +