diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 300dad4..aad7349 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -3231,9 +3231,10 @@ async function acquireProcLocked(agyPath, convKey, opts, isFreshConversation, fo } if (existing && !existing.dead && existing.turn) { const lineage = lineageVerdict(existing, existing.turn, opts) - if (lineage === "fork") { + if (lineage === "fork" || lineage === "answered") { 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) existing = null } else if (lineage === "conflict") { @@ -3462,6 +3463,11 @@ function lineageVerdict(proc, turn, opts) { const ids = new Set(turn.calls.map((call) => call.id)) const carried = (opts.messages || []).some((message) => Array.isArray(message?.content) && 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)) { // 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 @@ -3486,6 +3492,19 @@ function lineageVerdict(proc, turn, opts) { 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) { const calls = lastAssistantCalls(trailingMessages(body).history) if (!calls.length) return "no_tool_use" diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index ec6eb80..9e38935 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.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", "type": "module", "main": "./opencode.mjs", diff --git a/packages/agy-cli/test/smoke.mjs b/packages/agy-cli/test/smoke.mjs index f693c3b..3bff32d 100644 --- a/packages/agy-cli/test/smoke.mjs +++ b/packages/agy-cli/test/smoke.mjs @@ -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") } +{ + // #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. // Speed up its MCP deadline, keeping the production default repeat cap of 8.