fix: preserve reset acp session metadata

This commit is contained in:
Tak Hoffman
2026-03-26 11:27:39 -05:00
parent 74b0a948e3
commit 22f9c19a39
2 changed files with 66 additions and 2 deletions

View File

@@ -1738,7 +1738,7 @@ describe("gateway server sessions", () => {
});
test("sessions.reset closes ACP runtime handles for ACP sessions", async () => {
const { dir } = await createSessionStoreDir();
const { dir, storePath } = await createSessionStoreDir();
await writeSingleLineSession(dir, "sess-main", "hello");
await writeSessionStore({
@@ -1751,6 +1751,11 @@ describe("gateway server sessions", () => {
agent: "codex",
runtimeSessionName: "runtime:reset",
mode: "persistent",
runtimeOptions: {
runtimeMode: "auto",
timeoutSeconds: 30,
},
cwd: "/tmp/acp-session",
state: "idle",
lastActivityAt: Date.now(),
},
@@ -1758,10 +1763,39 @@ describe("gateway server sessions", () => {
},
});
const { ws } = await openClient();
const reset = await rpcReq<{ ok: true; key: string }>(ws, "sessions.reset", {
const reset = await rpcReq<{
ok: true;
key: string;
entry: {
acp?: {
backend?: string;
agent?: string;
runtimeSessionName?: string;
mode?: string;
runtimeOptions?: {
runtimeMode?: string;
timeoutSeconds?: number;
};
cwd?: string;
state?: string;
};
};
}>(ws, "sessions.reset", {
key: "main",
});
expect(reset.ok).toBe(true);
expect(reset.payload?.entry.acp).toMatchObject({
backend: "acpx",
agent: "codex",
runtimeSessionName: "runtime:reset",
mode: "persistent",
runtimeOptions: {
runtimeMode: "auto",
timeoutSeconds: 30,
},
cwd: "/tmp/acp-session",
state: "idle",
});
expect(acpManagerMocks.closeSession).toHaveBeenCalledWith({
allowBackendUnavailable: true,
cfg: expect.any(Object),
@@ -1769,6 +1803,35 @@ describe("gateway server sessions", () => {
reason: "session-reset",
sessionKey: "agent:main:main",
});
const store = JSON.parse(await fs.readFile(storePath, "utf-8")) as Record<
string,
{
acp?: {
backend?: string;
agent?: string;
runtimeSessionName?: string;
mode?: string;
runtimeOptions?: {
runtimeMode?: string;
timeoutSeconds?: number;
};
cwd?: string;
state?: string;
};
}
>;
expect(store["agent:main:main"]?.acp).toMatchObject({
backend: "acpx",
agent: "codex",
runtimeSessionName: "runtime:reset",
mode: "persistent",
runtimeOptions: {
runtimeMode: "auto",
timeoutSeconds: 30,
},
cwd: "/tmp/acp-session",
state: "idle",
});
ws.close();
});

View File

@@ -359,6 +359,7 @@ export async function performGatewaySessionReset(params: {
lastAccountId: currentEntry?.lastAccountId,
lastThreadId: currentEntry?.lastThreadId,
skillsSnapshot: currentEntry?.skillsSnapshot,
acp: currentEntry?.acp,
inputTokens: 0,
outputTokens: 0,
totalTokens: 0,