perf(core): index exact named graph lookups #7376
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #7376"
general
weight: 0.35
jeswr
<!-- claude-projects-attribution: {"github_login":"jeswr"} -->
_Requested by Jesse · project thread_
Addresses #7188.
Addresses #7370.
Change and design
Resolving a graph by its exact name used to scan the named-graph Vec. That happened in core, in constant GRAPH evaluation, in scoped forks and in durable effect application. This PR adds a shared in-memory exact-name index. Those paths, dataset-clause selection and the capability callers that do the same lookup now go through it.
- Removal still does linear work to shift Vec members and index positions. This PR doesn't claim deletion is independent of graph count.
- Single removals keep the table's capacity. Bulk membership rebuilds and drop-all can release it, and
heap_bytescounts retained capacity.heap_bytescounts the hash table and any duplicate-position allocations. The index lives only in memory, so the storage format, declared-slot behaviour and persistence ordering are unchanged.named_graph_index(&name)is now public for positional writes, and the data-format and query skills explain when a position goes stale.GraphandGraphSnapshotdon't implement Clone, so clone coverage uses shared snapshot ownership and independent forks.Tests
named_index_matches_vec_operations: runs random operations from a fixed seed and compares each step against an independent Vec model. It checks indexed positions, first-match references, full ordered contents and prefix results.- Operations: add, ensure, replace, remove/drop, retain, take/extend, clear, compression, default replacement and rebuild, vacuum, forks, scoped forks and shared snapshot clones.
- Inputs include duplicate names and different term kinds.
named_index_survives_save_replay_and_rewrites: runs durable operations from a fixed seed and checks the ordered state at each stage.- Stages: save/open, journal replay of committed but unmaterialized creates and drops in read-only and writable opens, per-slot WAL replay, clear, compaction, vacuum, and snapshot and scoped forks.
- It also checks that surviving members keep their declared slots across ordinary creates and drops.
removal_preserves_duplicate_order_and_term_identity: checks specific removal cases: duplicate promotion, deleting a non-first duplicate, shifted positions, deleting the tail, removing down to empty, and appending again.- An IRI, a blank node and a literal share the same lexical text, and each must still resolve to its own entry.
- After each step, scoped selection checks every remaining duplicate and its contents.
exact_lookup_work_is_bounded: a test-only comparison probe checks that hits, misses, existing ensure and scoped selection stay bounded as the population grows. Hit paths must record index work, so a fallback that skips the probe fails too. The test also checks thatheap_bytesincludes the index.pop_namedis compiled only with mmap, the feature its fixture callers need. This avoids an unused-helper warning in test builds without mmap.Mutation evidence
Each mutation below compiled, failed the named assertion and was restored. The index tests passed again after each restore.
NamedIndex::removeby adding an extra decrement after the normal shift:removal_preserves_duplicate_order_and_term_identityfails indexed-position equality for a survivor.The removal test fails ordered membership and contents equality in scoped selection.
The removal test fails indexed-position equality.
named_index_matches_vec_operationsfails indexed-position equality.named_index_survives_save_replay_and_rewritesfails indexed-position equality.exact_lookup_work_is_boundedfailsexact lookup must not scan named graphs. An instrumented linear scan fails the same assertion.The bounded-work test fails
scoped selection must not scan named graphs.named_index.heap_bytes()contribution. The bounded-work test failsaccount for the exact index allocationequality.Base gate (always required)
Rerun after the review fixes:
cargo test -p sparq-core,--no-default-features, and--features mmap,dict-spill: PASS. These include the crash, fault, journal, corruption and byte-identity suites.cargo test -p sparq-engineand defaultcargo test -p sparq-lws-core: PASS.cargo clippy --workspace --exclude sparq-py --all-targets -- -D warnings: PASS.python3 scripts/preflight.py, changed-markdown lint, andgit diff --check: PASS.cargo build --workspacewas not run. Crate-scoped builds and workspace clippy were run instead.Targeted re-evaluation (check the rows that apply to your change)
odrl-bridge,trust-graph; MCP withsolid; LWS with no default features and withhttp-sparq; strict rustdoc for the other changed crates. All PASS.cargo test -p sparq-zkis blocked locally at the live external-compiler cross-check, because the compiler's dependency cache can't be locked on a read-only home filesystem. The Rust suite passed with the existing missing-toolchain declaration and the named skip shown. That skip doesn't count as a pass for the live check. No gate source was changed.Ratchets and conventions
- The separate decoded update Dataset still does its own name lookup.
- The existing parent-state and checkpoint work under the linked durable-create issue is separate from Graph exact-name resolution.
🤖 Generated with Claude Code
https://claude.ai/code/session_01JLKBH5gHei9rJAmvhNgZyi