warpdotdev/warp · error

Failed to revert changes to {file_name}

Error message

Failed to revert changes to {file_name}

What it means

During revert of a file's agent edit, `diff.diff_view.update(ctx, |v, ctx| v.restore_diff_base(ctx))` fails. The underlying error is reported to Sentry with context 'Failed to restore diff base', and a toast 'Failed to revert changes to {file_name}' is shown (file_name falls back to "file" when unavailable). The code then still sets CodeDiffState::Reverted and marks the action reverted, so UI state and disk state can diverge.

Source

Thrown at app/src/ai/blocklist/inline_action/code_diff_view.rs:1056

            );
            return;
        }

        let window_id = ctx.window_id();
        for diff in &self.pending_diffs {
            if let Err(err) = diff
                .diff_view
                .update(ctx, |v, ctx| v.restore_diff_base(ctx))
            {
                report_error!(anyhow::anyhow!("{err}").context("Failed to restore diff base"));
                let file_name = diff
                    .diff_view
                    .as_ref(ctx)
                    .file_name()
                    .unwrap_or_else(|| "file".to_string());
                ToastStack::handle(ctx).update(ctx, |toast_stack, ctx| {
                    toast_stack.add_ephemeral_toast(
                        DismissibleToast::error(format!("Failed to revert changes to {file_name}")),
                        window_id,
                        ctx,
                    );
                });
            }
        }

        self.state = CodeDiffState::Reverted;
        self.mark_action_as_reverted(ctx);
        ctx.notify();
    }

    fn mark_action_as_reverted(&self, ctx: &mut ViewContext<Self>) {
        if let Some(conversation_id) = self.identifiers.client_conversation_id {
            let action_id = self.action_id.clone();
            BlocklistAIHistoryModel::handle(ctx).update(ctx, |history_model, ctx| {
                if let Some(conversation) = history_model.conversation_mut(&conversation_id) {
                    conversation.mark_action_as_reverted(action_id, ctx);

View on GitHub (pinned to e72fd7aacb)

Solutions

  1. Check whether the file still exists and is writable; reload it in the editor and retry the revert
  2. Re-run the diff to capture a fresh base, then revert again
  3. If the tooling cannot restore, revert manually (git checkout/restore the file) and mark the action reverted
  4. Read the wrapped {err} in Sentry ('Failed to restore diff base' context) for the filesystem-level cause

Example fix

// before: revert blindly
if let Err(err) = diff.diff_view.update(ctx, |v, ctx| v.restore_diff_base(ctx)) { /* toast */ }

// after: verify the file is present first
let path = diff.diff_view.as_ref(ctx).file_path();
if !path.as_ref().map(|p| p.is_file()).unwrap_or(false) {
    toast("File missing on disk; revert manually");
} else if let Err(err) = diff.diff_view.update(ctx, |v, ctx| v.restore_diff_base(ctx)) {
    toast(format!("Failed to revert changes to {file_name}"));
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Before reverting, confirm the file still exists and is writable.
let revert_ok = path
    .as_ref()
    .map(|p| p.is_file() && !p.metadata().map(|m| m.permissions().readonly()).unwrap_or(true))
    .unwrap_or(false);
anyhow::ensure!(revert_ok, "File missing or read-only; cannot revert");

Try / catch

if let Err(err) = diff.diff_view.update(ctx, |v, ctx| v.restore_diff_base(ctx)) {
    report_error!(anyhow::anyhow!("{err}").context("Failed to restore diff base"));
    ToastStack::handle(ctx).update(ctx, |toast_stack, ctx| {
        toast_stack.add_ephemeral_toast(
            DismissibleToast::error(format!("Failed to revert changes to {file_name}")),
            window_id,
            ctx,
        );
    });
}

Prevention

When it happens

Trigger: `restore_diff_base` returns Err because the target file changed or disappeared on disk since the diff base was captured, the write is blocked by permissions or a read-only filesystem, or the stored diff base snapshot is invalid/missing.

Common situations: File edited outside Warp (editor, CLI, formatter) between the agent edit and the revert; file deleted or moved; branch switch or checkout invalidating paths; long-lived diff sessions over stale bases.

Related errors


AI-assisted analysis of warpdotdev/warp@e72fd7aacb (2026-08-16). Data as JSON: /api/errors/12cca57a4d0ff80e. Report an issue: GitHub.