agy-cli 0.1.49: a session opened before a line was reworded is not resumed (#1151)

A parked session was keyed on the client's instructions as written. agy
keeps the instructions a session was opened with, so a Codex conversation
parked under 0.1.47 (whose "You are a coding agent running in the Codex
CLI" line went to agy as written, and was turned away) was resumed after
0.1.48 began rewording that line, and every turn on it went on getting
429 for up to the 6h resume window. jx407 found this on #1151.

The parked hash is now taken over the instructions as agy is sent them
(outgoing: the turned-away lines reworded), with the same clock and billing
stripping as before. When the rewording changes, the parked session is not
taken and a new one is opened; when it doesn't, it resumes as before.

Run (WSL magpie-desktop, from the repo root, HOME a temp dir):
- packages/agy-cli `bun test`: 21 pass, 0 fail.
- node --test test/conversation-key.mjs: 34 pass, including the new
  "#1151: a parked session is keyed on the instructions as agy was sent
  them".
Broken by hand: with park/takeParked hashing instructionsIdentity again,
the new test fails (33 pass, 1 fail).
Not tried: a real agy session parked under 0.1.47 and resumed under this
version.
This commit is contained in:
yetone
2026-11-14 22:15:14 +08:00
parent a617ecfd42
commit 1c3c58be56
3 changed files with 42 additions and 4 deletions
+12 -2
View File
@@ -2720,7 +2720,7 @@ function park(proc) {
historyHash: digest(historyKey(proc.expectedMessages)),
historyHashSansInputs: digest(historyKey(stripToolUseInputs(proc.expectedMessages))),
toolUseIdentitiesHash: digest(toolUseIdentitiesKey(proc.expectedMessages) ?? ""),
instructionsHash: digest(instructionsIdentity(proc.instructions)),
instructionsHash: digest(sentInstructionsIdentity(proc.instructions)),
workDir: proc.workDir,
at: Date.now(),
})
@@ -2736,7 +2736,7 @@ function takeParked(convKey, opts) {
unparked.add(convKey)
saveParked()
if (Date.now() - entry.at > RESUME_TTL_MS || (entry.workDir ?? null) !== (opts.workDir ?? null) ||
entry.instructionsHash !== digest(instructionsIdentity(opts.instructions))) return null
entry.instructionsHash !== digest(sentInstructionsIdentity(opts.instructions))) return null
const incoming = digest(historyKey(opts.history))
if (entry.historyHash === incoming) return { sessionId: entry.sessionId, expectedMessages: opts.history }
// Sans-inputs resume needs the hashes written by current park(). Old
@@ -3327,6 +3327,16 @@ function instructionsIdentity(text) {
return compactIdentity(stripVolatileSystem(text))
}
// sentInstructionsIdentity is the instructions as agy was handed them
// (outgoing: the lines Antigravity turns away reworded), as a parked
// session is keyed. A session agy opened with a line a later version
// rewords keeps that line in its own copy, and every turn on it is turned
// away, so when the rewording changes, the session is not resumed and a
// new one is opened with the instructions as they go now (#1151).
function sentInstructionsIdentity(text) {
return compactIdentity(outgoing(stripVolatileSystem(text)))
}
// Message text used for conversation/history identity: billing header lines,
// and clock lines only inside <system-reminder> blocks (Claude Code injects
// these on later turns too, so a mid-chat clock change must not rewrite the
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-agy-cli-auth",
"version": "0.1.48",
"version": "0.1.49",
"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",
+29 -1
View File
@@ -15,7 +15,7 @@ process.env.AGY_BRIDGE_STATE_FILE = path.join(workspace, "sessions.json")
process.env.HOME = workspace
fs.writeFileSync(
path.join(workspace, "bridge.mjs"),
source + "\nexport { conversationKey, stripVolatileOpening, stripVolatileSystem, isContinuedOpening, openingTextOf, sameInstructions, historyKey, takeParked, park, instructionsIdentity, Turn };\n",
source + "\nexport { conversationKey, stripVolatileOpening, stripVolatileSystem, isContinuedOpening, openingTextOf, sameInstructions, historyKey, takeParked, park, instructionsIdentity, digest, Turn };\n",
)
const {
conversationKey,
@@ -28,6 +28,7 @@ const {
takeParked,
park,
instructionsIdentity,
digest,
Turn,
} = await import(pathToFileURL(path.join(workspace, "bridge.mjs")).href)
after(() => fs.rmSync(workspace, { recursive: true, force: true }))
@@ -366,6 +367,33 @@ test("takeParked uses the same instruction stripping, so a clock change still re
)
})
test("#1151: a parked session is keyed on the instructions as agy was sent them", () => {
// A session agy opened before a line was reworded keeps the line, so a
// version that rewords it must not resume that session.
const convKey = "test-parked-sent"
const history = [{ role: "user", content: STABLE }, { role: "assistant", content: "ok" }]
const instructions = "You are a coding agent running in the Codex CLI, a terminal-based coding assistant.\nRules.\n"
const proc = {
convKey,
sessionId: "sess-sent",
expectedMessages: history,
instructions,
workDir: "/tmp/agy-park-test",
hasSentFirstTurn: true,
historyInvalid: false,
turn: null,
dead: false,
canPark() { return true },
}
park(proc)
const entry = JSON.parse(fs.readFileSync(process.env.AGY_BRIDGE_STATE_FILE, "utf8")).entries.find((e) => e.key === convKey)
const sent = "You're a coding agent running in the Codex CLI, a terminal-based coding assistant.\nRules.\n"
assert.equal(entry.instructionsHash, digest(instructionsIdentity(sent)))
assert.notEqual(entry.instructionsHash, digest(instructionsIdentity(instructions)))
const resumed = takeParked(convKey, { workDir: "/tmp/agy-park-test", instructions, history })
assert.equal(resumed?.sessionId, "sess-sent", "the same instructions still resume")
})
async function withKit(options, fn) {
const kit = await createBridgeKit(options)
try {