agy-cli 0.1.11: sessions survive canonicalized tool input; a first prompt's tool steps count the settled prefix as cached (ChrisJ_AI on X, klarkxy #971)

Reported by ChrisJ_AI on X: Claude Code on an agy-cli model showed 268K-input turns
at 0% cache hit, turn after turn.

Two places dropped cache reuse; both are klarkxy's #971 (closes #970):
- a follow-up turn after the client filled defaults into historical
  tool_use.input (Edit's replace_all) failed matchesHistory / takeParked, so
  the live agy session was retired and the whole prefix replayed;
- tool steps of a fresh process's first prompt reported every token as a
  cache miss until the prompt ended (no ratio learned yet).

Run at reviewed head 27245320 (win-run, xiaomi-gpu): node --test
test/usage-settlement.mjs 26/26 pass; the same file against c27ba5f7's
index.mjs fails tests 20, 21 and 24 (red on old code). bun test
packages/agy-cli: 7 of 8 pass, smoke.mjs 1 failure of 321 checks, the same
count on c27ba5f7.
Not tried: a real agy (signed out on every machine here, mote refused SSH),
so the 0% was not reproduced against Google's cache; the in-turn figure is
an estimate, not ACP usage.
This commit is contained in:
Klarkxy
2026-11-11 13:20:37 +08:00
committed by GitHub
parent 6c20f1dac7
commit 73d2006444
4 changed files with 395 additions and 15 deletions
+12 -1
View File
@@ -237,10 +237,20 @@ class FakeAgy {
const { id, method, params } = message
this.kit.acpLog.push({ method, params, sessionId: this.sessionId })
if (method === "initialize") {
this.respond(id, { protocolVersion: 1, agentInfo: { name: "fake-agy", version: this.kit.agentVersion }, agentCapabilities: {} })
this.respond(id, {
protocolVersion: 1,
agentInfo: { name: "fake-agy", version: this.kit.agentVersion },
agentCapabilities: this.kit.sessionResume ? { sessionCapabilities: { resume: {} } } : {},
})
} else if (method === "session/new" && this.kit.sessionNewError) {
// Real agy 1.5.3 not signed in: {"code":-32000,"message":"Authentication required"}.
this.send({ id, error: this.kit.sessionNewError })
} else if (method === "session/resume" && this.kit.sessionResume && params?.sessionId) {
this.sessionId = params.sessionId
if (this.token) this.control({ kind: "list" })
const models = { currentModelId: this.kit.initialAgyModel }
if (this.kit.offeredModels) models.availableModels = this.kit.offeredModels.map(([modelId, name]) => ({ modelId, name }))
this.respond(id, { sessionId: this.sessionId, models })
} else if (method === "session/new") {
this.sessionId = `fake-session-${++this.kit.sessionSerial}`
// Only the bridge's own processes carry a control token; the catalog's
@@ -404,6 +414,7 @@ export async function createBridgeKit(options = {}) {
initialAgyModel: options.initialAgyModel ?? "gemini-3.8-flash-low",
offeredModels: options.offeredModels ?? null,
sessionNewError: options.sessionNewError ?? null,
sessionResume: options.sessionResume ?? false,
agentVersion: options.agentVersion ?? "1.5.0",
setModels: [],
acpLog: [],