From c51431fc985e136ae271de53cc4d9a4be0ad50fc Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 02:12:51 +0000 Subject: [PATCH] fix(server): list commands without starting an archived agent's runtime (#11521) A timeline read loads an archived agent as a history session. The list commands handler checked archivedAt only for agents that were not loaded, so it called listCommands on that session and started the provider process. Read the stored record for loaded agents too. Co-authored-by: phanthawas.jir --- .../src/server/daemon-client.e2e.test.ts | 67 +++++++++++++++++++ packages/server/src/server/session.ts | 6 +- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/packages/server/src/server/daemon-client.e2e.test.ts b/packages/server/src/server/daemon-client.e2e.test.ts index ea140238d2..47aab50543 100644 --- a/packages/server/src/server/daemon-client.e2e.test.ts +++ b/packages/server/src/server/daemon-client.e2e.test.ts @@ -590,6 +590,73 @@ test("agent.config.apply sets an option that has no control and the next snapsho } }); +test("listing commands after importing archived history does not call the provider", async () => { + const clients = createTestAgentClients(); + const codex = clients.codex as AgentClient; + const listed: string[] = []; + // Records which session phase lists commands; behavior is the fake client's. + function recordListCommands(session: AgentSession, phase: string): AgentSession { + const list = session.listCommands?.bind(session); + session.listCommands = async () => { + listed.push(phase); + return (await list?.()) ?? []; + }; + return session; + } + const recordingCodex: AgentClient = Object.create(codex, { + createSession: { + value: async (...args: Parameters) => + recordListCommands(await codex.createSession(...args), "created"), + }, + resumeSession: { + value: async (...args: Parameters) => + recordListCommands(await codex.resumeSession(...args), "resumed"), + }, + }); + const root = mkdtempSync(path.join(tmpdir(), "paseo-archived-commands-")); + const cwd = path.join(root, "repo"); + const staticDir = path.join(root, "static"); + mkdirSync(cwd); + mkdirSync(staticDir); + const startDaemon = () => + createTestPaseoDaemon({ + agentClients: { ...clients, codex: recordingCodex }, + paseoHomeRoot: root, + staticDir, + cleanup: false, + }); + const connectClient = (port: number) => + new DaemonClient({ url: `ws://127.0.0.1:${port}/ws`, appVersion: "0.1.82" }); + let daemon = await startDaemon(); + let client = connectClient(daemon.port); + + try { + await client.connect(); + await client.fetchAgents({ subscribe: {} }); + const agent = await client.createAgent({ provider: "codex", cwd, title: "Archived agent" }); + await client.archiveAgent(agent.id); + await client.close(); + await daemon.close(); + + // Simulate an archived record from before timelines were stored in SQLite. + rmSync(path.join(daemon.paseoHome, "paseo.db")); + daemon = await startDaemon(); + client = connectClient(daemon.port); + await client.connect(); + await client.fetchAgents({ subscribe: {} }); + const timeline = await client.fetchAgentTimeline(agent.id, { limit: 5 }); + expect(timeline.error).toBeNull(); + const commands = await client.listCommands(agent.id); + + expect(listed).toEqual([]); + expect(commands).toMatchObject({ commands: [], error: `Agent not found: ${agent.id}` }); + } finally { + await client.close(); + await daemon.close(); + rmSync(root, { recursive: true, force: true }); + } +}); + test("createAgent with background initialPrompt returns a running snapshot before turn completion", async () => { const daemon = await createTestPaseoDaemon(); const client = new DaemonClient({ diff --git a/packages/server/src/server/session.ts b/packages/server/src/server/session.ts index 33680247d1..9b02ce7f20 100644 --- a/packages/server/src/server/session.ts +++ b/packages/server/src/server/session.ts @@ -5916,9 +5916,11 @@ export class Session { try { const existing = this.agentManager.getAgent(agentId); - const stored = existing ? null : await this.agentStorage.get(agentId); + // Check the record even when loaded: a timeline read loads an archived agent for history, + // and listing its commands would start the provider process. + const stored = await this.agentStorage.get(agentId); const agent = - existing || (stored && !stored.archivedAt) + !stored?.archivedAt && (existing || stored) ? await ensureAgentLoaded(agentId, { agentManager: this.agentManager, agentStorage: this.agentStorage,