earendil-works/pi · error · SessionError

invalid_fork_target

invalid_fork_target

Error message

Fork target is not a message entry: ${selectedEntryId}

What it means

Error "Fork target is not a message entry: ${selectedEntryId}" thrown in earendil-works/pi.

Source

Thrown at packages/session-backends/sqlite-node/src/sqlite/repo.ts:824

			if (sessionExists(db, id)) throw new SessionError("already_exists", `Session already exists: ${id}`);

			const entries: EntryRow[] = [];
			const lanes: { lane: string; leafId: string | null }[] = [];
			const branchTips: string[] = [];
			let branchForkTargetId: string | null = null;

			if (options.scope === "tree") {
				entries.push(...readEntryRows(db, source.id, { order: "oldestFirst" }));
				lanes.push(...readLanes(db, source.id).map((row) => ({ lane: row.lane, leafId: row.leaf_id })));
				branchTips.push(...readBranchTipIds(db, source.id));
			} else {
				const main = readLane(db, source.id, "main");
				if (!main) throw new SessionError("invalid_lane", "Lane not found: main");
				const selectedEntryId = options.entryId ?? main.leaf_id;
				if (selectedEntryId !== null) {
					const target = readEntryRow(db, source.id, selectedEntryId);
					if (!target || target.type !== "message") {
						throw new SessionError(
							"invalid_fork_target",
							`Fork target is not a message entry: ${selectedEntryId}`,
						);
					}
					const position = options.position ?? (options.entryId === undefined ? "at" : "before");
					branchForkTargetId = position === "at" ? target.id : target.parent_id;
				}
				lanes.push({ lane: "main", leafId: branchForkTargetId });
				if (branchForkTargetId !== null) {
					const cached = readCachedBranch(db, source.id, branchForkTargetId);
					if (!cached) {
						throw new SessionError(
							"invalid_fork_target",
							`Fork target is not on a cached branch: ${branchForkTargetId}`,
						);
					}
					const rows = queryCachedBranchRows(db, source.id, cached, { order: "oldestFirst" });
					entries.push(...rows.map(entryRowFromCached));

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Fork from a message entry; the selected entry is not a message.

When it happens

Trigger: Thrown at packages/session-backends/sqlite-node/src/sqlite/repo.ts:824 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/fe2381116d10f291. Report an issue: GitHub.