agy-cli 0.1.30: a new agy session logs why the live one was not reused (#1058)
#1058: in one Claude Code conversation every request started a new agy conversation, so Gemini 4 Carbon's cache read stayed at 0. The bridge reuses a live session only when the conversation key, work dir, instructions and history all match, and nothing said which one failed. acquireProcLocked now writes one content-free stderr row per new session ("[agy-bridge] {event: agy_bridge_session, action: session_new, reason, conv, fresh, resumed, parked, history}"). reason is no_live (no session under this conversation key), or for a live one that was dropped: forced, dead, retiring, work_dir, instructions, history or fresh_after_first. conv is the key's 12-char digest, so a key that changes per request shows as a new conv each time. The rows have their own 30/min budget, so they never crowd out the tool-state rows. magpie writes plugin stderr into its log, so the reporter can send them. Run (on a separate test Mac, temp HOME): bun scripts/check.mjs agy-cli ok; packages/agy-cli bun test ./agy-cli.test.mjs 14 pass 0 fail; test/repeat-batch.mjs 20 pass, test/conversation-key.mjs 31 pass. Broken by hand: with the logSessionEvent call disabled, the new #1058 test fails. Not tried: a real agy, or the reporter's Claude Code requests. This does not fix the cache miss; it finds which check misses. Reported-by: chrisjian
This commit is contained in:
@@ -2395,6 +2395,7 @@ async function acquireProcLocked(agyPath, convKey, opts, isFreshConversation, fo
|
||||
const candidate = findLiveContinuedProc(opts)
|
||||
if (candidate && lockedKeys.has(candidate.convKey)) existing = rekeyProc(candidate, convKey)
|
||||
}
|
||||
let why = "no_live"
|
||||
if (existing) {
|
||||
if (!existing.dead && existing.turn) {
|
||||
throw new BusyError("agy bridge: this conversation still has an unfinished response")
|
||||
@@ -2424,6 +2425,10 @@ async function acquireProcLocked(agyPath, convKey, opts, isFreshConversation, fo
|
||||
await existing.updateTools(opts.tools)
|
||||
return { proc: existing, history: matchedHistory }
|
||||
}
|
||||
why = forceNew ? "forced" : existing.dead ? "dead" : existing.retiring ? "retiring" :
|
||||
existing.workDir !== opts.workDir ? "work_dir" :
|
||||
!sameInstructions(existing.instructions, opts.instructions) ? "instructions" :
|
||||
!(existing.matchesHistory(matchedHistory) || continuedFresh) ? "history" : "fresh_after_first"
|
||||
existing.retiring = true
|
||||
dropFromPool(existing)
|
||||
await existing.stop().catch(() => {})
|
||||
@@ -2442,6 +2447,12 @@ async function acquireProcLocked(agyPath, convKey, opts, isFreshConversation, fo
|
||||
throw error
|
||||
}
|
||||
pool.set(convKey, proc)
|
||||
// Why this request got a new agy session, so a cache that never hits can be
|
||||
// traced to the check that failed (#1058). Counts only, never content.
|
||||
logSessionEvent(proc, why, {
|
||||
fresh: !!isFreshConversation, resumed: !!proc.resumed,
|
||||
parked: !!resume, history: Array.isArray(opts.history) ? opts.history.length : null,
|
||||
})
|
||||
return { proc, history: opts.history }
|
||||
}
|
||||
|
||||
@@ -2496,6 +2507,21 @@ function logBridgeEvent(proc, turn, action, reason, meta = {}, extra = {}) {
|
||||
try { process.stderr.write("[agy-bridge] " + JSON.stringify(row) + "\n") } catch {}
|
||||
}
|
||||
|
||||
// One row per new agy session, on a budget of its own so it never crowds out
|
||||
// the tool-state rows above.
|
||||
let sessionWindowStart = 0
|
||||
let sessionWindowCount = 0
|
||||
|
||||
function logSessionEvent(proc, reason, extra) {
|
||||
if (process.env.AGY_BRIDGE_EVENTS === "0") return
|
||||
const now = Date.now()
|
||||
if (now - sessionWindowStart >= EVENT_WINDOW_MS) { sessionWindowStart = now; sessionWindowCount = 0 }
|
||||
if (sessionWindowCount++ >= EVENT_MAX_PER_WINDOW) return
|
||||
const row = { event: "agy_bridge_session", host_epoch: HOST_EPOCH, ts: now,
|
||||
conv: proc?.convKey ? digest(proc.convKey).slice(0, 12) : null, action: "session_new", reason, ...extra }
|
||||
try { process.stderr.write("[agy-bridge] " + JSON.stringify(row) + "\n") } catch {}
|
||||
}
|
||||
|
||||
// Per-conversation counter of consecutive unmatched tool-result requests that
|
||||
// hit the same turn while its lastProgressAt did not move. A different turn,
|
||||
// any progress, a window timeout or a reclaim restarts it from zero.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-agy-cli-auth",
|
||||
"version": "0.1.29",
|
||||
"version": "0.1.30",
|
||||
"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",
|
||||
|
||||
@@ -279,6 +279,35 @@ test("A11: AGY_BRIDGE_EVENTS=verbose reports layout_flip with a req_id and no co
|
||||
assert.ok(!JSON.stringify(flips).includes("hello") && !JSON.stringify(flips).includes("Opening hook"))
|
||||
})
|
||||
|
||||
// ------------------------------------------------- #1058 session_new rows
|
||||
|
||||
test("#1058: a new agy session says why the live one was not reused, with no content", async () => {
|
||||
const stderr = captureStderr()
|
||||
try {
|
||||
await withKit({}, async (kit) => {
|
||||
scriptedAgent(kit)
|
||||
const first = baseBody({ metadata: { user_id: "why-new" }, system: "base system",
|
||||
messages: [{ role: "user", content: "hello secret" }] })
|
||||
const one = await readSse(await kit.request(first))
|
||||
const reply = { role: "assistant", content: one.content.map((block) => ({ type: "text", text: block.text })) }
|
||||
const second = { ...first, messages: [...first.messages, reply, { role: "user", content: "again" }] }
|
||||
const two = await readSse(await kit.request(second))
|
||||
assert.equal(kit.acpSpawns.length, 1, "the second turn continues the live session")
|
||||
const changed = { ...second, system: "a different system",
|
||||
messages: [...second.messages, { role: "assistant", content: two.content.map((block) => ({ type: "text", text: block.text })) },
|
||||
{ role: "user", content: "third" }] }
|
||||
await readSse(await kit.request(changed))
|
||||
})
|
||||
} finally {
|
||||
stderr.restore()
|
||||
}
|
||||
const rows = stderr.lines.filter((row) => row.action === "session_new")
|
||||
assert.deepEqual(rows.map((row) => row.reason), ["no_live", "no_live"],
|
||||
"a changed system prompt is a different conversation key, so it starts with no live session")
|
||||
assert.notEqual(rows[0].conv, rows[1].conv)
|
||||
assert.ok(!JSON.stringify(rows).includes("secret") && !JSON.stringify(rows).includes("system"))
|
||||
})
|
||||
|
||||
// ------------------------------------------------------- A15 pool pressure
|
||||
|
||||
test("A15: a full pool evicts the oldest long-detached tool turn instead of answering 503, and that conversation replays later", async () => {
|
||||
|
||||
Reference in New Issue
Block a user