diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 3532201..c552d24 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -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 blocks (Claude Code injects // these on later turns too, so a mid-chat clock change must not rewrite the diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index 8e3b6be..00b3fef 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.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", diff --git a/packages/agy-cli/test/conversation-key.mjs b/packages/agy-cli/test/conversation-key.mjs index 9267d78..f4c5132 100644 --- a/packages/agy-cli/test/conversation-key.mjs +++ b/packages/agy-cli/test/conversation-key.mjs @@ -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 {