-
Notifications
You must be signed in to change notification settings - Fork 1
feat(geom): BroadPhase + AabbTree (split PR 3) #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…\n- Adds trait and O(n^2) reference implementation\n- Deterministic canonical pair ordering\n- Unit tests (fat AABB pair order, basic cases)\n\nExtracted from branch echo/geom-broad-phase-docs-smoke.
|
Warning Rate limit exceeded@flyingrobots has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 6 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (13)
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Summary by CodeRabbitRelease Notes
WalkthroughAdds a deterministic broad-phase API and a baseline AABB-based implementation (O(n²) all-pairs), renames a temporal proxy type, adds unit tests, and introduces related design and toolchain documentation and CI/toolchain updates. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant AabbTree
participant Storage as BTreeMap
Client->>AabbTree: upsert(id, aabb)
AabbTree->>Storage: insert/update (id → aabb)
Client->>AabbTree: pairs()
AabbTree->>Storage: collect items -> Vec<(id,aabb)>
Note over AabbTree: iterate all combinations (O(n²))
AabbTree->>AabbTree: test overlap (inclusive faces)
AabbTree->>AabbTree: canonicalize (min,max) and collect
AabbTree->>AabbTree: sort lexicographically
AabbTree-->>Client: Vec<(min_id, max_id)>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…H replacement\n\n- Add determinism/perf notes to AabbTree and broad module docs\n- Clarify canonical pair ordering and inclusive face-touch semantics
… pub mod broad; update tests to temporal::timespan::Timespan; fmt
…al::manifold::PositionProxy → temporal::manifold::SweepProxy\n- crate docs and execution plan mention Timespan + SweepProxy\n- rustfmt + clippy pedantic satisfied
…agrams, time braids, and deterministic kinematics)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (8)
crates/rmg-geom/src/broad/aabb_tree.rs(1 hunks)crates/rmg-geom/src/broad/mod.rs(1 hunks)crates/rmg-geom/src/lib.rs(2 hunks)crates/rmg-geom/src/temporal/manifold.rs(1 hunks)crates/rmg-geom/tests/geom_broad_tests.rs(1 hunks)docs/execution-plan.md(1 hunks)docs/spec-knots-in-time.md(1 hunks)docs/spec-timecube.md(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/rmg-geom/tests/geom_broad_tests.rs (2)
crates/rmg-geom/src/types/aabb.rs (3)
from_center_half_extents(54-57)min(42-44)max(48-50)crates/rmg-geom/src/broad/aabb_tree.rs (3)
new(52-56)pairs(16-16)pairs(68-84)
🪛 GitHub Actions: CI
crates/rmg-geom/tests/geom_broad_tests.rs
[error] 1-1: missing documentation for the crate.
[error] 1-1: could not compile rmg-geom (test "geom_broad_tests") due to 1 previous error
crates/rmg-geom/src/temporal/manifold.rs
[error] 1-1: could not compile rmg-geom (test "geom_broad_tests") due to 1 previous error
crates/rmg-geom/src/broad/aabb_tree.rs
[error] 1-1: could not compile rmg-geom (test "geom_broad_tests") due to 1 previous error
crates/rmg-geom/src/broad/mod.rs
[error] 1-1: could not compile rmg-geom (test "geom_broad_tests") due to 1 previous error
crates/rmg-geom/src/lib.rs
[error] 1-1: could not compile rmg-geom (test "geom_broad_tests") due to 1 previous error
🪛 LanguageTool
docs/spec-timecube.md
[grammar] ~49-~49: Ensure spelling is correct
Context: ...nto that state from a different path. - Merges are explicit (2+ parents) with recorded...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
docs/spec-knots-in-time.md
[grammar] ~69-~69: Ensure spelling is correct
Context: ...ervative hull of start/end world AABBs (determinstic and fast); refine later if needed 4) Ka...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🪛 markdownlint-cli2 (0.18.1)
docs/spec-timecube.md
82-82: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
100-100: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
docs/spec-knots-in-time.md
82-82: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
100-100: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🔇 Additional comments (18)
docs/execution-plan.md (1)
52-52: Documentation updated to match the renamed types.The reference to
TimespanandSweepProxycorrectly reflects the code changes.crates/rmg-geom/src/lib.rs (2)
16-17: Documentation updated correctly.The crate-level docs now mention temporal utilities and broad-phase correctly.
25-26: Everything checks out. The broad module addition is correct.Module files exist, re-exports are properly configured in
broad/mod.rs, and the module tree is complete. No structural issues. Code is ready to merge.BunBun
crates/rmg-geom/tests/geom_broad_tests.rs (4)
6-21: Test logic for swept AABB looks correct.The test verifies that a fat AABB computed from a
Timespancorrectly bounds the start and end poses. The math checks out:
- Unit cube at origin:
[-1, -1, -1]to[1, 1, 1]- Translated +10 on X:
[9, -1, -1]to[11, 1, 1]- Hull (fat AABB):
[-1, -1, -1]to[11, 1, 1]The test correctly verifies min and max extents.
23-45: Deterministic pair ordering test is solid.The test:
- Inserts AABBs out of order (2, 1, 0) to verify determinism
- Checks that only overlapping pairs are returned:
(0,1)- Adds another overlapping box (3) and verifies canonical ordering:
(0,1), (0,3), (1,3)This thoroughly exercises the BroadPhase trait's deterministic ordering guarantee. The expected pairs are correct based on the AABB positions.
However, the test will never run until you fix the compilation errors. Get your act together.
BunBun
2-2: The import path is valid and correct. No issues found.The module structure is exactly as it should be:
crates/rmg-geom/src/broad/mod.rsproperly re-exportsaabb_treeaspub mod- Both
BroadPhase(trait) andAabbTree(struct) are public inaabb_tree.rsYour speculative concern was unfounded. The import will compile without errors. Stop worrying about phantom issues and move on.
BunBun
1-5: CRITICAL: Missing crate-level documentation breaks compilation.Your
#![deny(missing_docs)]inlib.rsapplies to the entire crate, including test integration files. This test file has NO crate-level doc comment, causing the pipeline to explode with "missing documentation for the crate."Add a crate doc at the top:
+//! Integration tests for rmg-geom broad-phase collision detection. + use rmg_core::math::{Quat, Vec3}; use rmg_geom::broad::aabb_tree::{AabbTree, BroadPhase};This is a blocking compilation error. How did you not catch this locally? Did you even run
cargo testbefore pushing?BunBun
Likely an incorrect or invalid review comment.
crates/rmg-geom/src/broad/mod.rs (2)
1-10: Excellent documentation of the determinism contract.The module docs clearly specify:
- Pair identity canonicalization:
(min_id, max_id)- Lexicographic sorting of the pair list
- Inclusive face overlap semantics
This sets clear expectations for implementers and users. The note about replacing
AabbTreewith Sweep-and-Prune is useful context.
12-13: Verification complete: visibility is correct, re-export works as intended.Both
pub trait BroadPhase(line 10) andpub struct AabbTree(line 45) are public inaabb_tree.rs. Thepub mod aabb_tree;re-export inbroad/mod.rsmakes them accessible viarmg_geom::broad::aabb_tree::{AabbTree, BroadPhase}. The code is correct. If compilation is still failing, the issue lies elsewhere—not with this module structure.BunBun
docs/spec-timecube.md (2)
1-46: TimeCube architectural spec is comprehensive.The document clearly defines:
- The three temporal axes (Chronos, Kairos, Aion)
- Merkle-based snapshot structure with
SnapshotHeaderandSnapshotPayload- Content-addressed identity guarantees
This provides solid architectural foundation for the broad-phase implementation.
69-69: Typo: "determinstic" should be "deterministic".Line 69 has a spelling error that static analysis caught.
Apply this fix:
- - With rotation: we use a conservative bound (AABB hull of start/end) to remain deterministic and fast; narrow‑phase can refine later. + - With rotation: we use a conservative bound (AABB hull of start/end) to remain deterministic and fast; narrow‑phase can refine later.Wait, that's the same text. Let me check the actual line... Line 69 has "determinstic" (missing the second 'i'). Fix it.
BunBun
Likely an incorrect or invalid review comment.
crates/rmg-geom/src/broad/aabb_tree.rs (4)
5-17: BroadPhase trait definition is clean and well-documented.The trait clearly specifies:
upsertfor insertion/updatesremovefor deletionpairsfor querying overlapping pairs with deterministic orderingThe contract is explicit and matches the module-level documentation.
Verify this trait is actually
pub:#!/bin/bash # Confirm BroadPhase is public rg -n '^pub trait BroadPhase' crates/rmg-geom/src/broad/aabb_tree.rsIf it's not public, the test imports will fail (which explains your compilation error).
BunBun
19-47: Outstanding documentation of the implementation trade-offs.The doc comment:
- Explains why
O(n²)is acceptable for a baseline- Outlines the future plan (Sweep-and-Prune, Dynamic AABB Tree)
- Notes that all broad phases degenerate to
O(n²)when everything overlaps- Includes a clear TODO with context
This is exactly how temporary code should be documented. You're setting clear expectations for future maintainers.
44-57: AabbTree struct and constructor are straightforward.Using
BTreeMap<usize, Aabb>provides deterministic iteration order by key, which is essential for the determinism guarantees. The#[derive(Default)]and explicitnew()constructor are both present—good.But again, verify visibility:
#!/bin/bash # Confirm AabbTree is public rg -n '^pub struct AabbTree' crates/rmg-geom/src/broad/aabb_tree.rsBunBun
59-66: upsert and remove implementations are trivial and correct.Direct delegation to
BTreeMap::insertandBTreeMap::remove. No issues here.docs/spec-knots-in-time.md (2)
1-41: Knot theory integration spec is fascinating and well-structured.The document clearly outlines:
- Knot diagrams as typed graphs with Reidemeister moves as DPO rewrites
- Invariants computed as deterministic folds
- Integration with the TimeCube architecture
This is ambitious but well-reasoned. The connection to Echo's rewrite engine is clear.
76-86: Merkle-based determinism section is solid.The explanation of how commits as Merkle nodes guarantee identical folds across peers is clear and correct. This aligns with the TimeCube spec.
crates/rmg-geom/src/temporal/manifold.rs (1)
4-14: ---Rename verified clean—all
PositionProxyreferences eliminated.Ripgrep scan across all Rust files confirms zero lingering references to the old identifier. The
SweepProxyrename is complete, no stragglers. The semantic improvement is solid and properly propagated throughout.
BunBun
…parity for no-op; tx lifecycle + rule dup checks; tests tightened\n\n- Snapshot now includes parents + plan/decision/rewrites digests; commit hash binds provenance\n- Engine::commit computes state_root + digests; Engine::snapshot uses canonical empty digests\n- Track live txs; error on closed/zero tx; begin() #[must_use]\n- Reject duplicate rule names and ids; assign compact rule ids for execute path\n- Scheduler stays crate-private; ordering invariant documented\n- Tests: velocity preservation; NoMatch commit is no-op; mat4 right-hand mul; rotation rel. tol; vec3 negative scalar\n- Docs: execution plan + decision log updated for 2025-10-29
… devcontainer installs both; wasm crate rust-version=1.71; pre-push runs workspace on default and MSRV for core+geom; docs updated
…cross crates; align CI/devcontainer/hooks/docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 10
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
CONTRIBUTING.mdis excluded by!*.md
📒 Files selected for processing (14)
.devcontainer/post-create.sh(1 hunks).githooks/pre-commit(1 hunks).githooks/pre-push(2 hunks).github/workflows/ci.yml(5 hunks)crates/rmg-cli/Cargo.toml(1 hunks)crates/rmg-core/Cargo.toml(1 hunks)crates/rmg-core/src/engine_impl.rs(4 hunks)crates/rmg-core/src/snapshot.rs(2 hunks)crates/rmg-ffi/Cargo.toml(1 hunks)crates/rmg-ffi/README.md(1 hunks)crates/rmg-wasm/Cargo.toml(1 hunks)docs/decision-log.md(1 hunks)docs/execution-plan.md(2 hunks)rust-toolchain.toml(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
crates/rmg-core/src/snapshot.rs (1)
crates/rmg-core/src/engine_impl.rs (1)
new(71-84)
crates/rmg-core/src/engine_impl.rs (1)
crates/rmg-core/src/snapshot.rs (2)
compute_commit_hash(140-161)compute_state_root(135-137)
🔇 Additional comments (20)
crates/rmg-ffi/README.md (1)
9-10: Align automation with stated MSRV.Docs claim MSRV 1.68.0 for core libs; ensure pre-push/CI actually test rmg-core and rmg-geom on 1.68.0, not 1.71.1. As per execution plan and hooks.
docs/execution-plan.md (2)
51-55: Verify all tooling actually enforces 1.71.1 as floor.Double‑check that devcontainer, CI, and hooks read rust-toolchain.toml and don’t carry stale pins elsewhere. I can script a check if needed.
65-69: Audit rename fallout (TemporalTransform→Timespan, TemporalProxy→SweepProxy).Run a repo‑wide grep to ensure no stragglers in code/docs/tests remain. I can wire a script if you want.
.githooks/pre-push (1)
18-26: Workspace checks on default toolchain: good.fmt/clippy/test against default is the right fast path before MSRV runs.
crates/rmg-cli/Cargo.toml (1)
5-5: LGTM on rust-version bump.Consistent with repo floor at 1.71.1.
crates/rmg-ffi/Cargo.toml (1)
5-5: LGTM - Toolchain bump is straightforward.The rust-version bump to 1.71.1 aligns with the repository-wide toolchain update. No issues here.
BunBun
rust-toolchain.toml (1)
2-2: Toolchain pinned to 1.71.1 - looks good.The channel update is clean. Pinning to a specific patch version (1.71.1) rather than a minor version (1.71) is the right call for reproducibility.
BunBun
crates/rmg-core/Cargo.toml (1)
5-5: Another clean MSRV bump.Consistent with the workspace-wide upgrade. No complaints.
BunBun
crates/rmg-wasm/Cargo.toml (1)
5-5: WASM crate MSRV updated consistently.All manifest updates follow the same pattern. Good.
BunBun
.github/workflows/ci.yml (2)
58-59: Workspace-level testing is the right move.Good change from individual
cargo testtocargo test --workspace. This ensures all workspace members are tested consistently.BunBun
96-110: ---The rmg-geom crate exists—your concern was based on incomplete information.
rmg-geomis present atcrates/rmg-geom/Cargo.toml(version 0.1.0). This confirms scenario 1: the crate already exists (from PR #8), and this PR is correctly updating the CI to test it alongsidermg-core. The Floor job changes are legitimate—no issue here.BunBun
.devcontainer/post-create.sh (1)
10-14: Devcontainer setup is clean.Good that you're installing the 1.71.1 toolchain explicitly and letting rust-toolchain.toml control the default. The minimal profile keeps the image lean. The
|| trueguards on component/target installation are appropriate for non-critical additions.BunBun
docs/decision-log.md (1)
53-56: Toolchain decision documented.Short and to the point. Good.
BunBun
crates/rmg-core/src/engine_impl.rs (5)
12-12: Import changes match the new hashing strategy.You've replaced the old
compute_snapshot_hashwithcompute_state_rootandcompute_commit_hash. The imports are consistent with the refactored snapshot logic.BunBun
205-214: Rewrites digest captures the actual execution plan.Good that you're including the concrete
scope.0(NodeId) in the rewrites digest, not just the scope_hash. This makes the digest more specific and ties it to the actual graph nodes that will be modified.The distinction between plan_digest (intent) and rewrites_digest (actual reserved execution) is architecturally sound, assuming you plan to use these for replay/audit.
BunBun
241-250: Snapshot struct populated correctly.All the new fields (parents, plan_digest, decision_digest, rewrites_digest, policy_id) are properly initialized with either computed values or documented placeholders. No issues here.
BunBun
261-288: Digest semantics are intentional and fully documented—no issue here.The original concern about mixing
zerovs.empty_digestrepresentations was worth exploring, but verification confirms this is deliberate design, not a bug.The distinction is documented across three sources:
- execution-plan.md (2025-10-29): "
decision_digest(Aion; zero for now)" contrasted with "plan_digest(ready‑set ordering; empty = blake3(len=0))"- decision-log.md (2025-10-29): "Keep
decision_digest = 0until Aion/agency lands"- engine_impl.rs inline comments (line 233): "No Aion decisions yet; placeholder zero digest"
The semantics are sound:
decision_digest = [0u8; 32]→ "no Aion decisions applied" (structural placeholder)plan_digest = blake3(0),rewrites_digest = blake3(0)→ "empty inputs" (content hashes)Both
commit()(line 233) andsnapshot()(line 284) correctly use raw zero for decision_digest because Aion is not yet implemented. When agency lands,decision_digestwill be populated with a proper hash of Aion inputs while maintaining this same structure.The code is correct and consistent. No action needed.
185-195: ---Discard this review comment entirely.
The scheduler's
drain_for_txfunction explicitly documents its contract: "Removes and returns all pending rewrites fortx, ordered by(scope_hash, rule_id)in ascending lexicographic order. This ordering is stable across platforms and runs and is enforced before returning the pending queue to callers."The code you're reviewing correctly uses this documented guarantee. The ordering enforcement is not engine_impl's responsibility—it's the scheduler's. The plan_digest correctly hashes over (scope_hash, rule_id) in the order the scheduler guarantees. There is nothing to verify or fix here.
BunBun
Likely an incorrect or invalid review comment.
crates/rmg-core/src/snapshot.rs (2)
133-137: From: Linus Torvalds torvalds@linux-foundation.org
To: flyingrobots flyingrobots@users.noreply.github.com
Cc: code-rabbit@vger.kernel.orgcompute_state_root wrapper is fine.
Good separation of concerns; aligns with the docs once you fix them.
BunBun
139-161: From: Linus Torvalds torvalds@linux-foundation.org
To: flyingrobots flyingrobots@users.noreply.github.com
Cc: code-rabbit@vger.kernel.orgFundamentally broken review—Hash is a type alias, not a newtype struct.
The comment completely misses what it's looking at. Hash is defined as
pub type Hash = [u8; 32];in ident.rs—a TYPE ALIAS, not a struct newtype. So all those.0suggestions? Dead wrong.h.update()works perfectly fine as-is because[u8; 32]derefs to&[u8]automatically.More critically: the suggested
policy_id: u32parameter doesn't exist in either call site. Adding it breaks the build. Both engine_impl.rs call sites would fail to compile.That said, the underlying concern about parent ordering has merit IF you ever support multiple parents. Right now both call sites produce either a single parent or an empty vec, so it's not urgent. But for defensive programming and future-proofing:
pub(crate) fn compute_commit_hash( state_root: &Hash, parents: &[Hash], plan_digest: &Hash, decision_digest: &Hash, rewrites_digest: &Hash, ) -> Hash { let mut h = Hasher::new(); // Version tag for future evolution. h.update(&1u16.to_le_bytes()); // Parents (length + raw bytes) + // Sort parents for determinism (handles future multi-parent scenarios). + let mut parents_sorted: Vec<&Hash> = parents.iter().collect(); + parents_sorted.sort_unstable(); h.update(&(parents_sorted.len() as u64).to_le_bytes()); - for p in parents { + for p in parents_sorted { h.update(p); } // State root and metadata digests h.update(state_root); h.update(plan_digest); h.update(decision_digest); h.update(rewrites_digest); h.finalize().into() }Drop the phantom
policy_idnonsense. Skip the.0theater.BunBun
Likely an incorrect or invalid review comment.
… and snapshot(); fix doc lints
…wer rust-version; refine skip logic
Extracted from closed PR #6.\n\nScope\n- BroadPhase trait\n- AabbTree reference implementation with canonical pair ordering\n- Unit tests\n\nNotes\n- Documents O(n^2) scaling and TODO to replace with DynamicAabbTree in Phase 1.\n- Depends on PR 2 (rmg-geom foundation).