earendil-works/pi · error
Session file is not a valid
Error message
Session file is not a valid ${APP_NAME} session: ${explicitPath} What it means
Sanity guard when adopting an existing file as a session: the file at explicitPath exists and is non-empty but did not parse as a valid pi session (entries could not be loaded). The manager refuses to overwrite it and fails without modifying the file.
Solutions
- Verify the path points at a real session file produced by this app, not an arbitrary jsonl
- If the file is a stale/corrupt session, back it up and remove it before retrying
- To start fresh, point setSessionFile at a non-existent or empty path so a new header is initialized
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/coding-agent/src/core/session-manager.ts:905 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/d9f617d8bff33f28.
Report an issue: GitHub.
Appendix: source
Thrown at packages/coding-agent/src/core/session-manager.ts:905
}
}
/** Switch to a different session file (used for resume and branching) */
setSessionFile(sessionFile: string): void {
this._setSessionFile(sessionFile);
}
private _setSessionFile(sessionFile: string, preloadedFileEntries?: FileEntry[]): void {
this.sessionFile = resolvePath(sessionFile);
if (existsSync(this.sessionFile)) {
this.fileEntries = preloadedFileEntries ?? loadEntriesFromFile(this.sessionFile);
// If file was empty, initialize it with a valid session header. If it was
// non-empty but did not parse as a pi session, fail without modifying it.
if (this.fileEntries.length === 0) {
const explicitPath = this.sessionFile;
if (statSync(explicitPath).size > 0) {
throw new Error(`Session file is not a valid ${APP_NAME} session: ${explicitPath}`);
}
this.newSession();
this.sessionFile = explicitPath;
this._rewriteFile();
this.flushed = true;
return;
}
const header = this.fileEntries.find((e) => e.type === "session") as SessionHeader | undefined;
this.sessionId = header?.id ?? createSessionId();
if (migrateToCurrentVersion(this.fileEntries)) {
this._rewriteFile();
}
this._buildIndex();
this.flushed = true;
} else {View on GitHub (pinned to 4af9d21d3b)