{"record":{"id":"a05a6b6583393ef6","repo":"can1357/oh-my-pi","slug":"acp-session-session-sessionid-is-already-loaded","errorCode":null,"errorMessage":"ACP session ${session.sessionId} is already loaded for ${actual}, not ${expected}","messagePattern":"ACP session (.+?) is already loaded for (.+?), not (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/modes/acp/acp-agent.ts","lineNumber":1388,"sourceCode":"\t\t\t\teventType: event.type,\n\t\t\t\terror,\n\t\t\t});\n\t\t}\n\t}\n\n\t#getSessionRecord(sessionId: string): ManagedSessionRecord {\n\t\tconst record = this.#sessions.get(sessionId);\n\t\tif (!record) {\n\t\t\tthrow new Error(`Unsupported ACP session: ${sessionId}`);\n\t\t}\n\t\treturn record;\n\t}\n\n\t#assertMatchingCwd(session: AgentSession, cwd: string): void {\n\t\tconst expected = path.resolve(cwd);\n\t\tconst actual = path.resolve(session.sessionManager.getCwd());\n\t\tif (actual !== expected) {\n\t\t\tthrow new Error(`ACP session ${session.sessionId} is already loaded for ${actual}, not ${expected}`);\n\t\t}\n\t}\n\n\tasync #resolveForkSourceSessionPath(sessionId: string): Promise<string> {\n\t\tconst loaded = this.#sessions.get(sessionId);\n\t\tif (loaded) {\n\t\t\tif (isPromptTurnInFlight(loaded.promptTurn)) {\n\t\t\t\tthrow new Error(`ACP session fork is unavailable while a prompt is in progress: ${sessionId}`);\n\t\t\t}\n\t\t\tawait loaded.session.sessionManager.flush();\n\t\t\tconst sessionPath = loaded.session.sessionManager.getSessionFile();\n\t\t\tif (!sessionPath) {\n\t\t\t\tthrow new Error(`ACP session cannot be forked before it is persisted: ${sessionId}`);\n\t\t\t}\n\t\t\treturn sessionPath;\n\t\t}\n\n\t\tconst storedSession = await this.#findStoredSessionById(sessionId);","sourceCodeStart":1370,"sourceCodeEnd":1406,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/modes/acp/acp-agent.ts#L1370-L1406","documentation":"Thrown by #assertMatchingCwd when a request to reuse an already-loaded ACP session provides a cwd that differs from the cwd the session's sessionManager was opened with. The agent refuses to silently re-scope a live session to another working directory.","triggerScenarios":"A session/load, session/resume, or session/new request with an existing in-memory sessionId but a different (resolved) cwd than the one the session currently runs in.","commonSituations":"Client moved the project or changed cwd casing/relative vs absolute path; two projects sharing a session id; the client sends `~`-relative or unresolved paths.","solutions":["Send the same absolute, resolved cwd the session was originally created/loaded with.","If the new cwd is intended, unload the existing session and create/load a fresh one under the new cwd.","Normalize paths on the client (path.resolve, expand `~`) before issuing the request."],"exampleFix":"// before\nawait agent.load({ sessionId: id, cwd: \"~/proj\" });\n// after\nimport * as path from \"node:path\";\nimport * as os from \"node:os\";\nawait agent.load({ sessionId: id, cwd: path.resolve(process.cwd()) }); // or os.homedir() expansion, must match original cwd","handlingStrategy":"validation","validationCode":"import * as path from \"node:path\";\nif (path.resolve(requestedCwd) !== path.resolve(sessionCwd)) {\n  throw new Error(\"cwd differs from the session's cwd; unload and create a new session\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agent.load({ sessionId, cwd });\n} catch (err) {\n  if (err.message.includes(\"is already loaded for\")) {\n    // reuse existing session unchanged, or reload under original cwd\n  } else throw err;\n}","preventionTips":["Always send the original absolute cwd a session was created with.","Resolve and normalize cwd (path.resolve, expand ~) on the client.","When the project moves, create a new session instead of re-pointing the old one."],"tags":["acp","cwd-mismatch","session-management"],"backgroundTag":"cwd-mismatch","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}