Skip to content

fix(ruflo-adr): adr-index upsert + deterministic edge keys (#2660)#2754

Open
michaelaperez-byte wants to merge 1 commit into
ruvnet:mainfrom
michaelaperez-byte:loop/T21-adr-index-upsert
Open

fix(ruflo-adr): adr-index upsert + deterministic edge keys (#2660)#2754
michaelaperez-byte wants to merge 1 commit into
ruvnet:mainfrom
michaelaperez-byte:loop/T21-adr-index-upsert

Conversation

@michaelaperez-byte

Copy link
Copy Markdown
Contributor

Fix: ruflo-adr adr-index can't update changed ADRs (#2660)

Three defects in plugins/ruflo-adr/scripts/import.mjs prevented adr-index from updating changed ADRs — its documented purpose per SKILL.md ("rebuild the ADR index + dependency graph"):

Defect 1 — Missing --upsert (line 224-228)

memoryStore() called npx ... memory store without --upsert. The CLI help says --upsert defaults to true, but #2594 shows the default is not honored. Without explicit --upsert, re-running on an existing key fails with UNIQUE constraint → the record stays frozen at its first-indexed value forever.

Fix: Added '--upsert' to the spawnSync argv.

Defect 2 — 'exists' (UNIQUE failure) counted as success (lines 255, 261)

if (r === 'ok' || r === 'exists') storedRecords++ — but 'exists' is the sentinel for the UNIQUE constraint FAILURE (line 231). A failed write was silently counted as a stored record, errors stayed empty, and the summary reported full success while nothing was persisted.

Fix: Changed to if (r === 'ok') for both patterns and edges; 'exists' now pushed to errors.

Defect 3 — Non-deterministic edge key (line 259)

Edge key had Date.now()+random suffix → never collided → upsert couldn't dedup → edges duplicated 3→6→9 on repeated runs. The edge's identity IS (relation, from, to)capturedAt already lives in the value.

Fix: Made the key deterministic: ${e.relation}:${e.from}->${e.to}.

Regression test

v3/@claude-flow/cli/__tests__/issue-2660-adr-index-upsert.test.mjs — standalone Node assertion runner (13/13 pass).

Verification

  • node --check import.mjs → SYNTAX OK
  • Regression test: 13/13 assertions passed
  • Independent verifier (fresh detached-HEAD worktree): 5 gates PASS
  • Verifier note: reindex.mjs (separate file, not touched) has the same three bugs — should get its own ticket.

Fixes #2660

Three defects in plugins/ruflo-adr/scripts/import.mjs prevented adr-index
from updating changed ADRs (its documented purpose):

1. memoryStore() called 'memory store' without --upsert. The CLI default
   is declared true but not honored (ruvnet#2594); without explicit --upsert,
   re-running on an existing key fails UNIQUE → record frozen forever.

2. The 'exists' sentinel (UNIQUE constraint failure, line 231) was counted
   as a stored record/edge (lines 255, 261). A failed write silently
   became a success tally, errors stayed empty, summary reported full
   success while nothing was persisted.

3. Edge key had Date.now()+random suffix (line 259) → never collided →
   upsert couldn't dedup → edges duplicated 3→6→9 on repeated runs.

Fix: add --upsert, count only 'ok' as stored, make edge key deterministic
(relation:from->to — capturedAt already in the value).

Issue: ruvnet#2660
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.

ruflo-adr: adr-index cannot update a changed ADR — records frozen by a strict insert, edges duplicated every run, and both reported as success

1 participant