{"record":{"id":"04f42aba1883c7b1","repo":"Hmbown/CodeWhale","slug":"sub-agent-transcript-message-is-missing-its-index","errorCode":null,"errorMessage":"sub-agent transcript message is missing its index","messagePattern":"sub-agent transcript message is missing its index","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":7610,"sourceCode":"            != Some(u64::from(SUBAGENT_TRANSCRIPT_ARTIFACT_SCHEMA_VERSION))\n        || header.get(\"agent_id\").and_then(Value::as_str) != Some(agent_id)\n    {\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> {","sourceCodeStart":7592,"sourceCodeEnd":7628,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tools/subagent/mod.rs#L7592-L7628","documentation":"A message record in the transcript artifact has no usable \"index\" field: it is missing, not a JSON u64, or too large for usize. The loader requires a dense integer index on every message record so ordering can be verified, so an unindexable record fails the whole load.","triggerScenarios":"Records written without the index field (external writer or older format), index serialized as a string or negative number, or manual edits that dropped the field.","commonSituations":"Hand-repaired artifacts; third-party code writing message lines; serialization changes that emit index as a different JSON type.","solutions":["Ensure every message record carries an unsigned integer \"index\" field.","Repair the offending line by adding the correct dense index, or regenerate the artifact.","Always write artifacts through the persister, which stamps index automatically."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"for (i, line) in raw.lines().enumerate().skip(1) {\n    let v: serde_json::Value = serde_json::from_str(line)?;\n    if v.get(\"index\").and_then(|x| x.as_u64()).is_none() {\n        // line {i} lacks a u64 index: repair before loading\n    }\n}","typeGuard":"fn record_has_u64_index(v: &serde_json::Value) -> bool {\n    v.get(\"index\").and_then(|x| x.as_u64()).is_some()\n}","tryCatchPattern":"match load_subagent_transcript_artifact(&state_root, agent_id) {\n    Err(e) if e.to_string().contains(\"missing its index\") => { /* add dense index to offending line */ }\n    r => r?,\n}","preventionTips":["Write message records only via the persister, which stamps index.","Keep index as a JSON integer, never a string.","Repair artifacts by regenerating, not by hand-editing."],"tags":["subagent","transcript","missing-field","index","rust"],"backgroundTag":"missing-required-argument","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}