Plan: 002 — Resolve Citations to Case Nodes¶
Approach¶
- Extend
ExtractionResultwith an optionalaliases: list[str](default[]). Threaded throughMERGE_CASE_CYPHERso freshly-ingested cases register their canonical citation forms. - New module
backend/app/db/citation_resolver.pywith two pure-async functions and one batched Cypher query. - Wire
densify_extractionintoIngestionScout.run_and_commitbetweenextractandcommit_extraction. - Add provenance hook so each resolution emits an audit record.
Cypher¶
UNWIND $normalized AS n
OPTIONAL MATCH (c:Case)
WHERE n IN coalesce(c.aliases, [])
RETURN n AS normalized, head(collect(c.id)) AS case_id
- One round-trip regardless of input length (NFR-PERF-1).
head(collect(...))deterministic on alias collisions (lexicographically smallest first via secondary sort if needed; first iteration ships with non-deterministicheadand a follow-up to add a deterministic tie-break).
Idempotency Argument¶
MERGE_CITES_CYPHER is the existing MERGE on the (src,dst) pair, so re-running with the same target_case_id is a no-op. Resolver itself is read-only, so it's trivially idempotent.
Test Strategy¶
- Pure unit tests with a
FakeAsyncSessionrecording calls and returning canned cursors. No Docker required for the green path (constitution §3 — fast tests). - Integration test gated behind
@pytest.mark.integrationmirroring spec 001 pattern (BL-20260429-01 will close that gap globally; this spec inherits the marker).
Migration¶
Add backend/app/db/neo4j_migrations/002_case_aliases.cypher:
Run by the existing migration runner on next make dev.
Risk Mitigations¶
R-1(bad aliases)::CITES.confidenceinherits source confidence, HITL gate upstream.R-2(backfill): added to follow-ups, not in this spec.