Skip to content

Conversation

@flyingrobots
Copy link
Owner

Closes #151
Closes #152

  • Parameterizes Engine.policy_id (default POLICY_ID_NO_POLICY_V0), removing magic 0u32 at the boundary.
  • Adds GraphStore reverse index (EdgeId -> from) so tick patch replay no longer scans all edge buckets.
  • Maintains edges_from invariant by pruning empty buckets (prevents history-sensitive state_root).

Validation:

  • cargo test --workspace
  • cargo clippy --workspace --all-targets -- -D warnings -D missing_docs

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

Summary by CodeRabbit

  • New Features

    • Engine initialization accepts an explicit policy identifier via new constructors for deterministic flows.
  • Performance Improvements

    • Added a reverse edge index to enable O(bucket) edge migration/removal, avoiding full-edge scans during replay and patching.
  • Documentation

    • Decision log and execution plan updated to describe policy-id plumbing, replay semantics, and edge-index-driven optimizations.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

The PR makes Engine.policy_id explicit and plumbs it through Engine constructors and commit/snapshot paths, and adds a reverse edge index (EdgeId → NodeId) to GraphStore with upsert/delete helpers to enable O(bucket) edge migration/removal during tick-patch replay.

Changes

Cohort / File(s) Summary
Policy ID Plumbing
crates/warp-core/src/constants.rs, crates/warp-core/src/engine_impl.rs
Added policy_id: u32 field to Engine; new constructors with_policy_id(...) and with_scheduler_and_policy_id(...). Existing constructors now delegate to the canonical constructor and use instance policy_id in commit/snapshot flows. Minor doc comment removals in constants.rs.
Edge Index & Graph Operations
crates/warp-core/src/ident.rs, crates/warp-core/src/graph.rs
EdgeId derives now include PartialOrd, Ord. GraphStore gains edge_index: BTreeMap<EdgeId, NodeId>. Added upsert_edge_record(...) and delete_edge_exact(...) to maintain reverse index and bucket invariants; insert/delete paths updated to use these helpers and include stronger debug assertions.
Tick Patch Integration
crates/warp-core/src/tick_patch.rs
Tick-patch apply now calls store.upsert_edge_record(...) for UpsertEdge and store.delete_edge_exact(...) for deletes; removed local remove_edge_by_id. Missing ownership causes TickPatchError::MissingEdge.
Documentation
docs/decision-log.md, docs/execution-plan.md
Added decision-log entry and updated execution plan describing explicit policy_id plumbing and the GraphStore reverse index, including rationale and impacts on patch replay/determinism.

Sequence Diagram(s)

(omitted — changes are focused on data-structure plumbing and constructor threading; control flow is localized and does not present a multi-component sequential interaction requiring diagramming)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

Policy threaded through the Engine's veins,
Edges remember where each path remains,
No forest sweep—just buckets neat and small,
Deterministic roots stand firm through all. 🎯

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title is concise, specific, and accurately summarizes the two primary changes: policy_id parameterization and edge replay index addition.
Description check ✅ Passed Description clearly relates to the changeset, citing closed issues and summarizing the core modifications with validation steps performed.
Linked Issues check ✅ Passed All code changes directly address requirements from #151 (policy_id parameterization) and #152 (edge reverse index for O(bucket_edges) replay).
Out of Scope Changes check ✅ Passed All changes are scoped to policy_id plumbing and edge index implementation; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch echo/warp-core-followups-151-152

📜 Recent review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a78256 and 1a159d3.

📒 Files selected for processing (3)
  • crates/warp-core/src/engine_impl.rs
  • crates/warp-core/src/graph.rs
  • docs/decision-log.md
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Every public API across crates (warp-core, warp-ffi, warp-wasm, etc.) must carry rustdoc comments that explain intent, invariants, and usage. Treat missing docs as a failing test.
Run cargo clippy --all-targets -- -D missing_docs before every PR; CI will expect a zero-warning, fully documented surface.
Every source file must start with exactly: // SPDX-License-Identifier: Apache-2.0 and // © James Ross Ω FLYING•ROBOTS <https://github.com/flyingrobots>

Files:

  • crates/warp-core/src/graph.rs
  • crates/warp-core/src/engine_impl.rs
🧠 Learnings (2)
📚 Learning: 2025-12-28T23:14:28.083Z
Learnt from: CR
Repo: flyingrobots/echo PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-28T23:14:28.083Z
Learning: When a PR touches non-doc code, update `docs/execution-plan.md` and `docs/decision-log.md` in the same PR.

Applied to files:

  • docs/decision-log.md
📚 Learning: 2025-12-28T23:14:28.083Z
Learnt from: CR
Repo: flyingrobots/echo PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-28T23:14:28.083Z
Learning: Applies to **/*.rs : Every public API across crates (warp-core, warp-ffi, warp-wasm, etc.) must carry rustdoc comments that explain intent, invariants, and usage. Treat missing docs as a failing test.

Applied to files:

  • crates/warp-core/src/engine_impl.rs
🧬 Code graph analysis (1)
crates/warp-core/src/engine_impl.rs (2)
crates/warp-core/src/tick_patch.rs (2)
  • new (176-206)
  • policy_id (210-212)
crates/warp-core/src/scheduler.rs (3)
  • new (39-47)
  • new (489-494)
  • new (640-646)
🔇 Additional comments (8)
docs/decision-log.md (1)

1-310: Both docs/execution-plan.md and docs/decision-log.md were updated as required.

The execution plan has a completed entry (2025-12-29 — Follow-ups: policy_id plumbing + edge replay index) with scope documenting the policy_id parameter threading and GraphStore reverse index addition, along with exit criteria and evidence. The decision log contains the corresponding entries (lines referencing 2025-12-29 in the snippet you provided). The learning requirement has been met.

crates/warp-core/src/engine_impl.rs (4)

67-72: Excellent - field documentation now complete.

The policy_id field documentation is thorough and correctly explains its role in the deterministic boundary, its inclusion in both patch_digest and commit_id v2, and references the appropriate constructor. This fully addresses the previous review feedback.


87-144: Constructor chain is well-designed and properly documented.

The delegation pattern is clean:

  • with_scheduler_and_policy_id is clearly identified as the canonical constructor
  • Convenience constructors (new, with_scheduler, with_policy_id) delegate with sensible defaults
  • All public APIs carry complete rustdoc per coding guidelines
  • The use of POLICY_ID_NO_POLICY_V0 as the default is consistently applied

The parameter documentation in the canonical constructor is particularly well done, explaining each parameter's role in the deterministic boundary.


266-322: Policy ID correctly threaded through commit path.

The plumbing is correct and complete:

  • Line 266: Captures self.policy_id early
  • Line 290: Includes in WarpTickPatchV1::new for patch digest computation
  • Line 312: Passes to compute_commit_hash_v2 for commit hash v2
  • Line 322: Stored in the resulting Snapshot

This properly replaces the previous hardcoded placeholder and ensures policy_id participates in all deterministic boundary calculations as intended.


434-456: Policy ID correctly threaded through snapshot path.

The implementation mirrors commit_with_receipt appropriately:

  • Line 434: Captures self.policy_id
  • Line 437: Includes in empty WarpTickPatchV1 construction
  • Line 445: Passes to compute_commit_hash_v2
  • Line 454: Stored in the Snapshot result

Even though no rewrites are executed, the policy_id participates in the v2 commit hash computation, maintaining consistent deterministic boundary semantics across both commit and snapshot paths.

crates/warp-core/src/graph.rs (3)

19-23: Reverse index field properly documented.

The edge_index field documentation clearly explains:

  • Its purpose as a reverse index (EdgeId → from NodeId)
  • The performance benefit (avoiding O(total_edges) scans)
  • Its use case (tick patch replay, edge migration/removal)

The pub(crate) visibility is appropriate for internal graph store bookkeeping.


60-71: Documentation improved and delegation is correct.

The updated rustdoc for insert_edge properly clarifies:

  • EdgeId uniqueness is maintained across the entire store (not just per bucket)
  • Insertion order is preserved within buckets
  • Deterministic ordering requires explicit sorting by EdgeId by callers

The delegation to upsert_edge_record is appropriate and maintains the method's public contract.


115-146: delete_edge_exact implementation is correct and handles all edge cases properly.

The method correctly implements "exact" deletion semantics:

  • Returns false if the edge doesn't exist in the reverse index (line 120-122)
  • Returns false if the edge exists but belongs to a different bucket (line 121-122)
  • Removes the edge from the bucket (line 132)
  • Updates the reverse index (line 141)
  • Prunes empty buckets to maintain the edges_from invariant (lines 142-144)

Operation order is sound: The method removes from the bucket before updating the index (lines 132, then 141). This order preserves the critical EdgeId uniqueness invariant even if the operation is interrupted—a stale index entry pointing to a removed edge is safely caught by debug assertions, whereas the reverse order could allow duplicate EdgeIds to persist.

The debug assertions (lines 125-130, 134-139) appropriately catch index/bucket consistency violations during development.


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 and usage tips.

coderabbitai[bot]
coderabbitai bot previously requested changes Dec 29, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
crates/warp-core/src/engine_impl.rs (1)

111-131: Sparse rustdoc on canonical constructor with_scheduler_and_policy_id.

This is the canonical constructor that all others delegate to. The one-liner doc does not explain intent or invariants. At minimum, document that policy_id becomes part of the deterministic boundary and that kind selects Radix vs Legacy scheduler.

🔎 Proposed fix
-    /// Constructs a new engine with explicit scheduler kind and policy id.
+    /// Constructs a new engine with explicit scheduler kind and policy identifier.
+    ///
+    /// This is the canonical constructor; all other constructors delegate here.
+    ///
+    /// # Parameters
+    /// - `store`: backing graph store
+    /// - `root`: root node id for snapshot hashing
+    /// - `kind`: scheduler variant (Radix or Legacy)
+    /// - `policy_id`: policy identifier committed into `patch_digest` and `commit_id` v2
     pub fn with_scheduler_and_policy_id(
crates/warp-core/src/graph.rs (1)

60-67: Semantic change not reflected in rustdoc: insert_edge now upserts.

The previous insert_edge allowed duplicate EdgeIds across buckets. Now it delegates to upsert_edge_record, which enforces EdgeId uniqueness and removes any prior edge with the same id. The rustdoc still says "Inserts a directed edge" without mentioning the upsert/uniqueness semantics.

Update the doc to reflect the new behavior.

🔎 Proposed fix
-    /// Inserts a directed edge into the store in insertion order.
+    /// Inserts or replaces a directed edge in the store.
     ///
-    /// Ordering note: The underlying vector preserves insertion order. When
-    /// deterministic ordering is required (e.g., snapshot hashing), callers
-    /// must sort by `EdgeId` explicitly.
+    /// If an edge with the same `EdgeId` already exists (in any bucket), the old
+    /// edge is removed before inserting the new one. This maintains `EdgeId`
+    /// uniqueness across the entire store.
+    ///
+    /// Ordering note: Edges within a bucket preserve insertion order. When
+    /// deterministic ordering is required (e.g., snapshot hashing), callers must
+    /// sort by `EdgeId` explicitly.
     pub fn insert_edge(&mut self, from: NodeId, edge: EdgeRecord) {
         self.upsert_edge_record(from, edge);
     }
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e6cf90 and 8a78256.

📒 Files selected for processing (7)
  • crates/warp-core/src/constants.rs
  • crates/warp-core/src/engine_impl.rs
  • crates/warp-core/src/graph.rs
  • crates/warp-core/src/ident.rs
  • crates/warp-core/src/tick_patch.rs
  • docs/decision-log.md
  • docs/execution-plan.md
💤 Files with no reviewable changes (1)
  • crates/warp-core/src/constants.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Every public API across crates (warp-core, warp-ffi, warp-wasm, etc.) must carry rustdoc comments that explain intent, invariants, and usage. Treat missing docs as a failing test.
Run cargo clippy --all-targets -- -D missing_docs before every PR; CI will expect a zero-warning, fully documented surface.
Every source file must start with exactly: // SPDX-License-Identifier: Apache-2.0 and // © James Ross Ω FLYING•ROBOTS <https://github.com/flyingrobots>

Files:

  • crates/warp-core/src/ident.rs
  • crates/warp-core/src/engine_impl.rs
  • crates/warp-core/src/tick_patch.rs
  • crates/warp-core/src/graph.rs
🧠 Learnings (1)
📚 Learning: 2025-12-28T23:14:28.083Z
Learnt from: CR
Repo: flyingrobots/echo PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-28T23:14:28.083Z
Learning: Start each session by updating *Today's Intent* in `docs/execution-plan.md` and capture milestones, blockers, and decisions in the Decision Log.

Applied to files:

  • docs/execution-plan.md
🧬 Code graph analysis (1)
crates/warp-core/src/engine_impl.rs (1)
crates/warp-core/src/tick_patch.rs (2)
  • new (176-206)
  • policy_id (210-212)
🔇 Additional comments (8)
docs/decision-log.md (1)

302-313: LGTM — Detailed decision entry is well-structured.

The expanded entry at lines 302-313 provides essential context (prior O(total_edges) scan, hardcoded policy_id), explicit decisions with rationale, and clearly stated consequences. This is the canonical format future entries should follow.

crates/warp-core/src/ident.rs (1)

25-26: LGTM — EdgeId ordering enables BTreeMap keying.

The derived PartialOrd and Ord for EdgeId use lexicographic byte comparison over the inner [u8; 32], which is deterministic and consistent with NodeId's existing derives. This unblocks the edge_index: BTreeMap<EdgeId, NodeId> in GraphStore.

crates/warp-core/src/tick_patch.rs (1)

269-276: LGTM — Clean delegation to GraphStore primitives.

The UpsertEdge and DeleteEdge arms now delegate to upsert_edge_record and delete_edge_exact respectively, eliminating the O(total_edges) scan. Error handling for missing edges is preserved.

crates/warp-core/src/engine_impl.rs (1)

253-253: LGTM — policy_id threading is consistent.

Both commit_with_receipt (line 253) and snapshot (line 421) extract self.policy_id and thread it through patch construction and commit hashing. No hardcoded constants leak into the commit paths.

Also applies to: 421-421

crates/warp-core/src/graph.rs (3)

19-23: LGTM — Reverse index field is well-documented.

The edge_index field has clear rustdoc explaining its purpose (efficient edge migration/removal by id) and its role in avoiding O(total_edges) scans.


115-142: LGTM — delete_edge_exact correctly validates ownership before deletion.

The ownership check at lines 116-119 ensures the edge belongs to the specified from bucket before removal. The invariant that edge_index and edges_from stay consistent is maintained by pruning empty buckets and removing the index entry together.


13-24: LGTM — Default and Clone derives remain correct with new field.

The derived Default initializes edge_index to an empty BTreeMap, and Clone clones all three maps. Both are required for the commit path's store_before.clone() capture.

docs/execution-plan.md (1)

38-44: LGTM — Today's Intent accurately captures the completed work.

Exit criteria (cargo test + clippy gates) and evidence (Engine constructors, reverse index usage) are explicit and verifiable. The scope description matches the PR objectives.

@flyingrobots
Copy link
Owner Author

@coderabbitai addressed the requested changes in 1a159d3:

Please re-review / update review state when you get a chance.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

@flyingrobots — Acknowledged. I see you've explicitly addressed:

  • Rustdoc for Engine.policy_id and expanded constructor documentation
  • GraphStore::insert_edge documentation updates for upsert semantics
  • Cleanup of duplicate decision-log entries

I will conduct a full re-review of the PR now to verify these improvements and assess the overall implementation against the strictest standards. Expect no mercy — every line will be scrutinized.

Stand by.


🧠 Learnings used
Learnt from: CR
Repo: flyingrobots/echo PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-28T23:14:28.083Z
Learning: When a PR touches non-doc code, update `docs/execution-plan.md` and `docs/decision-log.md` in the same PR.
✅ Actions performed

Review triggered.

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.

@flyingrobots flyingrobots dismissed coderabbitai[bot]’s stale review December 29, 2025 16:10

Addressed requested changes in 1a159d3 (rustdoc + decision-log cleanup). Dismissing bot review to unblock merge.

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.

warp-core: edge reverse index for tick patch replay warp-core: parameterize policy_id (Aion policy semantics)

2 participants