Repository navigation
fix(query): apply terminal-key conditionals per item - #734
Conversation
|
Warning Review limit reached
Next review available in: 6 minutes Limit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?Wait for the limit to reset, then comment An organization admin can change what happens after included review limits in Billing. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #734 +/- ##
===========================================
+ Coverage 92.30% 92.37% +0.06%
===========================================
Files 278 280 +2
Lines 86145 86307 +162
===========================================
+ Hits 79520 79724 +204
+ Misses 6625 6583 -42
🚀 New features to boost your workflow:
|
99a27f5 to
cc83d0f
Compare
* feat(version): add GROVE_V4, behaviourally identical to V3 GROVE_V3 is live, so a fix that changes an accepted/rejected outcome, a committed root hash, or a tracked cost cannot be applied unconditionally — nodes carrying it would diverge from nodes that do not. There is currently nowhere for such a fix to land, which has left several of them stuck: - #776: overwriting an indexed tree with a bare Reference skips the per-axis secondary cleanup. Closing it costs an extra stored-element read on EVERY reference overwrite (+1 seek, +79 storage_loaded_bytes, measured by the refresh-reference cost tests), and references over plain trees are shipped functionality. - Batch DeleteTree treats the caller-declared tree type as authoritative when selecting cleanup namespaces. Reading the stored element instead fixes both an indexed type-confusion and a live CommitmentTree wrong-emptiness-path bug, but adds a read to a released path. - Per project notes, five audit-fix PRs (#726, #730, #732, #734, #739) are gated on v3 and need re-gating before they can merge. This adds the version and nothing else. Every method-version slot is copied from V3 unchanged, so activating protocol version 4 today is a no-op; each gate is a deliberate, separately-reviewable slot bump. Verified rather than assumed: registering V4 changes what `GroveVersion::latest()` resolves to, and the whole test suite defaults to latest. The full workspace suite passes with V4 as latest (2459 grovedb + 705 merk + the rest), and the only two failures were the version registry's own self-describing tests — `grove_version_latest_returns_v3` and `grove_versions_count` — which are updated here. That is the evidence the change is inert. Adds `grove_v4_is_behaviourally_identical_to_v3_until_a_gate_is_added`, which compares every slot and fails the moment one is bumped. That failure is the intended prompt to document the gate rather than let V4 accrete behaviour silently. Co-Authored-By: Claude Fable 5 <[email protected]> * test(version): drop the V3/V4 slot-identity assertion It pinned V4's initial state as inert, which was worth verifying once but becomes churn the moment a gate is added — and the DeleteTree read and #776 are both queued to gate on V4 next, so it would fail immediately and be deleted anyway. The evidence it provided is preserved where it belongs: the PR description records that the full workspace suite passed with V4 as latest and that only the registry's own self-describing tests changed. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
…inal-keys-conditionals
GROVE_V3 went live in production, so the terminal_keys fix from #689 can no longer activate there: v3 must keep the legacy walk that expands every conditional branch before the queried items. Move the gate to GROVE_V4 (terminal_keys: 1), keep v1..v3 at 0, and pin all four versions with a regression test. Also adapt to the unified-PathQuery develop: - add the new Query::read_mode field to the absence-proof test's struct literal - add a PathQuery-level test proving v3 resolves terminal keys with the legacy semantics while v4 applies conditionals per queried item - document the flipped slot in the v4 module header Co-Authored-By: Claude Fable 5 <[email protected]>
Replace the ad-hoc terminal_keys_for_version(u16) API and _legacy suffix with the project's versioned-function layout (as in add_element_on_transaction and Drive): a terminal_keys module in grovedb-query with v0.rs (legacy walk, frozen for GROVE_V1..V3, bug-for-bug per issue #689) and v1.rs (per-item conditional resolution, GROVE_V4+), each with a doc header explaining what is frozen and why. grovedb-query does not depend on grovedb-version, so the GroveVersion match dispatch lives in PathQuery::terminal_keys, selecting terminal_keys_v0 / terminal_keys_v1 and returning UnknownVersionMismatch otherwise. The unversioned Query::terminal_keys is removed entirely — it silently defaulted to the new semantics, so any external caller now has to pick a version explicitly. Tests updated: shared behavior runs against both versions, version-specific semantics (including the frozen v0 (None, None)-override key drop) are pinned per version, and an unknown-version dispatch test is added in grovedb. Co-Authored-By: Claude Fable 5 <[email protected]>
…inal-keys-conditionals
llvm-cov showed v0.rs at 80.7% line coverage (v1.rs was 100%). Cover the remaining v0-only paths: the conditional subquery-path-without-subquery arm (terminal key emission, at-limit error, empty-path corruption error), both over-limit loop guards, and error propagation through nested subqueries reached via conditional and default branches. Both files are now at 100% line and function coverage. Co-Authored-By: Claude Fable 5 <[email protected]>
Summary
Query::terminal_keysresolved conditional subquery branches independently of the queried items, so absence-proof verification and thequery_keys_optionalfamily could demand terminal keys for selectors that were never queried, or silently drop a queried key overridden by a(None, None)conditional branch.Fixes #689.
Approach
The fix follows the project's standard versioned-function layout (v0/v1 sub-files with a dispatch on the
GroveVersionslot, as inadd_element_on_transaction):grovedb-query/src/terminal_keys/v0.rs— the legacy walk, frozen bug-for-bug forGROVE_V1..GROVE_V3(all live in production): conditional branches are expanded before the queried items. Token-identical to the previous implementation.grovedb-query/src/terminal_keys/v1.rs—GROVE_V4+: terminal keys are computed per queried item, resolving the first conditional branch containing the key (IndexMap insertion order) with the default branch as fallback — mirroring runtime query execution (subquery_paths_and_value_for_sized_query).PathQuery::terminal_keys(grovedb-query does not depend on grovedb-version), matching onpath_query_methods.terminal_keys:0 → v0,1 → v1, otherwiseUnknownVersionMismatch.Version gating
terminal_keys: 0onGROVE_V1..GROVE_V3,1onGROVE_V4, pinned by a regression test in grovedb-version.terminal_keysis verifier-side result assembly (absence proofs) and trusted reads only — proof generation never calls it, so no wire-format change. The locked V0 prover/verifier functions are untouched; verification under v1–v3 grove versions is byte-identical to before.OperationCost), so no estimation/replay implications.Breaking change (downstream)
The unversioned
Query::terminal_keysis removed — it would have silently defaulted to one behavior. Callers outside this repo (e.g. Drive) that used it directly must switch toPathQuery::terminal_keys(max_results, grove_version)or pickterminal_keys_v0/terminal_keys_v1explicitly.Tests
path_query_terminal_keys_conditionals_gate_at_v4) proving legacy vs fixed semantics throughPathQuery::terminal_keys, plus an unknown-version dispatch test.grovedb-query/tests/query_terminal_and_merge.rs, including the frozen v0 quirk where a(None, None)conditional override drops the queried key; shared behavior (limits, depth cap, error paths) runs against both versions.verify_absence_ignores_unqueried_conditional_subquery_branches.Verification
cargo test -p grovedb— 2809 passed, 0 failedcargo test -p grovedb-query— 405 passed, 0 failedcargo test -p grovedb-version— 52 passed, 0 failedcargo fmt --checkandcargo clippy --workspace --all-features -- -D warnings— clean🤖 Generated with Claude Code