{"record":{"id":"32321493100adb38","repo":"BigPizzaV3/CodexPlusPlus","slug":"empty-undo-token","errorCode":null,"errorMessage":"empty undo token","messagePattern":"empty undo token","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-data/src/storage.rs","lineNumber":882,"sourceCode":"        session_id: session_id.to_string(),\n        message,\n        undo_token: Some(token.to_string()),\n        backup_path: backup_path.map(|path| path.to_string_lossy().to_string()),\n    }\n}\n\nfn normalize_codex_thread_id(session_id: &str) -> String {\n    session_id\n        .strip_prefix(\"local:\")\n        .unwrap_or(session_id)\n        .to_string()\n}\n\nfn undo_backups(backup_store: &BackupStore, token: &str) -> anyhow::Result<Vec<Value>> {\n    let tokens =\n        serde_json::from_str::<Vec<String>>(token).unwrap_or_else(|_| vec![token.to_string()]);\n    if tokens.is_empty() {\n        anyhow::bail!(\"empty undo token\");\n    }\n    tokens\n        .into_iter()\n        .map(|token| backup_store.read_backup(&token))\n        .collect()\n}\n\nfn restore_backups(\n    backups: &[Value],\n    fallback_db_path: &Path,\n    allowed_db_paths: &[PathBuf],\n    codex_home: Option<&Path>,\n) -> anyhow::Result<()> {\n    for backup in backups {\n        let Some(tables) = backup[\"tables\"].as_object() else {\n            continue;\n        };\n        let source_db = backup_source_db(backup, fallback_db_path, allowed_db_paths)?;","sourceCodeStart":864,"sourceCodeEnd":900,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-data/src/storage.rs#L864-L900","documentation":"undo_backups parses the undo token argument as either a JSON array of token strings or a single token string; if the result is an empty list it bails because there is nothing to undo. The undo API requires at least one backup token to restore from.","triggerScenarios":"Calling undo with an empty string, a JSON \"[]\" literal, or an empty token array produced by a caller that collected zero undo tokens.","commonSituations":"UI/caller stored an empty undo history and still invoked undo; a double-undo consumed the last token and a stale token list ([]) was passed again; deserializing an empty clipboard/history entry as the token.","solutions":["Pass a non-empty token: a single token string or a JSON array like [\"token1\",\"token2\"].","Check that undo history is non-empty in the caller before invoking undo and disable the undo action otherwise.","If the token was lost, redo/recreate the operation; backups cannot be restored without a token.","Treat \"[]\" as a no-op in your own wrapper instead of forwarding it to undo."],"exampleFix":"// before\nlet token = history.last_undo_token(); // \"\" or \"[]\"\nstorage.undo(&token)?;\n// after\nmatch history.last_undo_token() {\n    Some(token) if !token.trim().is_empty() && token != \"[]\" => storage.undo(&token)?,\n    _ => return Ok(()), // nothing to undo\n}","handlingStrategy":"validation","validationCode":"fn has_undo_token(token: &str) -> bool {\n    let t = token.trim();\n    if t.is_empty() || t == \"[]\" { return false; }\n    serde_json::from_str::<Vec<String>>(t)\n        .map(|v| !v.is_empty())\n        .unwrap_or(true) // single token string\n}","typeGuard":"fn parse_undo_tokens(token: &str) -> Option<Vec<String>> {\n    if token.trim().is_empty() { return None; }\n    Some(serde_json::from_str::<Vec<String>>(token).unwrap_or_else(|_| vec![token.to_string()]))\n        .filter(|v| !v.is_empty())\n}","tryCatchPattern":"match storage.undo(&token) {\n    Ok(restored) => apply(restored),\n    Err(e) if e.to_string().contains(\"empty undo token\") => {\n        eprintln!(\"nothing to undo\"); // expected no-op, not a failure\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Disable the undo action in UI when the undo history is empty","Never forward an empty string or JSON \"[]\" to undo","Guard single-token values: pass the raw token string, not an empty array wrapper","Consume undo tokens atomically so a double-undo can't re-submit an exhausted list"],"tags":["validation","undo","argument"],"backgroundTag":"empty-required-field","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"}