Skip to content

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

Closed

Description

@malibio

Overview

Pressing Backspace at the start of an ai-chat node (empty or non-empty) deletes or merges it away exactly like a plain text node, silently discarding the entire conversation (stored in properties.messages, separate from .content) with no protection or confirmation.

Problem Statement

Backspace-at-start handling lives in packages/desktop-app/src/lib/design/components/base-node-viewer.svelte:

  • handleDeleteNode (lines 862-900) — deletes the current node when empty
  • handleCombineWithPrevious (lines 810-860) — merges the current node's content into the previous node

Both ultimately call nodeManager.combineNodes() (packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts:566), which concatenates .content strings and deletes the current node. Neither function has any awareness of the current/event node's own type — the only existing type check is against the previous node, via pluginRegistry.acceptsContentMerge(previousNode.nodeType) (checked at lines 838 and 888), which guards structured node types (code-block, quote-block, horizontal-line, table — set in packages/desktop-app/src/lib/plugins/core-plugins.ts lines 329/372/451/491) from accepting a Backspace-merge from the node above. This is the documented mechanism per creating-node-types.md: "acceptsContentMerge — set to false for structured nodes... that must not accept a Backspace-merge from the node above." No equivalent flag exists for protecting a node from being deleted/merged away as the current node.

Ai-chat has no acceptsContentMerge entry (defaults to true per plugin-registry.ts:513) and no other guard, so it is deleted the same way a text node is — losing the full conversation.

No prior ADR or architecture doc documents a "protect this node type from self-deletion via Backspace" policy; creating-node-types.md and keyboard-and-navigation.md only document the existing merge-into-previous protection. This is new ground, not a reversal of any existing decision.

Proposed Solution

Add a new plugin-level flag, deletableViaBackspace, mirroring the existing acceptsContentMerge pattern:

  • Default true (matches acceptsContentMerge's default-true convention, so existing node types are unaffected without an explicit opt-out)
  • Set false on the ai-chat plugin definition (packages/desktop-app/src/lib/plugins/core-plugins.ts, ai-chat plugin, ~lines 612-636)
  • handleDeleteNode and handleCombineWithPrevious (base-node-viewer.svelte) must check this flag against the current/event node's own type (not just the previous node's type, which is all that's checked today) before proceeding with deletion or combination, and no-op (or otherwise safely decline) when the flag is false

Acceptance Criteria

  • Pressing Backspace at the start of an empty ai-chat node does not delete it
  • Pressing Backspace at the start of a non-empty ai-chat node does not merge/delete it
  • Other node types' existing Backspace-delete/merge behavior is unaffected (regression check via existing tests)
  • New deletableViaBackspace plugin flag is documented consistently with the existing acceptsContentMerge flag (mirror its usage pattern)
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • base-node-viewer.svelte: packages/desktop-app/src/lib/design/components/base-node-viewer.svelte — handleDeleteNode (862-900), handleCombineWithPrevious (810-860), existing acceptsContentMerge checks (838, 888)
  • reactive-node-service.svelte.ts: packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts:566 — combineNodes(), the eventual deletion/merge call
  • core-plugins.ts: packages/desktop-app/src/lib/plugins/core-plugins.ts — ai-chat plugin definition (~lines 612-636) to add the new flag to; existing acceptsContentMerge: false examples at lines 329, 372, 451, 491 (code-block, quote-block, horizontal-line, table) as the pattern to follow
  • plugin-registry.ts: packages/desktop-app/src/lib/plugins/plugin-registry.ts:513 — default-true fallback pattern for acceptsContentMerge, to mirror for deletableViaBackspace

Testing Requirements

Add coverage in base-node-viewer tests (or equivalent) asserting that Backspace on an ai-chat node (both empty and non-empty) is a no-op with respect to node deletion/merging, alongside existing coverage for acceptsContentMerge-protected types.

Related Issues

Activity

  1. added
    bug
    on Jul 19, 2026
  2. mstomar125 commented on Jul 24, 2026

    @mstomar125
    Contributor

    ✅ Completed — merged in PR #1731

    Backspace at the start of an ai-chat node can no longer delete or merge the node away, so the conversation in properties.messages is safe.

    Fix: a new plugin flag deletableViaBackspace (default true, mirroring acceptsContentMerge):

    • types.ts — optional field on PluginDefinition
    • plugin-registry.ts — deletableViaBackspace(nodeType) (true for unknown/disabled/unspecified)
    • base-node-viewer.svelte — both handleDeleteNode and handleCombineWithPrevious now check the flag against the current/event node's own type and no-op when false (previously only the previous node's type was checked)
    • core-plugins.ts — ai-chat sets deletableViaBackspace: false, plus acceptsContentMerge: false so a node below it can't Backspace-merge its text into ai-chat's .content and consume itself (the symmetric guard, like code-block/quote-block)

    Acceptance criteria — all met

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

    Verification

    • New unit tests mirror the existing acceptsContentMerge block: plugin-registry.test.ts (+5: false/true/default/unknown/disabled) and core-plugins.test.ts (+1 asserting the real ai-chat plugin). All green.
    • Full frontend suite: 167 files, 4115 tests passing; svelte-check: 0 errors / 1769 files.
    • Independent adversarial review: CONFIRMED-GOOD (6/6) — verified these are the only Backspace-at-start paths (no Cmd+Backspace / select-all bypass), correct nodeType field, safe no-op (preventDefault already fired), and that ai-chat reaches these handlers via node-row's fallback BaseNode branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfoundation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions