agy-cli 0.1.85: agy's output-cap notice never reaches the client (#1235)

agy's output-cap retry writes three lines of its own into the reply (the
cut-off notice, its instruction to continue, "Retries remaining: N"); the
bridge now drops them where they start a line, held across chunks, and
keeps a mid-line quote of them. By ump45nose (#892).

The three strings were checked against the agy binary on this Mac
(strings: "Your previous response was cut off because it exceeded the
output token limit", "Please continue from where you left off, keeping
your response shorter", "Retries remaining: %d" and "%d.").

Run at e95ee1d5 (mote, HOME=$(mktemp -d)):
- bun test agy-cli.test.mjs: 20 pass, 0 fail.
- node --test repeat-batch.mjs smoke.mjs: 66 pass.
- bun scripts/check.mjs agy-cli: ok.

Broken by hand: origin/main's index.mjs with this PR's tests: "#892:
agy's output-cap notice never reaches the client" fails.

Not tried: a real turn that hits agy's output cap (the local agy account
answers 403).
This commit is contained in:
ump45nose
2026-11-17 03:33:14 +08:00
committed by GitHub
parent 44bfefb7a7
commit c52dd35bfa
5 changed files with 132 additions and 15 deletions
+5 -1
View File
@@ -346,7 +346,11 @@ 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. An ending that says "This service has been disabled in this account
dropped. So are the three lines agy writes into the reply when its own output
cap triggers a retry ("Your previous response was cut off because it exceeded
the output token limit", its instruction to continue, and "Retries
remaining: N"); the model's continuation after them still reaches the client.
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. So is the
"Verification Required" ending (Google wants the account verified), with
+4 -1
View File
@@ -247,7 +247,10 @@ 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
重试中的提示行会被去掉。agy 自己撞上输出上限后重试时,也会把三行提示写进正文
("Your previous response was cut off because it exceeded the output token limit"、
它的续写指令和 "Retries remaining: N"),这三行同样会被去掉,后面模型的续写照常
输出。若结尾是 "This service has been disabled in this account for
violation of Terms of Service",会按禁止重试的 403 语义 `permission_error` 返回,而不是
当成正常正文。结尾是 "Verification Required"(Google 要求先验证这个账号)时也一样,
并带上 agy 记下的验证链接;没有链接时说明去哪里验证。
+82 -12
View File
@@ -150,7 +150,19 @@ const refused429 = (detail) => /code 429\b/i.test(detail) && /resource has been
// It is agy's, not the model's, and the turn goes on (#1124).
const RETRY_MARKER = "\n⚠ Model produced invalid output.\n"
const RETRY_CORE = RETRY_MARKER.trim()
const HOLD_MAX = Math.max(...AGENT_ERROR_MARKERS.map((marker) => marker.length)) - 1
// agy's own output-cap retry reaches the reply as three lines of its own:
// what happened, its instruction to continue, and the retries left. The
// model's answer goes on after them in the same turn, so the notice is agy's
// and is dropped (#892). Wording as observed by lili-luo/dsh-plugin-bundle
// (dsh-llm-antigravity-acp, MIT).
const CAP_MARKER = "\n⚠ Your previous response was cut off because it exceeded the output token limit\n"
const CAP_CORE = CAP_MARKER.trim()
const CAP_TAIL_CORE = "Please continue from where you left off, keeping your response shorter"
const CAP_RETRIES_CORE = "Retries remaining: "
const CAP_RETRIES_LINE = /^Retries remaining: ?\d+\.?$/
const HOLD_MAX = Math.max(
...AGENT_ERROR_MARKERS.map((marker) => marker.length), CAP_MARKER.length, CAP_TAIL_CORE.length,
) - 1
// Opt-in. The minimal agent drops agy's own prompt components (~8,400 input
// tokens a model call, against ~500 without them), so the request goes upstream
// with the client's system prompt in their place.
@@ -1438,6 +1450,7 @@ class Turn {
this.heldText = ""
this.textTail = ""
this.openBanner = -1
this.capPending = false
this.attemptDetail = ""
this.refusedDetail = ""
this.agentErrorCore = ""
@@ -1614,7 +1627,7 @@ class Turn {
// Withholds agy's error marker, or a possible prefix of it, until it can be
// classified. agy's own marker ends the prompt; one that more text follows
// was the model quoting it (#1052). agy's retry banners are dropped where
// they start a line (#1124, #1136); one whose line hasn't ended is held.
// they start a line (#1124, #1136, #892); one whose line hasn't ended is held.
pushText(chunk) {
if (this.done || this.agentError) return
this.pushHeld(chunk)
@@ -1644,7 +1657,8 @@ class Turn {
for (let keep = Math.min(text.length, HOLD_MAX); keep > 0; keep--) {
const tail = text.slice(-keep)
if (AGENT_ERROR_MARKERS.some((marker) => marker.startsWith(tail)) ||
(keep > 1 && (RETRY_MARKER.startsWith(tail) || ATTEMPT_MARKER.startsWith(tail)))) {
(keep > 1 && (RETRY_MARKER.startsWith(tail) || ATTEMPT_MARKER.startsWith(tail) ||
CAP_MARKER.startsWith(tail)))) {
this.heldText = tail
text = text.slice(0, -keep)
break
@@ -1654,14 +1668,29 @@ class Turn {
}
// Removes agy's retry banners, each with its leading and one trailing
// newline, wherever one starts a line. Text that only quotes one mid-line is
// kept. Until the turn's text is flushed, a banner that ends the buffer is
// left in place and openBanner says where, so pushText holds it and its
// newline in the next chunk goes with it.
// newline, wherever one starts a line: the one-line retry and attempt
// banners, and the three-line output-cap notice (#892). Text that only
// quotes one mid-line is kept. Until the turn's text is flushed, a banner
// that ends the buffer is left in place and openBanner says where, so
// pushText holds it and its newline in the next chunk goes with it.
dropRetryBanner(text, final = false) {
this.openBanner = -1
let from = 0
for (;;) {
if (this.capPending) {
const end = text.indexOf("\n", from)
const line = text.slice(from, end < 0 ? text.length : end)
if (CAP_RETRIES_LINE.test(line)) {
this.capPending = false
text = text.slice(0, from) + text.slice(end < 0 ? text.length : end + 1)
continue
}
if (!final && CAP_RETRIES_CORE.startsWith(line)) {
this.openBanner = from
return text
}
this.capPending = false
}
const at = nextBanner(text, from)
if (at < 0) return text
const lineStart = at > 0 ? text[at - 1] === "\n" : this.textTail === "" || this.textTail === "\n"
@@ -1670,6 +1699,20 @@ class Turn {
continue
}
const start = at > 0 ? at - 1 : at
if (text.startsWith(CAP_CORE, at)) {
const cap = capNoticeEnd(text, at, final)
if (cap.end < 0) {
// agy's notice is still streaming: hold it with its lines' newlines
this.openBanner = start
return text
}
// The notice's "Retries remaining" line is its own line, so it can
// arrive in the next chunk after the two lines before it.
this.capPending = cap.retries
text = text.slice(0, start) + text.slice(cap.end)
from = start
continue
}
const attempt = !text.startsWith(RETRY_CORE, at)
let end = attempt ? text.indexOf("\n", at) : at + RETRY_CORE.length
if (end < 0) end = text.length
@@ -2953,13 +2996,40 @@ async function lastAgentError(file, offset) {
return found.trim().slice(0, 1000)
}
// Where agy's output-cap notice ends, given where it starts. The notice is its
// notice line, its "please continue" instruction and its "Retries remaining"
// count; a line that is neither is the model's and stays. -1 means the buffer
// still ends inside the notice; `retries` says the count line is still owed.
function capNoticeEnd(text, at, final) {
const lineAt = (from) => {
const end = text.indexOf("\n", from)
return { value: text.slice(from, end < 0 ? text.length : end), end }
}
let pos = text.indexOf("\n", at)
if (pos < 0) return { end: final ? text.length : -1, retries: false }
pos += 1
const tail = lineAt(pos)
if (tail.value === CAP_TAIL_CORE) {
if (tail.end < 0) return { end: final ? text.length : -1, retries: false }
pos = tail.end + 1
} else if (!final && CAP_TAIL_CORE.startsWith(tail.value)) {
return { end: -1, retries: false }
} else {
return { end: pos, retries: false }
}
const retries = lineAt(pos)
if (CAP_RETRIES_LINE.test(retries.value)) {
return { end: retries.end < 0 ? text.length : retries.end + 1, retries: false }
}
return { end: pos, retries: !final }
}
// Where the next retry banner of either kind starts, from `from` on.
function nextBanner(text, from) {
const retry = text.indexOf(RETRY_CORE, from)
const attempt = text.indexOf(ATTEMPT_CORE, from)
if (retry < 0) return attempt
if (attempt < 0) return retry
return Math.min(retry, attempt)
const found = [RETRY_CORE, ATTEMPT_CORE, CAP_CORE]
.map((core) => text.indexOf(core, from))
.filter((at) => at >= 0)
return found.length ? Math.min(...found) : -1
}
function dropFromPool(proc) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-agy-cli-auth",
"version": "0.1.84",
"version": "0.1.85",
"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",
+40
View File
@@ -990,6 +990,46 @@ test("#1124: the model quoting the retry banner mid-line keeps it", async () =>
})
})
// #892: agy's output cap, as it reaches the reply: agy's three-line notice and
// then the model's answer, still in the same turn.
const CAP_HEAD = "\n⚠ Your previous response was cut off because it exceeded the output token limit\n"
const CAP_TAIL = "Please continue from where you left off, keeping your response shorter\n"
const CAP_RETRIES = "Retries remaining: 3\n"
const CAP_NOTICE = CAP_HEAD + CAP_TAIL + CAP_RETRIES
test("#892: agy's output-cap notice never reaches the client", async () => {
const answer = "the rest of the answer"
for (const [chunks, want] of [
[[CAP_NOTICE + answer], answer],
[[CAP_NOTICE, answer], answer],
[[CAP_HEAD.slice(0, 20), CAP_HEAD.slice(20) + CAP_TAIL, CAP_RETRIES, answer], answer],
[[CAP_NOTICE.slice(0, 150), CAP_NOTICE.slice(150) + answer], answer],
[[CAP_HEAD, answer], answer],
[[CAP_NOTICE], ""],
[[CAP_HEAD + answer], answer],
]) {
await withKit({}, async (kit) => {
markerAgent(kit, chunks)
const parsed = await readSse(await kit.request(baseBody({ metadata: { user_id: "cap-notice" },
messages: [{ role: "user", content: "write the long answer" }] })))
assert.equal(parsed.error, null)
assert.equal(parsed.stopReason, "end_turn")
assert.equal(replyText(parsed), want)
})
}
})
test("#892: the model quoting the output-cap notice mid-line keeps it", async () => {
const chunks = ["agy prints `⚠ Your previous response was cut off because it exceeded the output token limit`", " when it retries."]
await withKit({}, async (kit) => {
markerAgent(kit, chunks)
const parsed = await readSse(await kit.request(baseBody({ metadata: { user_id: "cap-quoted" },
messages: [{ role: "user", content: "what did agy print?" }] })))
assert.equal(parsed.error, null)
assert.equal(replyText(parsed), chunks.join(""))
})
})
// #1136: agy 1.5.8's own words, byte for byte from the reporter's Codex rollout.
const EOF_ATTEMPT = (n) => `\n⚠ API error (attempt ${n}): request failed: Post "https://daily-cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse": EOF`
const NETWORK = "\n⚠ There was a network issue connecting to the server, please try again.\n"