can1357/oh-my-pi · error · SessionResolutionError
Session "${sessionArg}" belongs to a directory that no longe
Error message
Session "${sessionArg}" belongs to a directory that no longer exists (${sourceCwd}); run interactively to move it into the current project. What it means
When resuming a session whose recorded project directory no longer exists on disk, omp offers to move the session into the current project. In non-interactive contexts no move prompt can be shown ('unavailable'), so moveMissingCwdSessionIfNeeded throws this SessionResolutionError telling the user to run interactively to perform the move.
Source
Thrown at packages/coding-agent/src/main.ts:709
| { status: "not-needed" }
| { status: "declined" }
| { status: "moved"; manager: SessionManager };
async function moveMissingCwdSessionIfNeeded(
sessionArg: string,
session: SessionInfo,
cwd: string,
sessionDir: string | undefined,
askToMoveSession: SessionPrompt,
): Promise<MissingCwdMoveResult> {
const sourceCwd = session.cwd;
if (!sourceCwd || fsSync.existsSync(sourceCwd)) {
return { status: "not-needed" };
}
const movePromptResult = await askToMoveSession(session);
if (movePromptResult === "unavailable") {
throw new SessionResolutionError(
`Session "${sessionArg}" belongs to a directory that no longer exists (${sourceCwd}); run interactively to move it into the current project.`,
);
}
if (movePromptResult === "declined") {
return { status: "declined" };
}
// Open anchored at the (now-missing) recorded cwd: `open` otherwise falls back
// to the launch cwd, which would make the `moveTo` below a no-op whenever the
// move target equals the current project dir. moveTo never chdirs, so the
// stale cwd is only a relocation source, not a directory we enter.
const manager = await SessionManager.open(session.path, sessionDir, undefined, { initialCwd: sourceCwd });
await manager.moveTo(cwd, sessionDir);
return { status: "moved", manager };
}
type ResumedProjectResult = { cwd: string; chdirFailed?: string };
View on GitHub (pinned to 9690622007)
Solutions
- Run omp interactively (in a TTY) and resume the session; accept the move prompt to relocate it into the current project.
- Recreate the original directory (mkdir -p <sourceCwd>) so the existence check passes, then resume.
- Hand-edit/move the session .jsonl into the current project's sessions directory.
Example fix
// non-interactive fails: omp --resume <id> < /dev/null // interactive instead: omp --resume <id> # answer 'yes' to the move prompt
Defensive patterns
Strategy: try-catch
Validate before calling
// check the session's recorded cwd before resuming non-interactively
import * as fsSync from "node:fs";
if (!fsSync.existsSync(recordedSessionCwd)) {
console.error(`Session project dir ${recordedSessionCwd} is gone; resume interactively to move it.`);
} Try / catch
try {
await resumeSession(id);
} catch (err) {
if (err.message.includes("belongs to a directory that no longer exists")) {
// fall back to interactive prompt or recreate the dir
}
} Prevention
- Resume sessions from a TTY so the interactive move prompt is available.
- Avoid deleting/renaming project directories that still own live sessions.
- In CI, recreate the original directory path before resuming.
When it happens
Trigger: Resuming (or forking from) a session whose sourceCwd directory was deleted/renamed, while askToMoveSession returns 'unavailable' (no TTY / non-interactive mode).
Common situations: Project folder deleted or moved since the session was created; working inside a container/CI where the original path never existed; resuming over SSH without an interactive terminal.
Related errors
- Could not switch to resumed project ${resumedCwd} (${error i
- Import source is neither file nor directory: ${target}
- Session file not found: ${resolved}
- No files matched "${pattern}"
- Not a file: ${shortenPath(resolved)}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/92fa97ba4c18ecb4.
Report an issue: GitHub.