earendil-works/pi · error · SessionError
invalid_entry
invalid_entry
Error message
Invalid JSONL v4 session ${path}: line 1 is missing a header What it means
Error "Invalid JSONL v4 session ${path}: line 1 is missing a header" thrown in earendil-works/pi.
Source
Thrown at packages/agent/src/harness/session/jsonl/storage.ts:74
this.metadata = structuredClone(metadata);
}
static async create(
fs: JsonlSessionRepoFileSystem,
path: string,
header: JsonlV4Header,
): Promise<JsonlSessionStorage> {
fileResult(await fs.writeFile(path, encodeHeader(header)), `Failed to initialize session ${path}`);
const fileInfo = fileResult(await fs.fileInfo(path), `Failed to read session metadata ${path}`);
return new JsonlSessionStorage(fs, metadataFromHeader(header, path, fileInfo.mtimeMs));
}
static async load(fs: JsonlSessionRepoFileSystem, path: string): Promise<JsonlSessionStorage> {
const content = fileResult(await fs.readTextFile(path), `Failed to read session ${path}`);
const physicalLines = content.split("\n");
if (physicalLines.at(-1) === "") physicalLines.pop();
if (physicalLines.length === 0 || !physicalLines[0]) {
throw invalidFile(path, 1, new JsonlDecodeError("schema", "is missing a header"));
}
const headerResult = parseHeader(physicalLines[0]);
if (!headerResult.ok) throw invalidFile(path, 1, headerResult.error);
const fileInfo = fileResult(await fs.fileInfo(path), `Failed to read session metadata ${path}`);
const storage = new JsonlSessionStorage(fs, metadataFromHeader(headerResult.value, path, fileInfo.mtimeMs));
for (let index = 1; index < physicalLines.length; index++) {
const line = physicalLines[index]!;
const mutationResult = parseMutation(line);
if (!mutationResult.ok) {
const isTornTail = index === physicalLines.length - 1 && mutationResult.error.kind === "syntax";
if (isTornTail) {
// Drop the unacknowledged partial append by atomically publishing the valid prefix.
const validPrefix = `${physicalLines.slice(0, index).join("\n")}\n`;
await publishFileAtomically(fs, path, async (tempPath) => {
fileResult(await fs.writeFile(tempPath, validPrefix), `Failed to stage torn-tail repair ${path}`);
});
return storage;
}View on GitHub (pinned to 4af9d21d3b)
Solutions
- The session file is missing its header on line 1; the file is corrupt or truncated.
When it happens
Trigger: Thrown at packages/agent/src/harness/session/jsonl/storage.ts:74 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24).
Data as JSON: /api/errors/dd66438fbca6b40c.
Report an issue: GitHub.