Skip to content

Hold agent deletes for an explicit user yes (closes #3096) - #3147

Merged
malibio merged 2 commits into
mainfrom
issue-3096-confirm-agent-delete
Sep 27, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3096-confirm-agent-delete

Conversation

@malibio

@malibio malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Closes #3096.

What changes

delete_node no longer deletes. GraphToolExecutor::exec_delete_node resolves the target and returns a held result: title, type, version, and descendant count (from collect_subtree_ids, the same set a delete removes). A missing node is an error, as before.

The turn ends with a confirmation. run_turn now applies confirm_held_deletions alongside the existing duplicate-entity backstop. When the turn held any deletes, the reply is replaced with a one-paragraph question naming every target and the total nested count, plus the Yes, delete / No, keep options. The frontend already renders these as chips through the route_clarify plumbing. The held targets travel on ClarifyPrompt.pending_deletions and are persisted on that assistant message as pendingDeletions. If the model ended the turn with its own route_clarify, that question stands and the held deletes lapse.

The daemon answers the reply, not the model. At the start of run_ai_chat_turn, if the user's message directly follows a confirmation:

  • Unqualified yes (the option label, "yes", "delete them", …): runs execute_confirmed on exactly the confirmed ids. It first checks every target: a version or subtree size different from what the user was shown aborts the whole delete before anything is removed. Each delete then runs under the confirmed version (OCC). The result is recorded as completed delete_node writes.
  • Unqualified no: "OK — nothing was deleted."
  • Anything else ("yes, but keep its notes"): an ordinary model turn. The held deletes lapse, and a new delete_node is held again.

Held results are excluded from completed writes (landed_write), so the cross-turn duplicate guard never refuses the real delete.

The local agent's SINGLE DELETE imperative no longer tells the model to confirm on its own, since that would ask the user twice. The SKILL.md phrasing for external agents is unchanged.

Acceptance criteria

  • No agent turn can remove user data without an explicit confirmation naming what will be removed. The tool itself cannot delete; only the daemon's yes-path can.
  • The confirmation lists the targets and the descendant count
  • A "no" (or any non-affirmative reply) deletes nothing
  • Confirmed ids are executed exactly; a version change (or a node added under a target) between confirm and execute aborts
  • Local agent covered; the external-agent path (nodespace node delete via SKILL.md) was assessed and filed as External-agent deletes run without NodeSpace-side confirmation (CLI node delete path) #3142

Not in scope

Tests

  • deletion_confirmation: reply classification, question text, dedupe; real-store preview, exact execution, version-drift abort, added-child abort, nested-target handling
  • agent_loop: a held delete ends the turn with the confirmation (overriding a false "I deleted it"); a model clarification supersedes a held delete
  • tools: delete_node through GraphToolExecutor holds and leaves the node in place
  • daemon: yes deletes and records the write; no deletes nothing; any other reply goes to the model and deletes nothing; only the message right after the confirmation can answer it; pendingDeletions persist

🤖 Generated with Claude Code

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3147 (Hold agent deletes for an explicit user yes)

Review Type: Initial Review

Summary

This is a sound design. The safety property comes from the structure of the code, not from prompting. GraphToolExecutor::exec_delete_node has no delete call left in it (packages/agent/src/local_agent/tools.rs:3996-4029), so no model output can remove a node. The only hard-delete path is the daemon's yes branch, which deletes the persisted ids under the confirmed version (OCC). Every failure mode I traced ends with nothing deleted: a turn error, a cancel, a model route_clarify, an "Other" reply, or two user messages in a row. landed_write is threaded through every earlier !is_error && is_write_tool site (backstop, suppressed_response_replacement, completed_writes_from), and no other agent tool hard-deletes nodes. The turn lifecycle is correct: end_turn runs, append_assistant_message sets idle atomically, the idle-gate guard is dropped by RAII, and the failed-append path resets status. The comments explain why, contain no issue numbers, and there is no compat code or lint suppression. The remaining findings are about accuracy and polish, not safety.

Requirements Check

  • ✅ No agent turn removes data without an explicit confirmation naming it. The tool cannot delete. Only pending_deletion_answer → execute_confirmed can, and only for the message that directly follows the confirmation.
  • ✅ Confirmation lists targets and descendant count. confirmation_question covers this. The count is overstated when targets overlap (see finding 1).
  • ✅ "No" or any non-affirmative reply deletes nothing. classify_reply matches the whole message. Other falls through to a normal model turn, where a new delete is held again.
  • ✅ Confirmed ids executed exactly; version drift aborts. Every target is pre-checked (version and subtree size) before anything is deleted, and each delete then runs with delete_node(id, confirmed_version).
  • ✅ Local agent covered; external SKILL.md path assessed and filed (External-agent deletes run without NodeSpace-side confirmation (CLI node delete path) #3142).

Code Review Findings

🟡 Important

1. Overlapping targets double-count the cascade, and a cascaded target is reported as "Already gone"
📁 packages/agent/src/local_agent/deletion_confirmation.rs:169-193, 333-336, 369-377
If the model holds a parent and also one of its descendants (a plausible result of "delete the plan and its steps"), confirmation_question adds up each target's descendant_count independently. With Plan (2 descendants) plus Step (1 descendant), the question says "This also removes 3 items nested under them", but only 1 node beyond the two targets is actually removed. After the yes, Step is removed by Plan's cascade and lands in already_gone, so the reply says Already gone: "Step" (task). That reads as if it had disappeared before the user answered, when this delete removed it as confirmed.
The error goes in the safe direction (it overstates), so this doesn't block the merge. But the acceptance criterion is that the confirmation names what will be removed, and the numbers the user is shown should be correct.
Recommendation: Collapse targets that fall inside another held target's subtree before building the question. That needs collect_subtree_ids at preview time; the result could be carried on AiChatPendingDeletion. Alternatively, compute nested_total from the union of subtree ids. Then word the cascaded case as "removed along with X" rather than "Already gone". Add a test for the question text in the overlapping case; a_target_nested_under_another_is_reported_as_already_gone currently checks only the counts.
Principle: correctness of user-facing state. A confirmation dialog is a contract.

🟢 Suggestions

2. The confirmation replaces the report of other writes that landed in the same turn
📁 packages/agent/src/local_agent/agent_loop.rs (confirm_held_deletions)
If one turn both lands a write (for example update_node or create_node) and holds a delete, the visible reply becomes only the delete question. The landed write is still recorded in completed_writes, so history stays accurate, but the user is never told about it in chat. duplicate_entity_backstop handles this by listing what the turn already did (done). Consider giving the confirmation the same short prefix (for example Updated X. Delete "Y" (task)? …). The prefix must stay in the first \n\n paragraph, because chat-message.svelte renders only content.split('\n\n')[0] above the chips. The skipped backstop (the if !confirm_held_deletions branch) is the same trade-off. That choice is fine; it just deserves a line in the doc comment.
Principle: least surprise, and consistency with the backstop's existing pattern.

3. No end-to-end test from a held turn to the confirmed delete
📁 packages/daemon/src/services/local_agent_service.rs (tests around chat_answering_a_delete_confirmation)
The daemon tests build the confirmation message by hand from preview_deletion/confirmation_question. They never check that a real turn's result.clarify.pending_deletions goes through append_assistant_message → load_chat_messages → pending_deletion_answer. pending_deletions_persist_on_the_confirmation_message covers the append step only. A single StubEngine test (tool call delete_node then text, followed by a user "yes" and a second maybe_handle_ai_chat_node) would pin the whole seam.
Principle: test the integration seam, not only the units on each side.

4. The unreachable Other arm in answer_deletion_confirmation
📁 packages/daemon/src/services/local_agent_service.rs (ConfirmationReply::Decline | ConfirmationReply::Other =>)
pending_deletion_answer never returns Other, so this arm is dead and hides the invariant. The fail-safe direction (treat it as a decline) is correct. Consider having pending_deletion_answer return a two-state value, so the type rules out the impossible case. Optional.
Principle: make illegal states unrepresentable.

5. The model in an "Other" turn sees titles but not ids
For "yes, but keep its notes", the next model turn sees only the confirmation text, which has titles and no ids. So it has to re-resolve the targets by searching, and search is exactly the step that can pick the wrong record. The next delete is still held, so this is not a safety problem, but carrying the held ids into the rendered history (for example as a terse fact line) could make the follow-up more reliable. Worth measuring before adding it.

6. Pro access gate: forged pendingDeletions
📁 packages/daemon/src/services/local_agent_service.rs (pending_deletion_answer)
The daemon trusts pendingDeletions persisted on the ai-chat node. Locally this adds nothing, because any client that can write that node can already delete nodes directly. The daemon's delete still goes through NodeService::delete_node, so subtree_access_gate still applies. Just confirm that in a synced Pro setup the actor the gate checks on this path is the chat's user, not an elevated daemon identity. No change is needed for Community.

Nitpicks

  • Nit: packages/daemon/src/services/local_agent_service.rs (~4828): a stray trailing comma, …, Vec::new(), None,), in an otherwise unchanged test line.
  • Nit: deletion_confirmation.rs:231-267: a comment saying the reply lists are intentionally conservative, and that adding to CONFIRM widens what counts as a yes, would help whoever edits them next.
  • Nit: Existing installs keep the old seeded "Confirm each deletion before proceeding" guidance, because seeding skips by type. They will ask twice until the database is reset. That is expected under the reset-the-database policy; mentioning it for anyone testing on an existing database.

Recommendation

APPROVE: the safety property holds by construction and all five acceptance criteria are met. Finding 1 is worth fixing in this PR or a quick follow-up so the numbers in the confirmation are exact. The rest are optional.

🤖 Generated with Claude Code

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

Address-review summary (55552c8)

✅ Addressed

  • 🟡 Set up Tauri + Svelte project structure #1 Overlapping targets. Each held result now carries the target's ancestor_ids. held_deletions leaves out any target nested under another held target: the outer cascade removes it, and its subtree is already in the outer count. The confirmation count is now exact, and the misleading "Already gone" can no longer appear for this case. Tests: a_target_nested_under_another_held_target_is_left_out and ancestor_ids_walk_up_to_the_root_nearest_first (real store).
  • 🟢 Create design system foundation #2 Other writes hidden. done_this_turn_note is extracted from the duplicate-entity backstop and appended to the confirmation's first paragraph. Test: a_confirmation_names_the_writes_its_turn_completed.
  • 🟢 Desktop shell with resizable panels #3 No end-to-end test. a_model_delete_waits_for_the_users_yes_across_turns: a real turn holds the model's delete_node and persists the question and pendingDeletions with no completed write. The next turn's "Yes, delete" then deletes the node.
  • 🟢 Enhanced BaseNode with Hierarchical Circle Indicators + TextNode Implementation #4 Unreachable arm. The daemon now uses a two-state DeletionAnswer (Confirmed/Declined).

⏭️ Skipped

  • Basic storage integration #5 Held ids after a non-answer. This is a prompt/history change, and every agent-prompt change here has to be measured first. It is also not a safety issue: any new delete is held again. Worth revisiting if the live eval shows a wrong-record second attempt.
  • Tauri desktop app launches successfully #6 Forged pendingDeletions under sync. On Community this adds no new capability. The actor-identity check belongs with the Pro/sync access work.
  • Nits. The trailing comma is rustfmt output. Existing installs keeping the stale seeded guidance is handled by resetting the database, per project policy.

quality:fix is clean. The Rust suites (agent, daemon, core, types) pass: 3450/3450. The push check passed.

Re-review: not needed. The changes are small, targeted and covered by the new tests. Merging is the next step, and it is the user's call.

malibio and others added 2 commits September 27, 2026 16:50
The local agent's delete_node no longer deletes. It resolves the target and
returns what would go (title, type, version, descendant count), and the turn
ends with a Yes/No confirmation naming every held target and the nested
nodes the cascade removes. The held records ride on that confirmation
message (pendingDeletions), so only a reply to it can confirm them.

The daemon answers the reply without the model: an unqualified yes deletes
exactly the confirmed ids, after checking each still has the version and
subtree size the user was shown (any drift aborts the whole delete), and each
delete runs under the confirmed version. An unqualified no deletes nothing.
Any other reply is an ordinary turn and the held deletes lapse.

Held deletes are not recorded as completed writes. The SINGLE DELETE rule no
longer tells the model to confirm on its own. The external-agent CLI path is
filed separately as #3142.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- A held target nested under another held target is left out of the
  confirmation: the outer cascade removes it and its subtree is already in
  the outer count. Held results carry the target's ancestor ids for this.
- The confirmation names writes its turn completed, since it replaces the
  model's reply (shared with the duplicate-entity backstop).
- The daemon's answer is two-state; the unreachable "other" arm is gone.
- End-to-end daemon test: a real turn holds the model's delete, persists the
  confirmation, and only the next turn's yes deletes.

Skipped: surfacing held ids to the model after a non-answer (prompt change,
unmeasured; any new delete is held again anyway) and actor checks for forged
pendingDeletions under sync (no new capability on Community).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3096-confirm-agent-delete branch from 55552c8 to 97d24af Compare September 27, 2026 14:57
@malibio
malibio merged commit 8b3cdc1 into main Sep 27, 2026
@malibio
malibio deleted the issue-3096-confirm-agent-delete branch September 27, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent deletes run without user confirmation: require an explicit yes before delete_node removes anything

1 participant