{"record":{"id":"0197b0d1b6674217","repo":"BigPizzaV3/CodexPlusPlus","slug":"unexpected-backup-file-path-path","errorCode":null,"errorMessage":"unexpected backup file path: {path}","messagePattern":"unexpected backup file path: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-data/src/storage.rs","lineNumber":1186,"sourceCode":"        .collect::<Vec<_>>();\n    if table == \"messages\" && keys.is_empty() {\n        row.get_key_value(\"session_id\")\n            .map(|(key, _)| vec![key])\n            .unwrap_or_default()\n    } else {\n        keys\n    }\n}\n\nfn detect_file_restore_conflicts(tables: &Map<String, Value>) -> anyhow::Result<()> {\n    let Some(files) = tables.get(\"__files\").and_then(Value::as_array) else {\n        return Ok(());\n    };\n    let allowed_paths = allowed_backup_file_paths(tables);\n    for file in files {\n        if let Some(path) = file.get(\"path\").and_then(Value::as_str) {\n            if !allowed_paths.contains(path) {\n                anyhow::bail!(\"unexpected backup file path: {path}\");\n            }\n            if Path::new(path).exists() {\n                anyhow::bail!(\"restore conflict: file already exists: {path}\");\n            }\n            if let Some(content) = file.get(\"content_b64\").and_then(Value::as_str) {\n                base64::Engine::decode(&base64::engine::general_purpose::STANDARD, content)?;\n            }\n        }\n    }\n    Ok(())\n}\n\nfn allowed_backup_file_paths(tables: &Map<String, Value>) -> HashSet<String> {\n    tables\n        .get(\"threads\")\n        .and_then(Value::as_array)\n        .into_iter()\n        .flatten()","sourceCodeStart":1168,"sourceCodeEnd":1204,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-data/src/storage.rs#L1168-L1204","documentation":"During backup restore, detect_file_restore_conflicts validates every entry in the backup's __files array against allowed_backup_file_paths, which is built solely from the rollout_path column of the threads rows in the same backup. If a file entry's path is not one of those rollout_path values, the restore is aborted before anything is written. This guards against restoring files to arbitrary filesystem locations from a tampered or hand-edited backup.","triggerScenarios":"Calling restore_backups with a backup whose __files array contains a path that does not exactly match any threads.rollout_path in the backup JSON — e.g. the backup was hand-edited, a rollout_path row was dropped from the threads table, or the path string differs in case/whitespace/absolute-vs-relative form.","commonSituations":"Manually merging or editing backup JSON files; restoring a backup produced by a different/older tool version that wrote file paths in a different format; cross-machine restores where rollout_path values were rewritten but the __files entries were not; a truncated threads array in a corrupted backup.","solutions":["Inspect the backup JSON and ensure every __files[].path matches a threads row's rollout_path exactly (string-equal, same separators, no trailing whitespace).","Re-export a fresh backup instead of hand-editing the JSON.","If rollout_path rows are legitimately absent, remove the orphaned __files entries from the backup.","If this is a trusted internal backup format change, update allowed_backup_file_paths/backup generation together so both sides agree."],"exampleFix":"// before: hand-edited backup where __files path diverges from threads.rollout_path\n{\"__files\":[{\"path\":\"/home/u/.codex/sessions/rollout-2026.jsonl\"}],\"threads\":[]}\n// after: regenerate the backup so __files derives from threads\n{\"__files\":[{\"path\":\"/home/u/.codex/sessions/rollout-2026.jsonl\"}],\"threads\":[{\"rollout_path\":\"/home/u/.codex/sessions/rollout-2026.jsonl\",...}]}\n","handlingStrategy":"validation","validationCode":"const paths: Set<string> = new Set(backup.threads.map(t => t.rollout_path).filter(p => p && p.trim() !== ''));\nif (backup.__files?.some(f => !paths.has(f.path))) throw new Error('backup contains file paths not covered by threads.rollout_path');","typeGuard":"function isAllowedFilePath(backup: Backup, path: string): boolean {\n  return backup.threads.some(t => t.rollout_path === path);\n}","tryCatchPattern":null,"preventionTips":["Never hand-edit backup JSON; regenerate backups with the export tool.","Verify backup integrity after export (every __files path appears in threads.rollout_path).","Keep backup export and restore code in the same version to avoid format drift."],"tags":["restore","backup","validation","path"],"backgroundTag":"invalid-argument-value","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}