diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index f6eefdd..5645e6b 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -918,6 +918,20 @@ class UnsupportedContent extends Error { // An upstream failure inside a healthy agy session. The process keeps its // conversation, so a client retry continues without replaying history. +// streamErrorOf is the error event a failed turn ends its stream with. A +// refusal of the request itself (invalid_request_error: a system prompt +// Antigravity turns away) names its status, 400: magpie's gateway reads a +// stream error's status from the error's own status field first and from +// its words after, and this one's words quote Antigravity's "code 429", so +// without it the client got a 429 and retried a request that can't pass +// every minute (plugins#1151). +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 + return out +} + class AgentTurnError extends Error { constructor(message, kind = "api_error") { super(message) @@ -5595,10 +5609,7 @@ function makeAnthropicStream(proc, turn, body, msgId, signal, step = turn.regist } if (event.type === "error") { closeBlock() - send("error", { - type: "error", - error: { type: event.error?.kind || "api_error", message: String(event.error?.message ?? event.error) }, - }) + send("error", { type: "error", error: streamErrorOf(event.error) }) if (!event.error?.keepProcess) { dropFromPool(proc) await proc.stop().catch(() => {}) @@ -5764,7 +5775,7 @@ async function jsonResponseFromStream(stream, fallbackModel, fallbackId) { if (buffer.trim()) processBlock(buffer) if (streamError) { - const status = streamError.type === "rate_limit_error" ? 429 : 502 + 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" }, diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index ccd0072..67ccece 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.58", + "version": "0.1.59", "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/smoke.mjs b/packages/agy-cli/test/smoke.mjs index 1a551cf..e2ee373 100644 --- a/packages/agy-cli/test/smoke.mjs +++ b/packages/agy-cli/test/smoke.mjs @@ -1412,9 +1412,17 @@ for (const [title, tools, want, name] of [ check("#980 a 429 to a turned-away prompt is a prompt rejection, not a quota", turnedError?.type === "invalid_request_error" && turnedError.message.includes("answered 429 to this system prompt") && turnedError.message.includes("RFC 2119") && !/quota or rate limit reached/.test(turnedError.message), JSON.stringify(turnedError)) + // plugins#1151: magpie reads a stream error's status from its own status + // field before its words, which quote Antigravity's "code 429" + check("#1151 the turned-away error names status 400, so the client doesn't retry it as a 429", + turnedError?.status === 400, JSON.stringify(turnedError)) + const turnedWhole = await callFetch({ model, system: system + " T429W", stream: false, messages: [{ role: "user", content: "TURNED429 whole" }] }) + const turnedWholeBody = await turnedWhole.json() + check("#1151 a turned-away prompt asked for a whole reply is a 400", + turnedWhole.status === 400 && turnedWholeBody?.error?.type === "invalid_request_error", JSON.stringify({ status: turnedWhole.status, body: turnedWholeBody })) const quota = (await readSSE(await callFetch({ model, system: "CLOAK-QUOTA", messages: [{ role: "user", content: "TURNED429 plain" }] }))).events const quotaError = quota.find(event => event.event === "error")?.data?.error - check("#980 the same 429 to any other prompt is still a rate limit", quotaError?.type === "rate_limit_error", JSON.stringify(quotaError)) + check("#980 the same 429 to any other prompt is still a rate limit", quotaError?.type === "rate_limit_error" && quotaError.status === undefined, JSON.stringify(quotaError)) } // antigravity #1028: DeepSeek Harness's @-path paragraph reaches agy