diff --git a/packages/cli/src/utils/agent-directory.ts b/packages/cli/src/utils/agent-directory.ts index 106850521..d2031adbd 100644 --- a/packages/cli/src/utils/agent-directory.ts +++ b/packages/cli/src/utils/agent-directory.ts @@ -62,8 +62,9 @@ export async function resolveAgentEntry( } } - // A complete agent UUID is an exact identity: the daemon falls back to a - // title match, which must not answer for an ID that does not exist. + // COMPAT(fullAgentIdExact): daemons before v0.16.0 resolve a full agent ID + // that matches no agent to an agent titled with it, so archive, detach and + // reload accept their answer only when it is that ID. Remove after 2027-05-15. if (FULL_AGENT_UUID_PATTERN.test(trimmed)) { const agentId = trimmed.toLowerCase(); const fetchResult = await client.fetchAgent({ agentId }); diff --git a/packages/cli/tests/27-agent-delete.test.ts b/packages/cli/tests/27-agent-delete.test.ts index 349125109..77bc0301d 100644 --- a/packages/cli/tests/27-agent-delete.test.ts +++ b/packages/cli/tests/27-agent-delete.test.ts @@ -13,8 +13,8 @@ import assert from "node:assert"; import { runLocalPaseo } from "./helpers/local-cli.ts"; import { getAvailablePort } from "./helpers/network.ts"; -import { runPaseoCli, startTestDaemon } from "./helpers/test-daemon.ts"; -import { mkdtemp, rm } from "fs/promises"; +import { createTempDirs, runPaseoCli, startTestDaemon } from "./helpers/test-daemon.ts"; +import { mkdtemp, rm, writeFile } from "fs/promises"; import { tmpdir } from "os"; import { join } from "path"; @@ -135,6 +135,64 @@ try { } console.log("✓ delete reports AGENT_NOT_FOUND for an unknown ID\n"); } + + { + console.log("Test 10: a missing full ID does not delete an agent titled with it"); + const missingId = "11111111-2222-4333-8444-555555555555"; + const titledId = "c9a97e5d-4a92-4646-a016-53032146d0a1"; + const dirs = await createTempDirs(); + await writeFile( + join(dirs.paseoHome, "agents", `${titledId}.json`), + JSON.stringify( + { + id: titledId, + provider: "codex", + cwd: dirs.workDir, + createdAt: "2026-09-03T18:29:21.949Z", + updatedAt: "2026-09-03T18:29:21.949Z", + title: missingId, + labels: {}, + lastStatus: "closed", + }, + null, + 2, + ), + ); + const daemon = await startTestDaemon(dirs); + const host = `127.0.0.1:${daemon.port}`; + try { + for (const command of ["inspect", "delete"]) { + const result = await runPaseoCli(daemon, [ + "agent", + command, + missingId, + "--json", + "--host", + host, + ]); + assert.strictEqual(result.exitCode, 1, `${command}: ${result.stdout}`); + assert.strictEqual( + JSON.parse(result.stderr).error.code, + "AGENT_NOT_FOUND", + `${command}: ${result.stderr}`, + ); + } + + const titled = await runPaseoCli(daemon, [ + "agent", + "inspect", + titledId, + "--json", + "--host", + host, + ]); + assert.strictEqual(titled.exitCode, 0, titled.stderr); + assert.strictEqual(JSON.parse(titled.stdout).Id, titledId); + } finally { + await daemon.stop(); + } + console.log("✓ a missing full ID does not delete an agent titled with it\n"); + } } finally { await rm(paseoHome, { recursive: true, force: true }); } diff --git a/packages/server/src/server/session.ts b/packages/server/src/server/session.ts index ae19cdc0d..164792308 100644 --- a/packages/server/src/server/session.ts +++ b/packages/server/src/server/session.ts @@ -319,6 +319,7 @@ type ProviderSubagentManagerEvent = Extract< // Clients before 0.1.45 validate providers with z.enum(["claude", "codex", "opencode"]) and reject // the entire session message if they encounter an unknown provider. const LEGACY_PROVIDER_IDS = new Set(["claude", "codex", "opencode"]); +const FULL_AGENT_ID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i; const MIN_VERSION_ALL_PROVIDERS = "0.1.45"; const MIN_VERSION_EXPLICIT_WORKSPACE_RECOVERY = "0.1.105"; function errorToFriendlyMessage(error: unknown): string { @@ -5767,6 +5768,12 @@ export class Session { return { ok: true, agentId: trimmed }; } + // A complete agent ID names one agent. When none has it, no prefix or + // title answers for it, so a command never acts on a different agent. + if (FULL_AGENT_ID_PATTERN.test(trimmed)) { + return { ok: false, notFound: true, error: `Agent not found: ${trimmed}` }; + } + const prefixMatches = Array.from(knownIds).filter((id) => id.startsWith(trimmed)); if (prefixMatches.length === 1) { return { ok: true, agentId: prefixMatches[0] };