can1357/oh-my-pi · error

ACP session ${session.sessionId} is already loaded for ${act

Error message

ACP session ${session.sessionId} is already loaded for ${actual}, not ${expected}

What it means

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.

Source

Thrown at packages/coding-agent/src/modes/acp/acp-agent.ts:1388

				eventType: event.type,
				error,
			});
		}
	}

	#getSessionRecord(sessionId: string): ManagedSessionRecord {
		const record = this.#sessions.get(sessionId);
		if (!record) {
			throw new Error(`Unsupported ACP session: ${sessionId}`);
		}
		return record;
	}

	#assertMatchingCwd(session: AgentSession, cwd: string): void {
		const expected = path.resolve(cwd);
		const actual = path.resolve(session.sessionManager.getCwd());
		if (actual !== expected) {
			throw new Error(`ACP session ${session.sessionId} is already loaded for ${actual}, not ${expected}`);
		}
	}

	async #resolveForkSourceSessionPath(sessionId: string): Promise<string> {
		const loaded = this.#sessions.get(sessionId);
		if (loaded) {
			if (isPromptTurnInFlight(loaded.promptTurn)) {
				throw new Error(`ACP session fork is unavailable while a prompt is in progress: ${sessionId}`);
			}
			await loaded.session.sessionManager.flush();
			const sessionPath = loaded.session.sessionManager.getSessionFile();
			if (!sessionPath) {
				throw new Error(`ACP session cannot be forked before it is persisted: ${sessionId}`);
			}
			return sessionPath;
		}

		const storedSession = await this.#findStoredSessionById(sessionId);

View on GitHub (pinned to 9690622007)

Solutions

  1. Send the same absolute, resolved cwd the session was originally created/loaded with.
  2. If the new cwd is intended, unload the existing session and create/load a fresh one under the new cwd.
  3. Normalize paths on the client (path.resolve, expand `~`) before issuing the request.

Example fix

// before
await agent.load({ sessionId: id, cwd: "~/proj" });
// after
import * as path from "node:path";
import * as os from "node:os";
await agent.load({ sessionId: id, cwd: path.resolve(process.cwd()) }); // or os.homedir() expansion, must match original cwd
Defensive patterns

Strategy: validation

Validate before calling

import * as path from "node:path";
if (path.resolve(requestedCwd) !== path.resolve(sessionCwd)) {
  throw new Error("cwd differs from the session's cwd; unload and create a new session");
}

Try / catch

try {
  await agent.load({ sessionId, cwd });
} catch (err) {
  if (err.message.includes("is already loaded for")) {
    // reuse existing session unchanged, or reload under original cwd
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/a05a6b6583393ef6. Report an issue: GitHub.