Skip to content

feat: per-pair dedup control via POST /consolidate/pair - #1102

Merged
ajianaz merged 2 commits into
developfrom
feat/consolidate-pair
Aug 26, 2026
Merged

ajianaz merged 2 commits into
developfrom
feat/consolidate-pair

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

What

Add per-pair dedup control: POST /consolidate/pair accepts { "id_keep": "<uuid>", "id_remove": "<uuid>", "hard": false } and consolidates exactly one caller-chosen pair — the keeper stays untouched, the loser is deprecated (soft-delete with manual pair dedup: superseded by <id_keep> reason) or hard-deleted when hard=true.

  • uteke-core: Uteke::consolidate_pair() reusing the same soft-delete + reason + index cleanup path as bulk consolidate (SQLite first, then vector index removal + save, then recall-cache invalidation for the loser's namespace).
  • uteke-server: ConsolidatePairRequest type, route handler with 400 for validation errors (same id, missing memory, deprecated keeper) and 500 otherwise, api_registry entry (issue 1076).
  • docs/api-reference.md regenerated via cargo run -p docgen.

Why

The bulk /consolidate endpoint only merges everything above a threshold with a hard-coded keep-newer rule. Reviewers looking at duplicates side-by-side (Corin Consolidate Panel, codecoradev/corin#242) need to pick which memory survives — e.g. the older entry has richer content, or the newer one is a truncated re-save.

Closes #1076

How

Single new method on Uteke (consolidate_pair) mirroring the removal half of consolidate() without the pair-scan loop. New response type PairConsolidationResult { kept, removed, hard }. No schema change, no migration — pure additive endpoint.

Testing

  • test_consolidate_pair_soft_delete — caller keeps the OLDER entry (overrides keep-newer), loser gets deprecated=true + deprecated_at set.
  • test_consolidate_pair_hard_delete — hard=true removes the row outright; keeper survives.
  • test_consolidate_pair_validation — same-id, missing keeper/loser, and deprecated-keeper all rejected.
  • consolidate_pair_request_parses — request deserialization incl. hard default false.
  • Full workspace suite green: 591 passed, 0 failed (25 pre-existing ignores, embedder-dependent).
  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, docgen freshness: all clean.

Related Issues

Closes #1076
Related: codecoradev/corin#242 (Consolidate Panel will use this for per-pair [Keep A]/[Keep B] buttons)

Checklist

Known Limitations (Cora advisory — not addressed)

Cora review flagged /consolidate/pair ignores request namespace/tenant scoping [MAJOR]. This is consistent with every other ID-based endpoint in the API (DELETE /forget?id=, GET by id, room endpoints): memory IDs are unguessable UUIDs and the server has no per-request tenant binding for ID-addressed operations. Fixing this properly is a codebase-wide authz design change (namespace binding on all ID-based routes), out of scope for #1076 — tracked separately if desired.

Add caller-chosen survivor consolidation: keep id_keep untouched,
deprecate (or hard-delete) id_remove. Reuses the same soft-delete +
reason + index cleanup path as bulk /consolidate, overriding the
hard-coded keep-newer rule when the reviewer picks the richer entry.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

rusqlite reports an empty string (not ":memory:") as the path of an
in-memory database, so store.path() leaked through the ephemeral guard:
every ':memory:' open wrote ./uteke_index.usearch and ./embed_cache.db
into the CWD. Concurrent tests then raced on one shared index file
(sidecar keys vs usearch keys) producing non-deterministic
'Duplicate keys not allowed' flakes.

Treat both '' and ':memory:' as ephemeral: no index file, no embed
cache file. Verified: 3x full workspace suite green with zero stray
files emitted.
@ajianaz
ajianaz merged commit e7c127e into develop Aug 26, 2026
14 checks passed
@ajianaz
ajianaz deleted the feat/consolidate-pair branch August 26, 2026 06:31
ajianaz added a commit that referenced this pull request Sep 6, 2026