earendil-works/pi · error
Cannot fork: source session has no header
Error message
Cannot fork: source session has no header: ${resolvedSourcePath} What it means
Guard in SessionManager.forkFrom: the source session file has entries but no header entry, so fork metadata (id, timestamps, model info) cannot be carried over. The file was likely hand-edited or truncated so its header line was lost.
Solutions
- Restore or re-add a valid session header line at the top of the source file
- Fork from a session file written normally by the app
- If the header is unrecoverable, recreate the session and fork from that
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/coding-agent/src/core/session-manager.ts:1595 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/e216e68029103117.
Report an issue: GitHub.
Appendix: source
Thrown at packages/coding-agent/src/core/session-manager.ts:1595
* @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();
const fileTimestamp = timestamp.replace(/[:.]/g, "-");
const newSessionFile = join(dir, `${fileTimestamp}_${newSessionId}.jsonl`);
// Write new header pointing to source as parent, with updated cwd
const newHeader: SessionHeader = {View on GitHub (pinned to 4af9d21d3b)