Hmbown/CodeWhale · error · anyhow::Error
sub-agent transcript message index
Error message
sub-agent transcript message index {index} does not follow {} What it means
When reconstructing a sub-agent's transcript from its persisted JSONL artifact, each record must carry an `index` field that equals the running message count, proving the transcript is contiguous and gap-free. The parser reads the record, extracts the u64 index, and compares it to `messages.len()`. If they differ, the transcript has a gap, duplicate, or out-of-order entry, and the library refuses to load a potentially corrupt or truncated history.
Solutions
- Inspect the transcript JSONL file and remove or fix the out-of-order/duplicate record so indices are contiguous from 0.
- Delete the corrupt transcript/state artifact so the sub-agent session regenerates it from scratch.
- Ensure only one process writes the transcript at a time (avoid concurrent sub-agent runs sharing a state root).
- Check for version mismatch between the writer that produced the transcript and this reader; regenerate with the current version.
Example fix
// before (hand-edited transcript, record out of order)
{"index":0,"message":{...}}
{"index":2,"message":{...}}
// after
{"index":0,"message":{...}}
{"index":1,"message":{...}} Defensive patterns
Strategy: validation
Validate before calling
// before reading, verify indices are contiguous
let indices: Vec<u64> = records.iter().filter_map(|r| r.get("index").and_then(Value::as_u64)).collect();
let ok = indices.iter().enumerate().all(|(i, v)| *v == i as u64);
if !ok { /* regenerate or repair the transcript before calling the API */ } Prevention
- Never hand-edit transcript JSONL files; regenerate sessions instead.
- Ensure single-writer access to each transcript file.
- Validate indices after any external tooling touches the transcript.
When it happens
Trigger: Loading a sub-agent transcript where a record's `index` does not equal the number of messages parsed so far — e.g. an index of 5 when only 4 messages have been read, or an index repeated after a successful parse.
Common situations: A transcript file was manually edited or partially copied; a crash mid-write left a missing record; two writers appended to the same transcript concurrently; the writer version and reader version disagree on numbering.
Related errors
- sub-agent transcript artifact must have a parent directory
- sub-agent transcript record is missing its message
- agent action=claim widens an enforced write scope, and the…
- Agent has no continuable checkpoint to resume from…
- Agent not found
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/d11aec37e3bd8ce3.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/tools/subagent/mod.rs:8583
{
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
.get("index")
.and_then(Value::as_u64)
.and_then(|value| usize::try_from(value).ok())
.ok_or_else(|| anyhow!("sub-agent transcript message is missing its index"))?;
if index != messages.len() {
return Err(anyhow!(
"sub-agent transcript message index {index} does not follow {}",
messages.len()
));
}
let message = serde_json::from_value::<Message>(
record
.get("message")
.cloned()
.ok_or_else(|| anyhow!("sub-agent transcript record is missing its message"))?,
)?;
messages.push(message);
}
Ok(messages)
}
fn remove_subagent_transcript_artifact(state_root: &Path, agent_id: &str) -> Result<bool> {
let state_root = normalize_subagent_workspace(state_root);
let path = checked_subagent_transcript_artifact_path(&state_root, agent_id)?;View on GitHub (pinned to 73e0f67d83)