Skip to content

feat(indexed-tree)!: accept a bare SumItem under a ProvableCountProvableSumIndexedTree (GROVE_V4) - #1003

Merged
QuantumExplorer merged 1 commit into
developfrom
feat/pcpsit-sum-item-children
Oct 1, 2026
Merged

QuantumExplorer merged 1 commit into
developfrom
feat/pcpsit-sum-item-children

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: GroveDB has a tree that ranks its children three ways at once: by how many things each child counts, by their total, and by their average. It refuses a SumItem (a stored number) as a child, saying the number carries no count. But in that tree a SumItem counts as one and adds its number to the total, which is all the tree needs. This lets the tree accept it from GROVE_V4 on.

Value: Platform can keep one counter per post (a SumItem holding the post's like count) and rank authors and hashtags by number of posts, total likes and likes per post, all from one tree, without wrapping each counter in an empty item. It replaces #1002, which added a new element for this; plain SumItems do the job with no new element type.

Risks: Low. Only GROVE_V4 accepts the new child; GROVE_V1..GROVE_V3 keep refusing it through a version slot, so no released version changes behaviour. The tree already aggregates a SumItem correctly: the count, sum and average rankings all read count_sum_value_or_default, which returns (1, n) for it. A SumItem wrapped in NonCounted or another wrapper stays refused. Code that builds GroveDBOperationsInsertVersions by hand needs the new field.

Issue being fixed or feature implemented

A ProvableCountProvableSumIndexedTree (PCPSIT) primary only accepted children that carry a count and a sum explicitly: ItemWithSumItem, ReferenceWithSumItem and the count-and-sum trees (validate_indexed_child_for_variant → is_count_and_sum_bearing_child). A bare SumItem was refused as "sum-only", although in a count-and-sum tree it already contributes a count of one.

Platform's count-only indexes keep one counter per group: one per post, holding the number of likes. Ranking authors by posts, likes and likes per post needs those counters under a PCPSIT:

"postAuthor"  PCPSIT (count, sum, avg)   ranks authors by posts / likes / likes per post
  alice       CountSumTree (2, 8)
    "postId"  PCPSIT (sum)               ranks alice's posts by likes
      p1      SumItem(3)                 refused before this change
      p2      SumItem(5)

Before: inserting SumItem(3) at p1 fails with "ProvableCountProvableSumIndexedTree only accepts children that contribute both count and sum".
After (GROVE_V4): it is accepted. alice aggregates (2, 8), and postAuthor ranks by count, sum and average from it.

What was done?

  • validate_indexed_child_for_variant takes the grove version. For a PCPSIT primary it accepts a bare SumItem when the new slot grovedb_versions.operations.insert.validate_indexed_child_for_variant is 1. Both callers pass the version:
    • the dedicated insert_into_*_indexed_tree path;
    • the batch path, capture_indexed_pre_state → validate_indexed_child_ops.
  • The new slot is 0 for GROVE_V1..GROVE_V3 (keep refusing) and 1 for GROVE_V4. It is documented in the GROVE_V4 module docs.
  • Only an unwrapped SumItem qualifies: a wrapper would suppress the count or the sum it exists to give.
  • The CHANGELOG has the entry.

How Has This Been Tested?

  • pcpsit_accepts_a_bare_sum_item_from_grove_v4: replaces pcpsit_rejects_sum_only_item, which pinned the old refusal at the latest version. The parent then aggregates (1, 42) and verify_grovedb is clean.
  • pcpsit_child_rule_refuses_a_bare_sum_item_before_grove_v4: the rule refuses on GROVE_V1, GROVE_V2 and GROVE_V3, and accepts at the latest version.
  • pcpsit_refuses_a_wrapped_sum_item: NonCounted(SumItem) is still refused.
  • pcpsit_sum_item_children_tests builds the shape above:
    • proved top-K: authors by likes (bob 10, alice 8), by posts (alice 2, bob 1) and by likes per post (bob, alice); alice's posts by likes (p2, p1);
    • after a one-op batch rewrite of p1 to 13: the author ranking flips to alice 18 / bob 10, post counts don't move, bob still leads per post (10 against 9), and p1 leads alice's posts;
    • verify_grovedb is clean throughout.
  • cargo test -p grovedb -p grovedb-version --all-features: 3626 passed. cargo clippy --all-features --all-targets and cargo fmt --check clean.

Breaking Changes

  • GroveDBOperationsInsertVersions gains validate_indexed_child_for_variant.
  • Behaviour changes only at GROVE_V4: a bare SumItem under a PCPSIT primary is accepted. No released grove version changes outcome.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 076b3f9

  • Bots — coderabbitai ✓ · thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed once the bots are done
  • Within your 5 open PRs
  • Build running
  • Approvals — you own every area touched; none needed

When every box is checked the PR Hygiene check passes and this can merge.

Summary by CodeRabbit

  • New Features
    • In Grove V4, provable count-and-sum indexed trees now accept bare SumItem children. Each child contributes a count of one and its sum, enabling rankings such as total and average values.
  • Compatibility
    • Grove V1–V3 continue to reject bare SumItem children. Wrapped SumItem children remain unsupported across all versions.

…bleSumIndexedTree (GROVE_V4)

A ProvableCountProvableSumIndexedTree primary only accepted children that
carry a count and a sum explicitly (ItemWithSumItem, ReferenceWithSumItem,
the count-sum trees) and refused a bare SumItem as sum-only. A SumItem in a
count-and-sum tree counts one and adds its sum, which is every input the
count, sum and average axes read (count_sum_value_or_default), so the
refusal kept per-group counters out of the one tree that ranks groups by
how many counters they hold, their total and their average.

From GROVE_V4 the child rule accepts it on the direct and the batch path,
through the new insert.validate_indexed_child_for_variant slot (0 for
V1..V3, which keep refusing it; 1 for V4). A wrapped SumItem stays refused.

Breaking: GroveDBOperationsInsertVersions gains a field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 3d3f0f41-86a8-44e3-a5df-1ebfa8fde7b2

📥 Commits

Reviewing files that changed from the base of the PR and between a720f7c and 076b3f9.

📒 Files selected for processing (11)
  • CHANGELOG.md
  • grovedb-version/src/version/grovedb_versions.rs
  • grovedb-version/src/version/v1.rs
  • grovedb-version/src/version/v2.rs
  • grovedb-version/src/version/v3.rs
  • grovedb-version/src/version/v4.rs
  • grovedb/src/batch/indexed_tree/pre_state.rs
  • grovedb/src/operations/indexed_tree.rs
  • grovedb/src/tests/mod.rs
  • grovedb/src/tests/pcpsit_sum_item_children_tests.rs
  • grovedb/src/tests/provable_count_provable_sum_indexed_tree_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds versioned validation for bare SumItem children in provable count/sum indexed trees. GROVE_V4 accepts them as count one plus their sum. GROVE_V1–V3 and all versions for wrapped SumItem children retain rejection behavior.

Changes

PCPSIT SumItem child validation

Layer / File(s) Summary
Add and configure the validation version slot
grovedb-version/src/version/grovedb_versions.rs, grovedb-version/src/version/v1.rs, grovedb-version/src/version/v2.rs, grovedb-version/src/version/v3.rs, grovedb-version/src/version/v4.rs
GroveDBOperationsInsertVersions adds validate_indexed_child_for_variant. GROVE_V1–V3 set it to version 0, and GROVE_V4 sets it to version 1.
Apply versioned validation to insert paths
grovedb/src/operations/indexed_tree.rs, grovedb/src/batch/indexed_tree/pre_state.rs
The validator uses the configured version to decide whether a bare SumItem is accepted. Direct insertion and batch pre-state validation pass the Grove version to the validator.
Verify accepted and rejected child behavior
grovedb/src/tests/mod.rs, grovedb/src/tests/provable_count_provable_sum_indexed_tree_tests.rs, grovedb/src/tests/pcpsit_sum_item_children_tests.rs, CHANGELOG.md
Tests cover version-specific acceptance, wrapped-child rejection, ranking and batch updates, proofs, and database verification. The changelog records the behavior and the new version slot.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to 076b3

This change enables bare SumItem children in provable count/sum indexed trees only under GROVE_V4, leaving earlier versions unchanged. No merge-blocking risk was found in the reviewed code.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 076b3

This is a bounded, version-gated behavior change. Existing structural checks remain enforced, and no introduced security flaw was established. Compatibility after using the new behavior, especially during downgrade, remains incompletely demonstrated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The expanded input surface is a numeric child supplied through an existing indexed-tree write path. Its effects propagate through secondary rankings and aggregate ancestors. The reviewed library scope does not establish application authorization, tenant exposure or who may select the GroveVersion.

Trust Boundaries and Controls

  • observed — Acceptance remains structural validation, not an authorization grant. Batch operations still enforce tree insertability and reject rootless tree elements claiming nonzero aggregates. The new numeric leaf exception does not remove those controls or the dedicated path's expected-tree-type check.

Resilience and Maintainability Implications

  • observed — The inspected lifecycle derives secondary transitions from primary post-state and stages primary and secondary changes in the existing transactional batch pipeline. Dedicated deletion also delegates to that pipeline. This supports failure containment for the traced execution path, but does not establish concurrent ordering or process-interruption recovery guarantees.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: accepting bare SumItem children under ProvableCountProvableSumIndexedTree in GROVE_V4. The breaking-change marker is appropriate becau…
Docstring Coverage ✅ Passed Docstring coverage is 81.25% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 10 files. (1 skipped: 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 1, 2026
@thepastaclaw

thepastaclaw commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🕓 Queued for automated review — 2nd in line, estimated start in ~10 min (commit 076b3f9)
Estimated review time once started: ~15 min (two-phase automated review; median of recent runs).

  • Request priority review — click to move this review to the front of the queue.

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.83333% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.13%. Comparing base (dce8252) to head (076b3f9).
⚠️ Report is 8 commits behind head on develop.

Files with missing lines Patch % Lines
grovedb/src/operations/indexed_tree.rs 66.66% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1003      +/-   ##
===========================================
+ Coverage    93.10%   93.13%   +0.02%     
===========================================
  Files          336      336              
  Lines       105421   105623     +202     
===========================================
+ Hits         98153    98367     +214     
+ Misses        7268     7256      -12     
Components Coverage Δ
grovedb-core 91.47% <70.83%> (-0.01%) ⬇️
merk 94.03% <ø> (ø)
storage 91.94% <ø> (ø)
commitment-tree 95.62% <ø> (ø)
mmr 95.43% <ø> (ø)
bulk-append-tree 93.72% <ø> (ø)
element 97.18% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@QuantumExplorer
QuantumExplorer merged commit d7e6f94 into develop Oct 1, 2026
13 of 15 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/pcpsit-sum-item-children branch October 1, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants