BigPizzaV3/CodexPlusPlus · error
empty undo token
Error message
empty undo token
What it means
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.
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.
Example fix
// before
let token = history.last_undo_token(); // "" or "[]"
storage.undo(&token)?;
// after
match history.last_undo_token() {
Some(token) if !token.trim().is_empty() && token != "[]" => storage.undo(&token)?,
_ => return Ok(()), // nothing to undo
} Defensive patterns
Strategy: validation
Validate before calling
fn has_undo_token(token: &str) -> bool {
let t = token.trim();
if t.is_empty() || t == "[]" { return false; }
serde_json::from_str::<Vec<String>>(t)
.map(|v| !v.is_empty())
.unwrap_or(true) // single token string
} Type guard
fn parse_undo_tokens(token: &str) -> Option<Vec<String>> {
if token.trim().is_empty() { return None; }
Some(serde_json::from_str::<Vec<String>>(token).unwrap_or_else(|_| vec![token.to_string()]))
.filter(|v| !v.is_empty())
} Try / catch
match storage.undo(&token) {
Ok(restored) => apply(restored),
Err(e) if e.to_string().contains("empty undo token") => {
eprintln!("nothing to undo"); // expected no-op, not a failure
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: Calling undo with an empty string, a JSON "[]" literal, or an empty token array produced by a caller that collected zero undo tokens.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- 会话 ID 为空
- 主题包必须是 32 MiB 以内的普通 ZIP 文件
- 请填写 API 的模型名称
- 官方混合 API 不应在 auth.json 中保存 OPENAI_API_KEY。请清理此供应商的…
- 请填写 API 的模型名称
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/32321493100adb38.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-data/src/storage.rs:882
session_id: session_id.to_string(),
message,
undo_token: Some(token.to_string()),
backup_path: backup_path.map(|path| path.to_string_lossy().to_string()),
}
}
fn normalize_codex_thread_id(session_id: &str) -> String {
session_id
.strip_prefix("local:")
.unwrap_or(session_id)
.to_string()
}
fn undo_backups(backup_store: &BackupStore, token: &str) -> anyhow::Result<Vec<Value>> {
let tokens =
serde_json::from_str::<Vec<String>>(token).unwrap_or_else(|_| vec![token.to_string()]);
if tokens.is_empty() {
anyhow::bail!("empty undo token");
}
tokens
.into_iter()
.map(|token| backup_store.read_backup(&token))
.collect()
}
fn restore_backups(
backups: &[Value],
fallback_db_path: &Path,
allowed_db_paths: &[PathBuf],
codex_home: Option<&Path>,
) -> anyhow::Result<()> {
for backup in backups {
let Some(tables) = backup["tables"].as_object() else {
continue;
};
let source_db = backup_source_db(backup, fallback_db_path, allowed_db_paths)?;View on GitHub (pinned to b1ed92e5e4)