Skip to content

Protect ai-chat nodes from Backspace deletion/merge (closes #1697) - #1731

Merged
mstomar125 merged 1 commit into
mainfrom
worktree-issue-1697-aichat-backspace-guard
Jul 24, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
worktree-issue-1697-aichat-backspace-guard

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Fixes a data-loss bug: pressing Backspace at the start of an ai-chat node deleted or merged it away exactly like a plain text node, silently discarding the entire conversation. An ai-chat's messages live in properties.messages (ADR-028), separate from .content, so combineNodes() — which only concatenates .content strings and deletes the current node — destroyed the whole conversation with no protection or confirmation.

The existing acceptsContentMerge flag only guards the previous (target) node from receiving a merge; nothing guarded a node from being deleted/merged away as the current node.

Change

Adds a new plugin flag deletableViaBackspace, mirroring acceptsContentMerge exactly:

  • types.ts — optional deletableViaBackspace?: boolean on PluginDefinition, default true (existing types unaffected).
  • plugin-registry.ts — deletableViaBackspace(nodeType) returning true for unknown/disabled/unspecified, false only when a registered+enabled plugin opts out.
  • core-plugins.ts — deletableViaBackspace: false on the ai-chat plugin. Also sets acceptsContentMerge: false (like code-block/quote-block) so a node below an ai-chat can't Backspace-merge its text into ai-chat's .content and consume itself — the symmetric guard surfaced in review.
  • base-node-viewer.svelte — both handleCombineWithPrevious and handleDeleteNode now check the flag against the current/event node's own type (nodeManager.nodes.get(eventNodeId).nodeType) right after the existence check, and no-op when it's false. (Previously the only type check was against the previous node.)

Acceptance criteria

  • Backspace at the start of an empty ai-chat node does not delete it
  • Backspace at the start of a non-empty ai-chat node does not merge/delete it
  • Other node types' Backspace behavior unchanged (default-true; full suite green)
  • Flag documented consistently with acceptsContentMerge (JSDoc in-code + nodespace-docs PR Phase 1.1: Enhanced ContentProcessor with Dual-Representation #70)
  • bun run test passes
  • Passes lint/format

Verification

  • New unit tests mirror the existing acceptsContentMerge registry block: plugin-registry.test.ts (+5 — false/true/default/unknown/disabled) and core-plugins.test.ts (+1 asserting the real ai-chat plugin sets the flag). All green.
  • Full frontend suite: 167 files, 4115 tests passing; svelte-check: 0 errors / 1769 files.
  • Docs: nodespace-docs PR Phase 1.1: Enhanced ContentProcessor with Dual-Representation #70 adds the flag to creating-node-types.md alongside acceptsContentMerge.
  • Independent adversarial review: CONFIRMED-GOOD. Verified the two guarded handlers are the only Backspace-at-start delete/merge paths (MergeNodesCommand → deleteNode/combineWithPrevious, no Cmd+Backspace or select-all bypass); nodeType is the correct field on the Map<string, Node>; default-true preserves all other types; and ai-chat reaches these handlers via node-row's fallback BaseNode branch (it has a viewer but no inline node component). The companion acceptsContentMerge: false was added per the review's secondary finding.

Closes #1697.

Backspace at the start of an ai-chat node deleted or merged it away like a
plain text node, silently discarding the conversation stored in
properties.messages (separate from .content).

Adds a deletableViaBackspace plugin flag (default true, mirroring
acceptsContentMerge). base-node-viewer's handleDeleteNode and
handleCombineWithPrevious now check it against the current/event node's own
type and no-op when false. ai-chat sets deletableViaBackspace: false, and
acceptsContentMerge: false so a node below it can't merge into its .content.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Independent adversarial review returned CONFIRMED-GOOD across all 6 scrutiny points: the two guarded handlers are the only Backspace-at-start delete/merge paths (MergeNodesCommand → deleteNode/combineWithPrevious; no Cmd+Backspace or select-all bypass — canExecute is false with a selection); nodeType is the correct field on Map<string, Node>; the guard no-ops safely because execute() already called preventDefault() (cursor stays at 0, command still returns handled); default-true leaves all other node types unchanged; and ai-chat reaches these handlers via node-row's fallback BaseNode branch (it has a viewer but no inline node component). The review's secondary finding — a node below ai-chat could merge its text into ai-chat's .content — is closed by the companion acceptsContentMerge: false. Full frontend suite 4115/4115, svelte-check 0 errors.

@mstomar125
mstomar125 merged commit c6b8405 into main Jul 24, 2026
@mstomar125
mstomar125 deleted the worktree-issue-1697-aichat-backspace-guard branch July 24, 2026 13:02
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.

Ai-chat nodes can be deleted via backspace, losing the entire conversation

1 participant