Skip to content

Last-edge protection ignores required in-direction relationships, so deleting the final inbound edge leaves the target incomplete #2942

Closed

Description

@malibio

Overview

Found while fixing core#2921 (PR #2935). The guard that stops the last edge of a required relationship from being deleted only protects out declarations. A required in declaration has no protection, so deleting the last inbound edge silently leaves the target incomplete.

Problem Statement

remove_relationship_in_tx (packages/core/src/services/node_service/relationship.rs:1142, guard at ~1170) and delete_relationship (relationship.rs:1331, guard at ~1375) resolve the source node's relationships. They apply last-edge protection only when the declaration is required: true && direction == Out. The Out filter is correct for that lookup: counting a source's outgoing edges under an in name would count the wrong edge set.

Nothing checks the target, though. With adr declaring superseded_by as a required in relationship (reverseName supersedes), deleting the only new --supersedes--> old edge succeeds. After that, check_node_completeness("old") reports superseded_by missing. The write path let through the exact state that required exists to prevent, and the out side would have rejected the same deletion.

Proposed Solution

When deleting an edge of forward type T from source to target, also resolve the target's relationships (extends-chain aware, as the source side already is). For each required: true, direction: In declaration whose reverseName == T, check that the edge's source type satisfies the declaration's targetType. If it does, reject the deletion when this is the last qualifying inbound edge. Count qualifying edges the same way check_node_completeness does: through SqliteStore::get_inbound_relationship_source_types plus type_satisfies, so an unrelated schema sharing the forward name doesn't count.

This builds on #2941. Once writes through an in name are normalized, only the forward storage shape exists and the guard needs to check only one shape. Do that one first.

Acceptance Criteria

  • Deleting the last qualifying inbound edge of a required in relationship is rejected with an error naming the relationship and the target, matching the out-side error
  • Deleting an inbound edge while another qualifying one remains succeeds
  • An edge from a source whose type doesn't satisfy the declaration's targetType is not protected, and doesn't count toward the remaining edges
  • Both remove_relationship_in_tx and delete_relationship enforce it
  • Code passes bun run quality:fix
  • Tests pass (bun run test:all)

Non-Goals

No change to how check_node_completeness evaluates requiredness, and no change to the existing out-side guard.

Activity

  1. malibio commented on Sep 25, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 265 files / 5293 tests passed

  2. self-assigned this
    on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions