agy-cli 0.1.59: a turned-away system prompt fails as a 400, not a 429 the client retries (#1151)
KevinXC5's run on 0.1.58: the bridge called the refusal an invalid_request_error, but magpie logged it as a 429 and Claude Code answered with api_retry, rate_limit, every 60s up to 9 times. A stream's error event carried only type and message, and magpie's gateway takes a stream error's status from the error's own status field first and its words after (namedStatusOf); the message quotes Antigravity's "RESOURCE_EXHAUSTED (code 429)", so the words won. streamErrorOf now gives an invalid_request_error status 400, in the SSE error event and in a whole (stream: false) reply, which was a 502. A rate_limit_error and every other kind go as before. Run: bun test in packages/agy-cli on mote, 24 pass (the smoke test's new #1151 checks: the turned-away event has status 400, a whole reply is a 400, a plain quota 429 still has no status); bun scripts/check.mjs agy-cli ok. Broken by hand: without the status line both #1151 checks fail (the whole reply came back 502). Read: magpie origin/main's upstream.go and fallback.go take a numeric error.status before the words. Not tried: a real Antigravity request (the local agy account answers 403), nor a real Claude Code against the gateway. Kevin's 0.1.58 run also shows a second line of Claude Code's prompt still matched; that is not fixed here.
This commit is contained in:
@@ -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" },
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user