{"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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":7612,"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":7594,"sourceCodeEnd":7630,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tools/subagent/mod.rs#L7594-L7630","documentation":"Each message record's index must equal the number of messages already read (dense 0-based sequence). This error fires when a record's index skips ahead, repeats, or is out of order — the loader refuses sequences with gaps or duplicates because they can hide dropped or duplicated messages.","triggerScenarios":"Lines reordered by an external process; a duplicated record pasted in; a record deleted manually leaving a gap; another writer numbering from 1 instead of 0.","commonSituations":"Manual artifact surgery; concurrent appends by two processes; migration scripts that renumber incorrectly.","solutions":["Repair the artifact so indexes run densely 0..n with no gaps or repeats.","Regenerate the transcript by re-running the sub-agent when manual renumbering is risky.","Never append to an artifact from more than one process; only the owning persister may write."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify dense 0-based ordering before loading:\nfor (expected, line) in raw.lines().skip(1).filter(|l| !l.trim().is_empty()).enumerate() {\n    let v: serde_json::Value = serde_json::from_str(line)?;\n    if v[\"index\"].as_u64() != Some(expected as u64) { /* gap/ordering issue at {expected} */ }\n}","typeGuard":"fn indexes_are_dense(lines: impl Iterator<Item = String>) -> bool {\n    lines.enumerate().all(|(i, l)| {\n        serde_json::from_str::<serde_json::Value>(&l)\n            .map(|v| v[\"index\"].as_u64() == Some(i as u64))\n            .unwrap_or(false)\n    })\n}","tryCatchPattern":"match load_subagent_transcript_artifact(&state_root, agent_id) {\n    Err(e) if e.to_string().contains(\"does not follow\") => { /* renumber 0..n or regenerate */ }\n    r => r?,\n}","preventionTips":["Single-writer discipline: never append from two processes.","When editing artifacts, renumber the full sequence densely.","Treat any gap as possible data loss — investigate before repairing."],"tags":["subagent","transcript","sequence","index","rust"],"backgroundTag":"out-of-order-sequence","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}