Skip to content

perf: hold a grant to one parent resolve and one read per moved node - #1845

Merged
FSM1 merged 1 commit into
mainfrom
fix/1714-one-parent-resolve-per-grant
Sep 15, 2026
Merged

FSM1 merged 1 commit into
mainfrom
fix/1714-one-parent-resolve-per-grant

Conversation

@FSM1

@FSM1 FSM1 commented Sep 14, 2026

Copy link
Copy Markdown
Owner

What this changes

Two repeated reads on the grant-creation path, both found while reviewing #1624 and merged into one issue.

One resolve of the parent scope root per grant. converge_grant_subtree resolves the parent so the resume probe can read the scope source that resolve parks. It then called converge_subtree, which resolved the same name again inside walk_and_converge. The pass now takes the proved (ChildScopeRef, SweptScope) pair from its caller; sweep_pass keeps its own resolve, so nothing else changes.

One read of every already-moved node. A resumed interior walk met each node the first attempt had moved with resolve_child, which paid a fanout resolve, a head-block fetch and an envelope decode, refused the record and dropped the decoded bytes. The fall-through then ran moved_interior_node, which repeated all three on the same name. One seam replaces the pair: resolve_moving_child reads the record once and classifies it against both scope ids, and each arm opens it under the derivation of the scope the record claims.

One override-seed recovery per move. moved_interior_node and reseal_interior_node each recovered the promoted root's override seed from its owner blob on every node, which is an X25519 operation plus an HPKE open per node. MovedScopeSeed holds the recovered seed behind an Rc, keyed on the root's own scope id, name and read epoch. A record naming any other root recovers its own seed rather than aliasing onto the held one.

Behaviour

The verdicts do not move. A grant-section record still runs the descendant gate, a record claiming neither scope still reports InteriorResolve with Rejected, and a version skew still reports as skew. The new seam additionally demands the parked source scope, which the publish arm already demanded.

Tests

  • a_grant_resolves_the_parent_scope_root_once — the whole command costs one scope-root resolve.
  • a_resumed_walk_reads_each_already_moved_node_once — a re-drive reads each moved node once and resolves the parent name once.
  • one_override_seed_recovery_serves_a_whole_interior_move — the memo answers the same root from one recovery and re-recovers for another root.

All three run in the Test gate.

Body checks / follow-ups filed

Closes #1714.

Summary by CodeRabbit

  • Bug Fixes

    • Improved recovery of in-progress scope moves, helping operations resume consistently when data has already been transferred.
    • Reduced redundant scope resolution during sweep and convergence operations, improving reliability and efficiency.
    • Improved handling and classification of moved, pending, and scope-root records during recovery.
  • Tests

    • Added coverage for consistent seed reuse and optimized single-resolution behavior during interior moves.

Note

Reduce grant moves to one parent resolve and one read per moved node

  • Replaces the old destination-only moved-interior lookup with GrantResumeResolver::resolve_moving_child, which reads each node once against the source and destination scopes and returns a MovingChild (Pending, Moved, or ScopeRoot). Moved nodes are traversed without re-sealing; pending source nodes are re-sealed; scope roots are rejected.
  • Adds MovedScopeSeed to OwnerRotationNet — a one-slot cache keyed by destination scope id, IPNS name, and read epoch — so the destination override seed is recovered once per root and reused across interior reseals and promotion.
  • Reworks walk_and_converge and converge_subtree to accept a caller-supplied SweptScope, letting converge_grant_subtree reuse the resume probe's parent-scope proof instead of resolving the parent name a second time.
  • Behavioral Change: GrantResumeResolver renames its moved-interior callback to resolve_moving_child with a new MovingChild return type; all in-tree implementors (OwnerRotationNet, FakeNet in create.rs, invite_mint.rs, contract.rs) are updated, but out-of-tree implementations of the old moved_interior_node trait method will break.

Macroscope summarized 7f4f13a.

…ed node

The convergence pass resolved the parent scope root a second time, after
converge_grant_subtree had already resolved it for the resume probe. The
pass now takes the proved pair from its caller, so sweep_pass keeps the
resolve and converge_subtree does not repeat it.

The resumed interior walk read every already-moved node twice: resolve_child
paid a fanout resolve, a head fetch and a decode, then dropped them and
moved_interior_node repeated all three. One seam, resolve_moving_child,
now reads the record once and classifies it against both scope ids, each
arm opening under the derivation of the scope the record claims.

The promoted root's override seed is recovered once for the whole move
instead of once per node. MovedScopeSeed holds it behind an Rc keyed on the
root's own identity, so the memo is the terminal owner and the bytes
zeroize when the slot is replaced.
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: aa63c143-5797-412f-8363-0f3bc7590c42

📥 Commits

Reviewing files that changed from the base of the PR and between d0815cb and 7f4f13a.

📒 Files selected for processing (8)
  • crates/contract/tests/contract.rs
  • crates/engine/src/facade.rs
  • crates/engine/src/grants/create.rs
  • crates/engine/src/grants/invite_mint.rs
  • crates/engine/src/grants/mod.rs
  • crates/engine/src/net/cut.rs
  • crates/engine/src/net/rotation.rs
  • crates/engine/src/rotation/sweep.rs

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


Walkthrough

Changes

Moving scope convergence

Layer / File(s) Summary
Moving child resolution
crates/engine/src/grants/create.rs, crates/engine/src/net/rotation.rs, crates/contract/tests/contract.rs, crates/engine/src/grants/invite_mint.rs
resolve_moving_child now classifies records as Pending, Moved, or ScopeRoot. Grant traversal, test doubles, and exports use MovingChild.
Moved seed cache and wiring
crates/engine/src/net/rotation.rs, crates/engine/src/net/cut.rs, crates/engine/src/facade.rs
MovedScopeSeed caches recovered override seeds. Promotion and resealing use the cache. All OwnerRotationNet constructions initialize it.
Resolved sweep entry points
crates/engine/src/rotation/sweep.rs, crates/engine/src/grants/create.rs
Sweep convergence accepts an already-resolved scope reference and SweptScope, avoiding a second scope resolve. Tests verify resolve and read counts.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant sweep_pass
  participant converge_subtree
  participant GrantResumeResolver
  participant OwnerRotationNet
  sweep_pass->>converge_subtree: pass resolved scope_ref and SweptScope
  converge_subtree->>GrantResumeResolver: resolve_moving_child(source, root, node)
  GrantResumeResolver->>OwnerRotationNet: read and classify child record
  OwnerRotationNet-->>GrantResumeResolver: MovingChild
  GrantResumeResolver-->>converge_subtree: continue, reseal, or stop traversal
Loading

Merge Risk: ⚪ Minimal · up to 7f4f1

The change has no identified merge-blocking risk in the reviewed scope.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Issue #1714 concerns the duplicate parent scope-root resolve during grant convergence. The PR also changes resumed interior-node classification and adds MovedScopeSeed memoization for override-seed … Split the moved-node read/classification changes and MovedScopeSeed changes into a separate pull request with a linked coding issue, or provide a linked issue that requires those changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 6 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #1714 requires reuse of the resolved (ChildScopeRef, SweptScope) pair and one parent-root resolve for a non-resuming grant. The change passes the resolved scope into converge_subtree and `wa…
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary performance changes: reusing one parent-scope resolution and limiting moved-node reads.
Full details: Out of Scope Changes check

Explanation

Issue #1714 concerns the duplicate parent scope-root resolve during grant convergence. The PR also changes resumed interior-node classification and adds MovedScopeSeed memoization for override-seed recovery across interior moves. These changes reduce other reads, but the linked issue does not require them and the available issue text does not connect them to the parent-root resolve fix.

Full details: Docstring Coverage

Explanation

Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 6 files. (2 skipped: 2 too large.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1714-one-parent-resolve-per-grant

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.

@FSM1

FSM1 commented Sep 15, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@FSM1
FSM1 marked this pull request as ready for review September 15, 2026 03:24
@FSM1
FSM1 merged commit d7434bb into main Sep 15, 2026
32 checks passed
@FSM1
FSM1 deleted the fix/1714-one-parent-resolve-per-grant branch September 15, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

engine: a grant resolves the parent scope root twice

1 participant