BigPizzaV3/CodexPlusPlus · error

undo task failed

Error message

undo task failed: {error}

What it means

This error wraps a JoinError from tokio::task::spawn_blocking in the launcher's `undo` method (apps/codex-plus-launcher/src/main.rs:674). It means the blocking task that performs the undo of a previous operation never produced a result — the task panicked, was cancelled, or the runtime is shutting down. The actual undo failure (database error, missing token) would surface as a different error; this one is specifically the join/await failure.

Solutions

  1. Inspect the inner JoinError: check if it `is_panic()` and log the panic payload to find the real bug in adapter.undo
  2. Make adapter.undo return Err instead of panicking on malformed undo tokens
  3. Avoid dropping/aborting the undo future mid-flight; keep it awaited to completion
  4. If this happens at shutdown, drain pending blocking tasks before exiting

Example fix

// before
.map_err(|error| anyhow::anyhow!("undo task failed: {error}"))
// after
.map_err(|error| match error.try_into_panic() {
    Ok(panic) => anyhow::anyhow!("undo task panicked: {:?}", panic.downcast_ref::<String>()),
    Err(_) => anyhow::anyhow!("undo task cancelled (runtime shutdown?)"),
})
Defensive patterns

Strategy: try-catch

Validate before calling

// check runtime is running and token is non-empty before calling
if undo_token.trim().is_empty() { return Err(anyhow::anyhow!("empty undo token")); }

Type guard

fn join_error_is_panic(err: &tokio::task::JoinError) -> bool { err.is_panic() }

Try / catch

match task::spawn_blocking(move || adapter.undo(&token)).await {
    Ok(Ok(result)) => result,
    Ok(Err(e)) => eprintln!("undo failed: {e}"),
    Err(join_err) if join_err.is_panic() => eprintln!("undo panicked: {:?}", join_err.into_panic()),
    Err(_) => eprintln!("undo cancelled at shutdown"),
}

Prevention

When it happens

Trigger: Calling `undo(undo_token)` when the spawned blocking closure panics (e.g. adapter.undo panics on a corrupted undo token), when the future is dropped/cancelled before completion, or during tokio runtime shutdown.

Common situations: App shutting down while an undo is in flight; a panic inside the storage adapter's undo logic (unwrapped Option on a malformed undo token); user cancels the operation and the task is aborted.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/4c110699260d68c8. Report an issue: GitHub.

Appendix: source

Thrown at apps/codex-plus-launcher/src/main.rs:674

        let db_paths = self.candidate_db_paths();
        let backup_store = codex_plus_data::BackupStore::new(self.backup_dir.clone());
        tokio::task::spawn_blocking(move || {
            codex_plus_data::delete_local_from_paths(
                db_paths,
                backup_store,
                &session,
                Some(&codex_plus_core::codex_sqlite::default_codex_home_dir()),
            )
        })
        .await
        .map_err(|error| anyhow::anyhow!("delete task failed: {error}"))
    }

    async fn undo(&self, undo_token: String) -> anyhow::Result<DeleteResult> {
        let adapter = self.storage_adapter();
        tokio::task::spawn_blocking(move || adapter.undo(&undo_token))
            .await
            .map_err(|error| anyhow::anyhow!("undo task failed: {error}"))
    }

    async fn export_markdown(&self, session: SessionRef) -> anyhow::Result<ExportResult> {
        let db_paths = self.candidate_db_paths();
        tokio::task::spawn_blocking(move || {
            codex_plus_data::export_markdown_from_paths(db_paths, &session)
        })
        .await
        .map_err(|error| anyhow::anyhow!("export markdown task failed: {error}"))
    }

    async fn thread_usage_history(&self, session: SessionRef) -> anyhow::Result<Value> {
        let adapter = self.storage_adapter();
        tokio::task::spawn_blocking(move || adapter.codex_thread_usage_history(&session))
            .await
            .map_err(|error| anyhow::anyhow!("thread usage history task failed: {error}"))
    }

View on GitHub (pinned to b1ed92e5e4)