Repository navigation
fix(drive)!: index null flags follow each index's own path (PV14) - #5173
Conversation
The v2 index-level insert and delete walkers kept any_fields_null / all_fields_null in the function's variables and updated them for each sibling sub-level in turn, so a missing value in one branch of the merged index tree also marked every branch visited after it: a unique index could store its entry in the `[0]` tree meant for a missing value, and a `nullSearchable: false` index an entry for a document missing all of its values, because of another index's values. Update 1, the SDK document cost and the layout already judge each index alone. Each sub-level now gets its parent's flags combined with its own value. The delete also tracks the flag as the earlier rule carried it; where the two disagree on a unique index it reads the stored `[0]` and removes the entry in the shape it has, so an entry written before still deletes. Only PV14 (unreleased) selects these walkers; v0/v1 are unchanged. Tests: sibling-nulls fixture (added to the shared contract list, so the layout and SDK cost tests cover it) and an e2e suite, including a listing inserted under protocol version 13 deleted at 14. Book Null Handling and PV14 changelog item 59. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (15)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughVersion 14 index insertion now derives null flags independently for each index path. Delete and update walkers inspect stored entries in selected legacy-layout cases and use the detected layout. Fixtures and end-to-end tests cover sibling nulls and entries written under protocol version 13. ChangesIndex null handling
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to No actionable issue was established that would prevent merging after normal checks. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The change corrects how indexes are stored, but compatibility with older stored entries matters when documents are later replaced or deleted. Version gating limits the rollout, while some recovery cases remain unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 69.39% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 49 functions across 13 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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 |
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-09-29T06:59:03.247Z |
|
🔍 Review in progress — actively reviewing now (commit 4294b12) · triage: critical |
…view) Where an earlier writer could disagree with the per-path rule, the v2 delete walker and update 1 (old-entry removal and refresh) now read how the entry is stored, through `drive::document::stored_index_entry`: - a unique entry in the `[0]` tree although none of its own values is missing (an insert carried a sibling's null flag), or as the bare reference although one is (update 0 chose the layout from the all-null flag); - a `nullSearchable: false` entry the rule skips (the carried all-null flag, or update 0, which never skipped). The reads are unbilled bookkeeping, like the time-range walkers', so a dry run and the applied operation bill the same; the dead estimation arm and its comment are gone; a type with a `ttl` (PV14-only) skips them. Tests: legacy e2e cases for item, offer (flag crossing a level), profile (nullSearchable), badge (update 0 bare layout, delete and replace) and listing (replace moving and refreshing a legacy entry), each pinned by a mutation check; the shared layout and cost tests leave out optional indexed values on two seeds, so they catch a carried flag; helpers shared with the skip e2e suite; docs (insert v2, CONTRACTS, book, changelog item 59). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict: v14.rs changelog. #5161 took item 58 (so skipIfAbsent is now 59) and #5170 / #5041 took 60 and 61; the null-flags item becomes 62. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Basic explanation
What this does: Drive stores a unique index's entry in one of two shapes: a single reference when all of the index's values are present, or a small tree of references when one of them is missing (a missing value cannot be held to uniqueness). Drive picks the shape with flags it updates while walking the document type's merged index tree. When two indexes share their first property, the flags were carried from one index's branch into the next, so the shape of one index's entry could depend on another index's values. Now every index is judged by its own values only.
Value: What Drive writes now matches what the replace path, the SDK document cost (
documentCreateCost) anddocumentTypeLayoutalready assume for every index.Risks: Low to medium, contained to protocol version 14, which is not live on mainnet.
Issue being fixed or feature implemented
Under a shared first property, the index-level walkers kept
any_fields_null/all_fields_nullin the function's own variables and updated them for each sibling sub-level in turn. A missing value in one branch therefore also marked every branch visited after it. The replace walker (update v1), the SDK cost model and the layout compute the flags per index, so they could disagree with what an insert wrote.What was done?
Before and after
A listing
{ "slug": "my-bike" }without a category. Under the owner's value tree the walker visitscategorybeforeslug:The same carrying applied to
all_fields_null, which decides whether anullSearchable: falseindex writes an entry. A profile{ "name": "ada" }with no city and no zip, besidebyCityName [city, name]andbyCityZip [city, zip](nullSearchable: false):State trees
What Drive stores for the examples, dumped from a test run of each protocol version (
[0]at the document type is primary storage;<id>is the document,<owner>its owner;""is the null key a missing value takes).A listing
{ "slug": "my-bike" }without a category:A profile
{ "name": "ada" }with no city and no zip (byCityZipisnullSearchable: false):The same profile when
byCityZipkeeps the defaultnullSearchable: true:Both versions store the same tree. With
nullSearchable: truea document missing every value of the index still gets an entry, so the all-null flag decides nothing here, and the index is not unique, so the any-null flag never changes its shape: the carried flags only mattered for unique andnullSearchable: falseindexes.The other earlier writer, the replace walker of protocol version 13 and before: a badge (
byOwnerCodeVariant [$ownerId, code, variant], unique,variantoptional) created with{ "code": "a", "variant": "x" }and replaced with{ "code": "a" }:In each pair, a delete or a replace at protocol version 14 of the document on the left reads the element at the marked place and removes or refreshes the entry in the shape it finds there.
Walkers (Drive)
add_indices_for_index_level_for_contract_operationsv2): each sub-level's flags are its parent's flags combined with its own value.remove_indices_for_index_level_for_contract_operationsv2): the same, plus the flag as the earlier rule carried it.drive::document::stored_index_entry): two earlier writers disagree with the rule. The walkers carried the flags across siblings, and the replace walker of earlier versions (update 0) laid out a unique index with some values missing as the bare reference and never skipped anullSearchable: falseentry. So:[0]and act on that shape;nullSearchable: falseindex the rule skips, they check whether an entry is there anyway and remove it.ttl(only from protocol version 14) skips them.Which earlier writer can leave which shape, and what finds it now:
[0]tree although all its values are present[0]nullSearchable: falseentry although all its values are missing[0]nullSearchable: falseentry although all its values are missingHow the delete, and the replace for the old entry, pick the shape at each index's terminal:
flowchart TD A["Delete, or replace (old entry),<br/>at an index's terminal"] --> B{"Fee dry run, indexOnly index,<br/>or a type with a ttl?"} B -- yes --> R["The rule's shape, no read"] B -- no --> C{"nullSearchable: false and<br/>every value missing?"} C -- yes --> D{"An entry for the document<br/>in the [0] tree?"} D -- yes --> E["Remove it"] D -- no --> F["Nothing to remove"] C -- no --> G{"Unique, and a value missing on<br/>its path or on an earlier sibling's?"} G -- no --> R G -- yes --> H{"Read [0]"} H -- tree --> I["Remove or refresh the<br/>reference inside the tree"] H -- reference --> J["Remove or refresh the<br/>reference at [0]"] H -- nothing --> RDocs
In-place changes to shipped generations
add_indices_for_index_level_for_contract_operationsv2,remove_indices_for_index_level_for_contract_operationsv2 andupdate_document_for_contract_operationsv1: selected only at protocol version 14 (DRIVE_DOCUMENT_METHOD_VERSIONS_V4), which is unreleased. The walkers of earlier versions are unchanged, so every historical block replays as before.How Has This Been Tested?
sibling_null_flags_e2e_tests, fixturesibling-nulls-contract.json):$updatedAtit does not require gets a bare unique reference;nullSearchable: falseindex gets no entry there;[0]tree and the prior tree is restored;nullSearchable: falserule skips is removed and its branch pruned;should_price_what_drive_chargeson the new fixture (Drive charged more bytes than the model).nullSearchablecheck, update 1's old-entry read or its refresh read) fails at least one of the version 13 tests. Without the delete's read, it removes[0]as a lone element, leaving the reference inside it in storage where no walk of the tree can see it; the tests check the operations for that.should_lay_out_what_drive_writesandshould_price_what_drive_chargesnow leave out the optional indexed values on two seeds (all of them, or every other one), so a carried flag fails the cost test.Breaking Changes
Consensus: PV14 storage rules change in place (see above). No released protocol version is affected.
Notes for reviewers
[0]as the rule lays it out, so a replace that keeps the values of an entry written the earlier way stops there, as it did before; such a document can be deleted, or replaced with other values. A later protocol version rewrites those entries to the rule's shape and drops the reads: Rewrite index entries earlier versions laid out otherwise, then drop the stored-layout reads (PV15+) #5196.nullSearchable: falseentry are written on insert and, with no entry below them, not pruned on delete (the layout'snotNullSearchablenote describes the first half).Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull request (no structure change: no new node kinds)For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
4294b12/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are doneWhen every box is checked the
PR Hygienecheck passes and this can merge.