earendil-works/pi · error
Cannot fork: source session file is empty or invalid
Error message
Cannot fork: source session file is empty or invalid: ${resolvedSourcePath} What it means
Guard in SessionManager.forkFrom: loadEntriesFromFile on the resolved source session file returned zero entries, so there is no history to fork. The source file is empty, unreadable, or its contents did not parse as session entries.
Solutions
- Confirm sourcePath points at an existing, non-empty session file with valid entries
- If the source is corrupt, restore from a backup session file
- Skip forking and create a new session instead
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/coding-agent/src/core/session-manager.ts:1590 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24).
Data as JSON: /api/errors/08b8a0af3b0c4daf.
Report an issue: GitHub.
Appendix: source
Thrown at packages/coding-agent/src/core/session-manager.ts:1590
/**
* Fork a session from another project directory into the current project.
* Creates a new session in the target cwd with the full history from the source session.
* @param sourcePath Path to the source session file
* @param targetCwd Target working directory (where the new session will be stored)
* @param sessionDir Optional session directory. If omitted, uses default for targetCwd.
*/
static forkFrom(
sourcePath: string,
targetCwd: string,
sessionDir?: string,
options?: NewSessionOptions,
): SessionManager {
const resolvedSourcePath = resolvePath(sourcePath);
const resolvedTargetCwd = resolvePath(targetCwd);
const sourceEntries = loadEntriesFromFile(resolvedSourcePath);
if (sourceEntries.length === 0) {
throw new Error(`Cannot fork: source session file is empty or invalid: ${resolvedSourcePath}`);
}
const sourceHeader = sourceEntries.find((e) => e.type === "session") as SessionHeader | undefined;
if (!sourceHeader) {
throw new Error(`Cannot fork: source session has no header: ${resolvedSourcePath}`);
}
const dir = sessionDir ? normalizePath(sessionDir) : getDefaultSessionDir(resolvedTargetCwd);
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
// Create new session file with new ID but forked content
if (options?.id !== undefined) {
assertValidSessionId(options.id);
}
const newSessionId = options?.id ?? createSessionId();
const timestamp = new Date().toISOString();View on GitHub (pinned to 4af9d21d3b)