earendil-works/pi · error · Error

Persisted session is missing a session file

Error message

Persisted session is missing a session file

What it means

Invariant failure in AgentSessionRuntime.fork: the session manager reports the session as persisted, but session.sessionFile is unset, so the fork cannot derive a new session file from the current one. Indicates inconsistent session-runtime state rather than user error.

Solutions

  1. Save the current session (let an assistant response complete) and retry the fork
  2. Restart the session runtime if state is reproducibly inconsistent
  3. Report a bug with session transcript details
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/coding-agent/src/core/agent-session-runtime.ts:293 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/e05c7be0811c2fc1. Report an issue: GitHub.

Appendix: source

Thrown at packages/coding-agent/src/core/agent-session-runtime.ts:293

		if (!selectedEntry) {
			throw new Error("Invalid entry ID for forking");
		}

		if (position === "at") {
			targetLeafId = selectedEntry.id;
		} else {
			if (selectedEntry.type !== "message" || selectedEntry.message.role !== "user") {
				throw new Error("Invalid entry ID for forking");
			}
			targetLeafId = selectedEntry.parentId;
			selectedText = extractUserMessageText(selectedEntry.message.content);
		}

		const previousSessionFile = this.session.sessionFile;
		if (this.session.sessionManager.isPersisted()) {
			const currentSessionFile = this.session.sessionFile;
			if (!currentSessionFile) {
				throw new Error("Persisted session is missing a session file");
			}
			const sessionDir = this.session.sessionManager.getSessionDir();
			if (!targetLeafId) {
				const sessionManager = SessionManager.create(this.cwd, sessionDir);
				sessionManager.newSession({ parentSession: currentSessionFile });
				await this.teardownCurrent("fork", sessionManager.getSessionFile());
				this.apply(
					await this.createRuntime({
						cwd: this.cwd,
						agentDir: this.services.agentDir,
						sessionManager,
						sessionStartEvent: { type: "session_start", reason: "fork", previousSessionFile },
					}),
				);
				await this.finishSessionReplacement(options?.withSession);
				return { cancelled: false, selectedText };
			}

View on GitHub (pinned to 4af9d21d3b)