agy-cli 0.1.99: DSH's own notes beside a tool result no longer end the live session
seven_7cx on X (DSH + agy-cli on multi-step tool tasks): cache reads jumping between 10-20 and 0, drop_live (history_mismatch, interrupted) and session_new over and over, the history replayed each time, and the model looping on tool calls. Cause: DSH adds user-role notes of its own before a step (time-context's "Time sampled while preparing turn N, step M" clock, the runtime-context snapshot, the repeat-tool and plan-mode notes, tmux-context's location reading, a finished background job's notice, the model-changed note). Beside a live tool_result, inspectToolTurn took any such user text for the user steering, so the step was "interrupted": the live session was dropped and the whole history replayed in a new one, which put the cache at 0 and the model back at the start of its task. The same notes were already known as meta by isMetaOnlyUserText, but only for finding a prompt, not here. Fix: takeDshNotes lifts DSH's notes out of a user text in inspectToolTurn and hands them on as context notices with the result; isMetaOnlyUserText also knows the three newer ones. Test (repeat-batch.mjs): a 9-step tool turn with one DSH note per step, in the result's own message and in a message of its own. Red on 0.1.98 (the turn never ends; drop_live per step), green now; the session is opened once and no drop_live is logged. Run (mica/mote via mote-run, bun 1.4.2): repeat-batch.mjs 81 pass, steer-in-session, conversation-key, dropped-call 50 pass, compat 13 pass. Not tried: a real DSH session against a real agy account. history_mismatch was not reproduced from DSH's shape; it was seen after a replay, and the step notes were the only DSH-specific cause found by reading DSH's plugins (dsh-time-context, dsh-tmux-context, dsh-tool-jobs, dsh-agent).
This commit is contained in:
@@ -5382,6 +5382,28 @@ const DSH_PLAN_MODE_RE = /(?:^|\r?\n)The user switched this session (?:to plan|b
|
||||
// DeepSeek Harness sends a runtime-context snapshot as its own user message;
|
||||
// a gateway that merges user messages into one string could lose text after it.
|
||||
const DSH_RUNTIME_SNAPSHOT_RE = /^Current runtime context(?:\. This snapshot supersedes earlier runtime-context snapshots\.(?:\r?\n[\s\S]*)?|: none\. Earlier runtime-context snapshots no longer apply\.)$/
|
||||
// tmux-context's location reading, a finished background job's notice and the
|
||||
// note that the model changed: user-role text DSH adds on its own too.
|
||||
const DSH_TMUX_RE = /(?:^|\r?\n)tmux location \(turn \d+\):\r?\nsession [^\r\n]*\r?\nwindow active=[^\r\n]*/g
|
||||
const DSH_JOB_RE = /(?:^|\r?\n)background job \S+ \([^\r\n]*\) finished [^\r\n]*/g
|
||||
const DSH_MODEL_NOTE_RE = /(?:^|\r?\n)\[model changed: assistant turns above this point were generated by [^\r\n]*\]/g
|
||||
const DSH_NOTE_RES = [DSH_TIME_CONTEXT_RE, DSH_REPEAT_TOOL_RE, DSH_PLAN_MODE_RE, DSH_TMUX_RE, DSH_JOB_RE, DSH_MODEL_NOTE_RE]
|
||||
|
||||
// DSH's own notes in a user text, apart from what the user wrote. Beside a
|
||||
// live tool_result they are context for the model, never the user steering
|
||||
// (seven_7cx on X: every step's clock note dropped the live session).
|
||||
function takeDshNotes(text) {
|
||||
if (DSH_RUNTIME_SNAPSHOT_RE.test(text.trim())) return { notes: [text.trim()], rest: "" }
|
||||
const notes = []
|
||||
let rest = text
|
||||
for (const re of DSH_NOTE_RES) {
|
||||
rest = rest.replace(re, (match) => {
|
||||
notes.push(match.trim())
|
||||
return ""
|
||||
})
|
||||
}
|
||||
return { notes, rest }
|
||||
}
|
||||
|
||||
function isMetaOnlyUserText(text) {
|
||||
const rest = stripMagpiePlaceholderNotice(text)
|
||||
@@ -5391,6 +5413,9 @@ function isMetaOnlyUserText(text) {
|
||||
.replace(DSH_TIME_CONTEXT_RE, "")
|
||||
.replace(DSH_REPEAT_TOOL_RE, "")
|
||||
.replace(DSH_PLAN_MODE_RE, "")
|
||||
.replace(DSH_TMUX_RE, "")
|
||||
.replace(DSH_JOB_RE, "")
|
||||
.replace(DSH_MODEL_NOTE_RE, "")
|
||||
.replace(/\[Request interrupted by user(?: for tool use)?\]/g, "")
|
||||
.replace(/\[(?:SYSTEM NOTIFICATION|MESSAGE FROM NON-USER SOURCE) - NOT USER INPUT\]/g, "")
|
||||
.trim()
|
||||
@@ -5840,7 +5865,14 @@ function inspectToolTurn(results, body) {
|
||||
out = appendResultPart(out, resultIndex, parseUserImage(block))
|
||||
continue
|
||||
}
|
||||
const rawText = blockText(block)
|
||||
let rawText = blockText(block)
|
||||
if (message.role === "user") {
|
||||
const dsh = takeDshNotes(rawText)
|
||||
if (dsh.notes.length) {
|
||||
notices.push(...dsh.notes)
|
||||
rawText = dsh.rest
|
||||
}
|
||||
}
|
||||
if (!seenResult && message.role === "user" && rawText.trim()) {
|
||||
// A user can steer a pending tool turn from either side of a tool_result.
|
||||
// Replay the instruction as a user prompt, never as an MCP tool response.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-agy-cli-auth",
|
||||
"version": "0.1.98",
|
||||
"version": "0.1.99",
|
||||
"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",
|
||||
|
||||
@@ -1694,6 +1694,59 @@ test("live tool-turn drop logs drop_live and carries exact reason into session_n
|
||||
assert.equal(sessionNews.at(-1)?.reason, "history_mismatch")
|
||||
})
|
||||
|
||||
// seven_7cx on X (DSH + agy-cli): a multi-step tool task dropped its live
|
||||
// session at nearly every step (drop_live "interrupted"), so the cache read
|
||||
// fell to 0 and the whole history was replayed. DSH adds user-role notes of
|
||||
// its own before a step (time-context's clock, tmux-context's reading, a
|
||||
// finished job's notice, a model-change note); none is the user steering.
|
||||
const DSH_STEP_NOTES = [
|
||||
"Time sampled while preparing turn 3, step 2: 2026-11-18T10:24:33+08:00[Asia/Shanghai]\nBrowser time zone for this request: Asia/Shanghai. Interpret otherwise-unqualified dates and times in this zone.\nElapsed since the preceding step context: 12s.",
|
||||
"Time sampled while preparing turn 3, step 3: 2026-11-18T10:24:45Z",
|
||||
"Current runtime context. This snapshot supersedes earlier runtime-context snapshots.\nsession: main",
|
||||
"Current runtime context: none. Earlier runtime-context snapshots no longer apply.",
|
||||
"You are repeating the exact same tool call with identical arguments. Carefully analyze the previous result before calling again: if the task is not complete, try a different approach or different arguments instead of repeating the call.",
|
||||
"The user switched this session to plan mode.",
|
||||
"tmux location (turn 3):\nsession dev, window 1 \"main\", pane 0 %4\nwindow active=1, pane active=1, layout b25d,200x50,0,0,2",
|
||||
"background job job_7 (bash: npm test) finished exit 0. Read its output with job_output.",
|
||||
"[model changed: assistant turns above this point were generated by deepseek-v4; the session continues with agy-cli/gemini]",
|
||||
]
|
||||
|
||||
for (const shape of ["same message", "own message"]) {
|
||||
test(`a multi-step tool turn with DSH's own notes (${shape}) keeps its live session`, async () => {
|
||||
const stderr = captureStderr()
|
||||
try {
|
||||
await withKit({}, async (kit) => {
|
||||
kit.defaultPrompt = async (agent) => {
|
||||
for (let step = 0; step < DSH_STEP_NOTES.length; step++) await agent.tool("Read", { path: `/repo/${step}.txt` })
|
||||
await agent.text("done")
|
||||
return { stopReason: "end_turn" }
|
||||
}
|
||||
const meta = { user_id: `dsh-live-${shape}` }
|
||||
let body = baseBody({ metadata: meta, messages: [{ role: "user", content: "TOOL read everything" }] })
|
||||
let parsed = await readSse(await kit.request(body))
|
||||
for (const note of DSH_STEP_NOTES) {
|
||||
assert.equal(parsed.stopReason, "tool_use", JSON.stringify(parsed))
|
||||
const call = parsed.content.find((block) => block.type === "tool_use")
|
||||
const result = { type: "tool_result", tool_use_id: call.id, content: `ok ${call.id}` }
|
||||
body = baseBody({ metadata: meta, messages: [
|
||||
...body.messages,
|
||||
{ role: "assistant", content: [call] },
|
||||
...(shape === "same message"
|
||||
? [{ role: "user", content: [result, { type: "text", text: note }] }]
|
||||
: [{ role: "user", content: [result] }, { role: "user", content: [{ type: "text", text: note }] }]),
|
||||
] })
|
||||
parsed = await readSse(await kit.request(body))
|
||||
}
|
||||
assert.equal(parsed.stopReason, "end_turn", JSON.stringify(parsed))
|
||||
assert.equal(sessionsOpened(kit), 1, "one live session for the whole turn")
|
||||
})
|
||||
} finally {
|
||||
stderr.restore()
|
||||
}
|
||||
assert.deepEqual(stderr.lines.filter((row) => row.action === "drop_live"), [])
|
||||
})
|
||||
}
|
||||
|
||||
test("A16: oversized history[0] cannot evict the newest history reply before <current_turn>", async () => {
|
||||
await withKit({ env: { AGY_BRIDGE_MAX_PROMPT_BYTES: String(16 * 1024) } }, async (kit) => {
|
||||
scriptedAgent(kit)
|
||||
|
||||
Reference in New Issue
Block a user