Hmbown/CodeWhale · error · anyhow::Error

sub-agent transcript artifact is empty

Error message

sub-agent transcript artifact is empty

What it means

When loading a sub-agent transcript artifact (a JSON-lines file), the first line must be the transcript header. If the file contains no lines at all, the loader cannot even validate the header and throws this error.

Solutions

  1. Delete the empty artifact and let the sub-agent recreate its transcript (or restore from a backup)
  2. Check the writer/parent process logs for a crash before the header was flushed and re-run the agent
  3. Re-spawn the subagent session; the transcript is rebuilt
  4. If editing by hand, write a valid header line first: {"kind":"subagent_transcript_header","schema_version":<N>,"agent_id":"..."}

Example fix

// before
$ : > subagent-a1f3.transcript  # truncates -> loader error
// after
$ rm subagent-a1f3.transcript   # let the runtime recreate it with a valid header
Defensive patterns

Strategy: validation

Validate before calling

fn transcript_artifact_readable(path: &Path) -> Result<(), String> {
    let meta = std::fs::metadata(path).map_err(|e| e.to_string())?;
    if meta.len() == 0 { Err("transcript artifact is empty".into()) } else { Ok(()) }
}

Type guard

fn is_nonempty_file(path: &Path) -> bool {
    std::fs::metadata(path).map(|m| m.len() > 0).unwrap_or(false)
}

Try / catch

match load_transcript(state_root, agent_id) {
    Err(e) if e.to_string().contains("artifact is empty") => recreate_transcript(state_root, agent_id), // delete + respawn
    r => r,
}

Prevention

When it happens

Trigger: Reading a zero-byte transcript artifact file under the subagent state root — e.g. the file was created (touch/truncate) but the header was never written, a crashed writer, or an interrupted first write.

Common situations: Manual cleanup or log rotation that truncated the file; a crash between file creation and header flush; copying an empty placeholder file during state migration.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/d56276e5b18301a8. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tools/subagent/mod.rs:8559

        &subagent_transcript_artifact_relative_path(agent_id),
    )
}

/// Read the complete structured worker chat for the TUI Open action. The path
/// is derived from `agent_id` rather than accepted from handle JSON, so a
/// corrupted or model-supplied payload cannot redirect the reader outside the
/// manager state root.
pub fn load_subagent_transcript_artifact(
    state_root: &Path,
    agent_id: &str,
) -> Result<Vec<Message>> {
    let state_root = normalize_subagent_workspace(state_root);
    let path = checked_subagent_transcript_artifact_path(&state_root, agent_id)?;
    let raw = read_subagent_state_file(&state_root, &path)?;
    let mut lines = raw.lines();
    let header_line = lines
        .next()
        .ok_or_else(|| anyhow!("sub-agent transcript artifact is empty"))?;
    let header: Value = serde_json::from_str(header_line)?;
    if header.get("kind").and_then(Value::as_str) != Some("subagent_transcript_header")
        || header.get("schema_version").and_then(Value::as_u64)
            != Some(u64::from(SUBAGENT_TRANSCRIPT_ARTIFACT_SCHEMA_VERSION))
        || header.get("agent_id").and_then(Value::as_str) != Some(agent_id)
    {
        return Err(anyhow!(
            "sub-agent transcript artifact header does not match agent {agent_id}"
        ));
    }

    let mut messages = Vec::new();
    for line in lines.filter(|line| !line.trim().is_empty()) {
        let record: Value = serde_json::from_str(line)?;
        if record.get("kind").and_then(Value::as_str) != Some("message") {
            return Err(anyhow!("unknown sub-agent transcript artifact record"));
        }
        let index = record

View on GitHub (pinned to 73e0f67d83)