{"record":{"id":"d1b583c50617d8c8","repo":"Hmbown/CodeWhale","slug":"session-file-missing-parseable-metadata-block","errorCode":null,"errorMessage":"session file missing parseable `metadata` block","messagePattern":"session file missing parseable `metadata` block","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/session_manager.rs","lineNumber":2653,"sourceCode":"        let mut file = fs::File::open(path)?;\n        let mut buf = Vec::with_capacity(PREFIX_BYTES);\n        file.by_ref()\n            .take(PREFIX_BYTES as u64)\n            .read_to_end(&mut buf)?;\n\n        if let Some(mut metadata) = extract_top_level_metadata(&buf) {\n            apply_legacy_title_recovery(&mut metadata, &buf);\n            return Ok(metadata);\n        }\n\n        // Metadata wasn't extractable from the prefix (truncated mid-block,\n        // unusual key ordering, etc.). Read the rest and try again with the\n        // full buffer before giving up.\n        let mut rest = Vec::new();\n        file.read_to_end(&mut rest)?;\n        buf.extend_from_slice(&rest);\n        let mut metadata = extract_top_level_metadata(&buf).ok_or_else(|| {\n            std::io::Error::new(\n                std::io::ErrorKind::InvalidData,\n                \"session file missing parseable `metadata` block\",\n            )\n        })?;\n        apply_legacy_title_recovery(&mut metadata, &buf);\n        Ok(metadata)\n    }\n\n    /// Delete a session and its recovery checkpoints, retiring its origin.\n    pub fn delete_session(&self, id: &str) -> std::io::Result<()> {\n        self.remove_session(id, SessionRemoval::Explicit)\n    }\n\n    fn remove_session(&self, id: &str, removal: SessionRemoval) -> std::io::Result<()> {\n        let path = self.validated_session_path(id)?;\n        // Older ordinary snapshots may use a name reserved by the checkpoint\n        // directory. Such a name must never address its shared legacy files.\n        let checkpoint = self.validated_checkpoint_path(id).ok();","sourceCodeStart":2635,"sourceCodeEnd":2671,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/session_manager.rs#L2635-L2671","documentation":"The session lister reads only the head of each session file and extracts the top-level `metadata` object; if extraction fails it reads the whole file and retries. If the full buffer still yields no parseable metadata block, it throws this InvalidData io::Error. This means the file exists but its metadata cannot be located or parsed at all.","triggerScenarios":"Listing session metadata for a file that is empty, truncated before the metadata object, not JSON, or whose top-level structure no longer contains a `metadata` key the extractor recognizes (e.g. written by a very old or very new format).","commonSituations":"Crash-corrupted session files, hand-edited files, foreign or placeholder files dropped into the checkpoints directory, or format drift across versions.","solutions":["Inspect the session file: confirm it is valid JSON containing a top-level `metadata` object; repair or remove the broken file.","Restore the file from backup, or delete it so the corrupted session stops failing the listing flow.","If the file is from a different format version, load it with the matching app version or migrate it to the current format."],"exampleFix":"// before\nlet meta = manager.read_session_metadata(path)?;\n// after\nlet meta = manager.read_session_metadata(path).map_err(|e| {\n    eprintln!(\"skipping unreadable session file {}: {e}\", path.display());\n    e\n})?; // or filter such files out before listing","handlingStrategy":"validation","validationCode":"fn file_has_metadata(path: &Path) -> bool {\n    std::fs::read_to_string(path).map(|s| {\n        serde_json::from_str::<serde_json::Value>(&s)\n            .ok()\n            .map(|v| v.get(\"metadata\").is_some())\n            .unwrap_or(false)\n    }).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match read_session_metadata(path) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => {\n        log::warn!(\"skipping session file without parseable metadata: {}\", path.display());\n        continue; // in a listing loop\n    }\n    other => other,\n}","preventionTips":["Skip-and-log unreadable files when listing many sessions.","Keep session files intact: no truncation, no manual edits.","Drop foreign/placeholder files out of the checkpoints directory."],"tags":["metadata","session-file","corrupt-file","json"],"backgroundTag":"json-parse-error","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"}