Skip to content

fix(V2): guard shared deletes against staged references#1575

Merged
TheLastCicada merged 2 commits into
v2-rc2from
fix/v2-delete-reference-guards-staging
Apr 8, 2026
Merged

fix(V2): guard shared deletes against staged references#1575
TheLastCicada merged 2 commits into
v2-rc2from
fix/v2-delete-reference-guards-staging

Conversation

@TheLastCicada

@TheLastCicada TheLastCicada commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add V2 referential-integrity guards for shared DELETE endpoints (methodology, program, stakeholder, label) to block deletes when references exist in committed tables or staged INSERT/UPDATE rows
  • support explicit bypass via ?force=true while preserving current staging flow and clear 409 conflict payloads
  • extend integration and live API tests for guard behavior, and update V2 API docs with 409/force examples

Test plan

  • eval \"$(fnm env)\" && fnm use && npm run test:v2
    • observed: 1378 passing, 1 pending, 1 failing
    • existing unrelated failure: V2 Project API - Basic CRUD Tests -> should stage only project delete when there are no child records
  • verified new staged-reference guard tests pass for all four shared delete endpoints

Pre-push review

  • Ran adversarial pre-push diff review (fresh-context)
  • Findings: no critical issues; one warning about potential over-counting when committed + staged references overlap (non-blocking)

Note

Medium Risk
Changes DELETE behavior for shared entities by introducing new 409 conflict responses unless ?force=true is provided, which could impact existing clients and workflows. Logic also inspects staged INSERT/UPDATE rows, so incorrect counts or missed edge cases could block or allow deletes unexpectedly.

Overview
Adds referential-integrity guards to V2 DELETE endpoints for shared records (methodology, program, stakeholder, label), blocking deletion with 409 Conflict when referenced by committed data or uncommitted staged INSERT/UPDATE rows; supports bypass via ?force=true.

Introduces src/utils/v2-reference-guards.js to centralize reference counting and standardize the 409 response payload, updates docs with new 409/force examples, and extends integration + live API tests to cover referenced, staged-referenced, and forced-delete cases.

Reviewed by Cursor Bugbot for commit 3b0f920. Bugbot is set up for automated code reviews on this repo. Configure here.

Add referential integrity guards for methodology, program, stakeholder, and
label deletes so they block when links exist in committed tables or in
staged INSERT/UPDATE rows, with explicit force-delete override support.

Extend integration coverage for live and staged reference conflicts and
update live API delete helpers/docs to reflect and exercise the guard flow.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f121d6a. Configure here.

Comment thread src/utils/v2-reference-guards.js
Comment thread src/utils/v2-reference-guards.js Outdated
Address bugbot findings: add `committed: false` to the staging query
to prevent double-counting references after commit but before sync
cleanup, and replace the local toSnakeCase with the existing export
from v2-camel-to-snake.js.
@TheLastCicada TheLastCicada merged commit a9bbf5a into v2-rc2 Apr 8, 2026
25 checks passed
@TheLastCicada TheLastCicada deleted the fix/v2-delete-reference-guards-staging branch April 8, 2026 17:47
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.

1 participant