Skip to content

feat: contradiction resolution ledger + undo across CLI/HTTP/MCP (#1172) - #1185

Merged
ajianaz merged 1 commit into
developfrom
feat/1172-contradiction-chain
Sep 5, 2026
Merged

feat: contradiction resolution ledger + undo across CLI/HTTP/MCP (#1172)#1185
ajianaz merged 1 commit into
developfrom
feat/1172-contradiction-chain

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

What

Fase 2 of #1172: contradiction resolutions become a first-class, auditable ledger.

  • Uteke::contradiction_resolutions(namespace, limit) β€” the resolution ledger: superseded-but-not-restored memories with reason + timestamp. Membership is EDGE-driven (deprecated row JOIN memory_edges ON edge_type = 'superseded_by') β€” the same predicate undo_supersession resolves against, so listed ⇔ undoable.
  • Uteke::undo_supersession(id) β€” now atomic: restore + edge-pair removal in ONE transaction (previously promote() committed first, so a failed edge delete left an ACTIVE memory carrying a live superseded_by pair). Vector-index re-add + recall-cache invalidation run as post-commit side effects, mirroring promote()'s contract.
  • supersede() re-supersession fix β€” superseding an already-deprecated memory now refreshes deprecate_reason/deprecated_at, so the ledger always names the CURRENT winner (previously the stale first-winner reason contradicted the edge pair).
  • Surfaces (parity across all three):
    • HTTP: GET /contradictions?namespace=&limit=, POST /contradictions/undo ({id} β†’ 404 when nothing to undo)
    • CLI: uteke contradictions list [--namespace --limit --json], uteke contradictions undo <id|prefix>
    • MCP: uteke_contradictions, uteke_contradictions_undo
  • Fix: the no-namespace ledger query declared LIMIT ?2 while binding a single parameter β†’ runtime bind error on every call. Caught by the new MCP roundtrip test.
  • Docs: docs/cli-reference.md (contradictions section), CHANGELOG [Unreleased], docs/api-reference.md regenerated via docgen.

Why

#1172 Fase 2. Supersede was a side effect with no audit surface: agents couldn't see what the pipeline decided or revert a wrong decision without hand-editing edges. The ledger + undo close that loop, and the edge-driven membership guarantees the ledger can never disagree with what undo actually operates on (cora review caught exactly that divergence β€” plus the non-atomic undo β€” across three review rounds; all three findings are fixed here with regression tests).

Testing

  • cargo test --workspace β€” 554 passed, 0 failed (incl. 4 new: core resupersession-ledger regression, MCP list/undo roundtrip with short-id resolution + double-undo error, 2 server API tests via TestRequest: ledger-list/undo-restores + undo-404/malformed-400)
  • cargo fmt --all -- --check clean; cargo clippy --workspace --all-targets zero warnings
  • cora review --staged pass (3 iterations: fixed non-atomic undo, stale re-supersession reason, LIKE-based ledger membership β€” each verified by the new tests)
  • cargo run -p docgen regenerates api-reference with both endpoints

Fase 2 of #1172: supersessions become a first-class, auditable ledger.

- contradiction_resolutions(): edge-driven ledger (deprecated row +
  superseded_by edge) β€” same predicate undo_supersession resolves
  against, so listed = undoable, always
- undo_supersession(): atomic restore + edge-pair removal in one tx
  (was: promote() committed first, edge delete could fail after β†’
  active memory with live superseded_by pair), post-commit vector
  index re-add + cache invalidation
- supersede(): re-supersession refreshes deprecate_reason/deprecated_at
  so the ledger names the CURRENT winner
- Surfaces: GET /contradictions, POST /contradictions/undo,
  uteke contradictions list|undo, MCP uteke_contradictions(+_undo)
- Fix: no-namespace ledger query bound limit to nonexistent ?2
- Tests: core (ledger/undo/chain/resupersession), server API (2),
  MCP roundtrip (1); fmt/clippy clean; cora review pass
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

πŸ” Cora AI Code Review

βœ… No issues found. Code looks good!


Review powered by cora-code Β· BYOK Β· MIT

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