tinyhumansai/openhuman · error · Error

empty transcript

Error message

empty transcript

What it means

readTranscript() in scripts/debug/agent-prepare-context-audit.mjs reads a session .jsonl transcript, splits on newlines, filters blank lines, and throws 'empty transcript' when zero lines remain. Session transcripts are written by the core as NDJSON (first line carries _meta, subsequent lines are messages); a file with no content at all means the core created the file but never flushed a line — or the audit is pointing at a file it should not be reading.

Source

Thrown at scripts/debug/agent-prepare-context-audit.mjs:319

      entries.map(async (entry) => {
        const full = path.join(current, entry.name);
        if (entry.isDirectory()) return walk(full);
        if (entry.isFile() && entry.name.endsWith(".jsonl")) out.push(full);
      }),
    );
  }
  await walk(dir);
  return out;
}

function num(value) {
  return Number.isFinite(Number(value)) ? Number(value) : 0;
}

async function readTranscript(file) {
  const data = await readFile(file, "utf8");
  const lines = data.split(/\r?\n/).filter((l) => l.trim());
  if (lines.length === 0) throw new Error("empty transcript");
  const meta = JSON.parse(lines[0])._meta || {};
  const messages = [];
  for (const line of lines.slice(1)) {
    try {
      const m = JSON.parse(line);
      if (typeof m.role === "string") messages.push(m);
    } catch {
      // skip malformed line
    }
  }
  return {
    file,
    agent: String(meta.agent || "(unknown)"),
    threadId: meta.thread_id || null,
    isSubagent: path.basename(file).includes("__"),
    input: num(meta.input_tokens),
    output: num(meta.output_tokens),
    cached: num(meta.cached_input_tokens),

View on GitHub (pinned to a221052e0d)

Solutions

  1. Re-run the audit — if the empty file was a crash artifact of a one-off failed turn, the fresh threads will be well-formed
  2. Inspect the empty file's path from the error to identify which thread died, and delete the orphaned zero-byte file
  3. Verify --workspace points at the workspace the audited core actually writes transcripts into
  4. If the core itself is crashing mid-turn, diagnose that first (its stderr / --verbose) — the empty transcript is a symptom, not the cause

Example fix

// before — the audit's walkJsonl sweeps every *.jsonl, including orphans
Error: empty transcript

// after — remove the orphaned file so the walk skips it
$ find ~/.openhuman/users/<id>/workspace -name '*.jsonl' -size 0 -delete
$ node scripts/debug/agent-prepare-context-audit.mjs
Defensive patterns

Strategy: validation

Validate before calling

import { statSync } from "node:fs";
function isReadableTranscript(file) {
  const st = statSync(file);
  return st.size > 0; // zero-byte NDJSON can never carry the _meta line
}
const files = (await walkJsonl(dir)).filter(isReadableTranscript);

Type guard

async function isWellFormedTranscript(file) {
  const data = await readFile(file, "utf8");
  const lines = data.split(/\r?\n/).filter((l) => l.trim());
  if (lines.length === 0) return false;
  try { JSON.parse(lines[0]); return true; } catch { return false; }
}

Try / catch

for (const f of transcriptFiles) {
  try {
    results.push(await readTranscript(f));
  } catch (e) {
    if (/^empty transcript$/.test(e.message)) { console.warn(`skipping orphaned empty transcript ${f}`); continue; }
    throw e;
  }
}

Prevention

When it happens

Trigger: The transcript walk (walkJsonl over the workspace's session directories) finds a .jsonl that is zero bytes or whitespace-only — typically a thread whose first turn crashed before the meta line was written, or a file created by a core that was killed mid-write. Reading the very-fresh transcript of a turn that hasn't committed its first line yet can also race this.

Common situations: Auditing a workspace that contains aborted/crashed prior sessions; a spawned core dying during the audited turn (its transcript stays empty) and the audit then sweeping it up; workspace pointed at the wrong user dir so unrelated stale files are scanned.

Related errors


AI-assisted analysis of tinyhumansai/openhuman@a221052e0d (2026-08-16). Data as JSON: /api/errors/ba2b3ddcc018b8aa. Report an issue: GitHub.