agy-cli 0.1.76: a tool result buried under a client's own notice settles the round, not tool_state_conflict (#1208)

A client that answered the bridge's pending call and then wrote an
assistant notice of its own and a new prompt (Hermes Agent's "This turn
did not complete…" closer) carried the result in history, not the
trailing. With no trailing results the request took the acquire path,
lineageVerdict saw the carried tool_use and answered 400
tool_state_conflict on every resend until the 30-minute result timeout.

Now, when every call of the pending turn that the request carries has a
tool_result after it, the round is settled on the client's side: the
turn is superseded (logged as lineage_answered) and the request replays
as a new session, the buried result and the new prompt included. A
carried call with no result is still a terminal conflict.

Reported by 1468323775 with the exact request shape and a live repro.

Run (mote, HOME=$(mktemp -d)):
- packages/agy-cli: bun test: 36 pass, 0 fail (smoke 382 checks).
- bun scripts/check.mjs agy-cli: ok.

Broken by hand: origin/main's index.mjs with the new smoke checks: 3
fail, with the reporter's 400 tool_state_conflict body.

Not tried: a real agy account (the local one answers 403) or Hermes
Agent itself. The live session's prompt cache is not kept on this path:
it replays as a new session, as an interrupted round already does.
This commit is contained in:
yetone
2026-11-16 15:02:22 +08:00
parent 2af72df71a
commit 481ec997a5
3 changed files with 42 additions and 3 deletions
+21 -2
View File
@@ -3231,9 +3231,10 @@ async function acquireProcLocked(agyPath, convKey, opts, isFreshConversation, fo
} }
if (existing && !existing.dead && existing.turn) { if (existing && !existing.dead && existing.turn) {
const lineage = lineageVerdict(existing, existing.turn, opts) const lineage = lineageVerdict(existing, existing.turn, opts)
if (lineage === "fork") { if (lineage === "fork" || lineage === "answered") {
const orphan = existing.turn const orphan = existing.turn
logBridgeEvent(existing, orphan, "superseded", "lineage_fork", opts, { superseded_turn_id: orphan.turnId }) logBridgeEvent(existing, orphan, "superseded", lineage === "fork" ? "lineage_fork" : "lineage_answered", opts,
{ superseded_turn_id: orphan.turnId })
await reclaimStaleTurn(existing, orphan, SUPERSEDED_NOTE) await reclaimStaleTurn(existing, orphan, SUPERSEDED_NOTE)
existing = null existing = null
} else if (lineage === "conflict") { } else if (lineage === "conflict") {
@@ -3462,6 +3463,11 @@ function lineageVerdict(proc, turn, opts) {
const ids = new Set(turn.calls.map((call) => call.id)) const ids = new Set(turn.calls.map((call) => call.id))
const carried = (opts.messages || []).some((message) => Array.isArray(message?.content) && const carried = (opts.messages || []).some((message) => Array.isArray(message?.content) &&
message.content.some((block) => block?.type === "tool_use" && ids.has(block.id))) message.content.some((block) => block?.type === "tool_use" && ids.has(block.id)))
// The client answered every call of this turn it carries, then wrote on past
// the round (a notice of its own, a new prompt), so the results sit in
// history, not the trailing (#1208). The round is settled on the client's
// side: the turn is left behind, and the replay carries those results.
if (carried && carriedAnswered(opts.messages, ids)) return "answered"
if (history.length < base.length || historyKey(history.slice(0, base.length)) !== historyKey(base)) { if (history.length < base.length || historyKey(history.slice(0, base.length)) !== historyKey(base)) {
// The client no longer continues this turn's base: it was shortened or its // The client no longer continues this turn's base: it was shortened or its
// prefix was rewritten (a compaction summary). A plain new request has left // prefix was rewritten (a compaction summary). A plain new request has left
@@ -3486,6 +3492,19 @@ function lineageVerdict(proc, turn, opts) {
return carried || recorded ? "conflict" : "fork" return carried || recorded ? "conflict" : "fork"
} }
// Every tool_use of the turn's calls in messages has a tool_result after it.
function carriedAnswered(messages, ids) {
const open = new Set()
for (const message of messages || []) {
if (!Array.isArray(message?.content)) continue
for (const block of message.content) {
if (block?.type === "tool_use" && ids.has(block.id)) open.add(block.id)
else if (block?.type === "tool_result") open.delete(block.tool_use_id)
}
}
return open.size === 0
}
function replayHistoryProblem(body, resultBlocks) { function replayHistoryProblem(body, resultBlocks) {
const calls = lastAssistantCalls(trailingMessages(body).history) const calls = lastAssistantCalls(trailingMessages(body).history)
if (!calls.length) return "no_tool_use" if (!calls.length) return "no_tool_use"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@magpie-community/opencode-agy-cli-auth", "name": "@magpie-community/opencode-agy-cli-auth",
"version": "0.1.75", "version": "0.1.76",
"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", "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", "type": "module",
"main": "./opencode.mjs", "main": "./opencode.mjs",
+20
View File
@@ -2946,6 +2946,26 @@ for (const location of ["inline", "system", "developer", "user"]) {
check("terminal lineage conflicts leave the original tool turn usable", inits().length === before && stopOf(done.events) === "end_turn") check("terminal lineage conflicts leave the original tool turn usable", inits().length === before && stopOf(done.events) === "end_turn")
} }
{
// #1208: the client answered the pending call, then wrote a notice of its own
// and a new prompt, so the result is in history, not the trailing.
const body = { model, metadata: { user_id: "buried-result" },
messages: [{ role: "user", content: "TOOL buried result" }], tools: [echoTool] }
const pending = (await readSSE(await callFetch(body))).events
const answered = continuation(body, pending, "buried result text")
const buried = { ...answered, messages: [...answered.messages,
{ role: "assistant", content: "This turn did not complete. Some actions may already have run; verify their effects before resending." },
{ role: "user", content: "continue after the notice" }] }
const response = await callFetch(buried)
const final = response.status === 200 ? (await readSSE(response)).events : []
if (response.status !== 200) console.error("buried result:", response.status, await response.text())
check("a result buried under a client notice continues instead of tool_state_conflict", response.status === 200 && final.length > 0)
check("the replay carries the buried result and the new prompt", lastOf("user").text.includes("buried result text") && lastOf("user").text.includes("continue after the notice"))
// The replayed opening still says TOOL, so the fake asks for a tool again.
const done = await drive(buried, final)
check("the conversation after a buried result runs to its end", stopOf(done.events) === "end_turn")
}
{ {
// The existing LONGTOOL fake repeats identical calls until told to stop. // The existing LONGTOOL fake repeats identical calls until told to stop.
// Speed up its MCP deadline, keeping the production default repeat cap of 8. // Speed up its MCP deadline, keeping the production default repeat cap of 8.