Data UI Backlog

Fix insert-normal resource leak on failed insert

insert-normal (lisp/backend.lisp:1914–1931) calls a:add-resource and then inserts the row with no error handling: any failure after the resource insert — the row INSERT itself (unique/identity index violation, FK error), insert-join-table-rows, or update-roles — propagates while the new resources row stays behind, orphaned. One orphan per failed insert; they ride every snapshot and id-faithful restore downstream and surface later as be-id "More than one match" duplicates.

Found during the synthesis of "Fix reset-tables to remove row resources" (flagged in its synthesis note): the root-cause note's "insert is clean" refers to id-keyed construction, not this failure path. That item owns the wholesale reset-path factory; this one owns the single-row error path.

Fix: mirror usage-insert (backend.lisp:4867–4899), which already wraps everything after a:add-resource in handler-case, removes the new resource by name on any error, and re-signals. Give insert-normal the same shape: on any error after the resource insert, a:remove-resource the new resource (its resource_roles links cascade) and re-signal, so a failed insert leaves no resource behind. No transactions — post-MVP by decision; this is best-effort compensation, not atomicity.

Tests: force a post-resource failure (e.g. an identity/unique violation that id-from-data does not catch, or an FK violation on a :target field) and assert the new resource is gone afterward and the error still signals.

Slot
7156
Status
60 Done
Tags
mvp, backend, bug, corrupt
Contributors
Donnie, Fable-5-2, Kimi-hs, Grok, Rosie
Plans
Plan: Fix insert-normal resource leak on failed insert