{"record":{"id":"d11aec37e3bd8ce3","repo":"Hmbown/CodeWhale","slug":"sub-agent-transcript-message-index-index-does-no","errorCode":null,"errorMessage":"sub-agent transcript message index {index} does not follow {}","messagePattern":"sub-agent transcript message index (.+?) does not follow (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":8583,"sourceCode":"    {\n        return Err(anyhow!(\n            \"sub-agent transcript artifact header does not match agent {agent_id}\"\n        ));\n    }\n\n    let mut messages = Vec::new();\n    for line in lines.filter(|line| !line.trim().is_empty()) {\n        let record: Value = serde_json::from_str(line)?;\n        if record.get(\"kind\").and_then(Value::as_str) != Some(\"message\") {\n            return Err(anyhow!(\"unknown sub-agent transcript artifact record\"));\n        }\n        let index = record\n            .get(\"index\")\n            .and_then(Value::as_u64)\n            .and_then(|value| usize::try_from(value).ok())\n            .ok_or_else(|| anyhow!(\"sub-agent transcript message is missing its index\"))?;\n        if index != messages.len() {\n            return Err(anyhow!(\n                \"sub-agent transcript message index {index} does not follow {}\",\n                messages.len()\n            ));\n        }\n        let message = serde_json::from_value::<Message>(\n            record\n                .get(\"message\")\n                .cloned()\n                .ok_or_else(|| anyhow!(\"sub-agent transcript record is missing its message\"))?,\n        )?;\n        messages.push(message);\n    }\n    Ok(messages)\n}\n\nfn remove_subagent_transcript_artifact(state_root: &Path, agent_id: &str) -> Result<bool> {\n    let state_root = normalize_subagent_workspace(state_root);\n    let path = checked_subagent_transcript_artifact_path(&state_root, agent_id)?;","sourceCodeStart":8565,"sourceCodeEnd":8601,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L8565-L8601","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (hand-edited transcript, record out of order)\n{\"index\":0,\"message\":{...}}\n{\"index\":2,\"message\":{...}}\n// after\n{\"index\":0,\"message\":{...}}\n{\"index\":1,\"message\":{...}}","handlingStrategy":"validation","validationCode":"// before reading, verify indices are contiguous\nlet indices: Vec<u64> = records.iter().filter_map(|r| r.get(\"index\").and_then(Value::as_u64)).collect();\nlet ok = indices.iter().enumerate().all(|(i, v)| *v == i as u64);\nif !ok { /* regenerate or repair the transcript before calling the API */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["subagent","transcript","index","corruption"],"backgroundTag":"index-out-of-range","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}