-
Notifications
You must be signed in to change notification settings - Fork 1
Core: add deterministic math module #4
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
Summary by CodeRabbit
WalkthroughAdds a deterministic math module (scalars, Vec3, Mat4, Quat, Prng) and exports it from lib.rs; adds JSON fixtures and a fixture-driven Rust test harness; adds dev-dependencies for test fixtures; updates execution plan and decision log docs. Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Harness
participant Fixture as JSON Fixture
participant Math as rmg_core::math
participant Assert as Assertion
Note over Test,Fixture: Load and deserialize fixtures at test startup
Test->>Fixture: read fixtures (serde_json)
Fixture-->>Test: structured fixture data
loop per fixture case
Test->>Math: call operation (clamp / deg_to_rad / Vec3 / Mat4 / Quat / Prng)
Math-->>Test: computed result (f32 / arrays / sequences)
Test->>Assert: compare result vs expected within tolerance
Assert-->>Test: pass / fail
end
alt failure
Note over Test: test runner reports failure with details
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (4)
🧰 Additional context used📓 Path-based instructions (3)docs/execution-plan.md📄 CodeRabbit inference engine (AGENTS.md)
Files:
docs/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.rs📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2025-10-26T02:42:44.664ZApplied to files:
🧬 Code graph analysis (1)crates/rmg-core/tests/math_validation.rs (1)
🔇 Additional comments (22)
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.
Actionable comments posted: 10
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (6)
crates/rmg-core/Cargo.toml(1 hunks)crates/rmg-core/src/lib.rs(1 hunks)crates/rmg-core/src/math.rs(1 hunks)crates/rmg-core/tests/fixtures/math-fixtures.json(1 hunks)crates/rmg-core/tests/math_validation.rs(1 hunks)docs/execution-plan.md(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Public Rust APIs must have rustdoc comments explaining intent, invariants, and usage; treat missing docs as a failing test
Files:
crates/rmg-core/src/lib.rscrates/rmg-core/tests/math_validation.rscrates/rmg-core/src/math.rs
🧠 Learnings (1)
📚 Learning: 2025-10-25T13:22:15.193Z
Learnt from: CR
PR: flyingrobots/echo#0
File: AGENTS.md:0-0
Timestamp: 2025-10-25T13:22:15.193Z
Learning: Use Neo4j threads: echo-devlog for daily journal/decisions/blockers and echo-spec for high-level proposals
Applied to files:
docs/execution-plan.md
🧬 Code graph analysis (1)
crates/rmg-core/tests/math_validation.rs (1)
crates/rmg-core/src/math.rs (11)
new(35-37)new(122-124)new(179-181)clamp(12-15)deg_to_rad(18-20)rad_to_deg(23-25)from(109-111)from(166-168)from(290-292)from_axis_angle(193-204)from_seed(303-309)
🔇 Additional comments (7)
crates/rmg-core/src/lib.rs (1)
14-15: Export looks fine. Don’t ship undocumented public APIs.You’ve got
#![deny(missing_docs)]. Ensure every public item inmathhas rustdoc with intent/invariants, or this will fail builds.crates/rmg-core/Cargo.toml (1)
11-14: Fix missing toolchain pinning and MSRV, but edition = "2024" is valid.The Rust 2024 edition is valid and won't break CI. However, add a
rust-toolchain.tomlfile to pin the toolchain version, and addrust-versiontoCargo.tomlto specify the MSRV. This prevents unintended compiler version drift and ensures reproducible builds. The dev-dependencies are fine as-is.crates/rmg-core/tests/math_validation.rs (5)
176-192: Fine, this one's acceptable.Straightforward fixture-driven test. The logic is sound. Not much to screw up here.
236-251: Naming inconsistency, but I'll allow it.The fixture is called
transform_vec3but you're callingtransform_point. I assume that's the actual API name, so fine. But this is the kind of inconsistency that makes code harder to understand.
253-279: This is fine.Straightforward fixture validation. No issues here.
11-144: Where's the documentation?Yeah, I see these are test-internal structs, not public APIs, so the rustdoc guideline doesn't technically apply. But you've got 130+ lines of data structures with ZERO explanation of what they represent or how they map to the fixture format.
The
FixtureValueenum with#[serde(untagged)]is particularly clever, but good luck to the next person trying to understand why some fixtures need scalars and others need vectors without reading through the entire test suite.Add at least a module-level doc comment explaining the fixture structure.
⛔ Skipped due to learnings
Learnt from: CR PR: flyingrobots/echo#0 File: AGENTS.md:0-0 Timestamp: 2025-10-25T13:22:15.193Z Learning: Applies to **/*.rs : Public Rust APIs must have rustdoc comments explaining intent, invariants, and usage; treat missing docs as a failing test
146-146: Remove this review comment—it's based on a fundamental misunderstanding of how fixture-based tests work.These aren't algorithmic tests that compute values subject to floating-point accumulation errors across different platforms. These are fixture-based regression tests: the expected values are hardcoded in JSON and loaded at compile time. The implementation either matches the fixture within 1e-6 or it doesn't. The epsilon doesn't need to account for "accumulated error across platforms" because there's no computation happening across platforms—just IEEE 754-compliant floating-point comparisons.
The fixture precision itself is ~7 decimal places (see
0.70710677in the JSON), so 1e-6 tolerance is explicitly calibrated to that, not arbitrary. That choice is sound and will be deterministic on any system that respects IEEE 754, which is every modern architecture.If you want to criticize something, criticize the lack of CI/CD infrastructure or the absence of documentation about where the fixtures came from—but don't imply the epsilon is a ticking time bomb on different platforms when the entire test structure prevents that problem.
Likely an incorrect or invalid review 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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/execution-plan.md (1)
89-95: ---Decision log violates reverse-chronological ordering—exact fix required.
The table is currently oldest-first (2025-10-23 through 2025-10-26), but you need newest-first. Your 2025-10-26 entry sits before a 2025-10-25 entry on line 95, which breaks the ordering you committed to. Reorder the entire table so 2025-10-26 entries come first, then both 2025-10-25 entries (they're separate decisions), then 10-24, then 10-23. A decision log that can't maintain basic chronology isn't a log—it's noise.
| Date | Decision | Context | Follow-up | | ---- | -------- | ------- | --------- | +| 2025-10-26 | Adopt RMG + Confluence as core architecture | RMG v2 (typed DPOi engine) + Confluence replication baseline | Scaffold rmg-core/ffi/wasm/cli crates; implement rewrite executor spike; integrate Rust CI; migrate TS prototype to `/reference` | +| 2025-10-25 | Math validation fixtures & Rust test harness | Established deterministic scalar/vector/matrix/quaternion/PRNG coverage in rmg-core | Extend coverage to browser environments and fixed-point mode | | 2025-10-25 | Language direction pivot: Echo core to Rust | TypeScript validated specs; long-term determinism enforced via Rust + C ABI + Lua scripting | Update Phase 1 backlog: scaffold Rust workspace, port ECS/diff engine, FFI bindings | | 2025-10-24 | Branch tree spec v0.1: roaring bitmaps, chunk epochs, content-addressed IDs | Feedback loop to handle deterministic merges | Implement roaring bitmap integration | | 2025-10-23 | Monorepo seeded with pnpm & TypeScript skeleton | Baseline repo reset from Caverns to Echo | Implement Phase 0 specs | -| 2025-10-26 | Adopt RMG + Confluence as core architecture | RMG v2 (typed DPOi engine) + Confluence replication baseline | Scaffold rmg-core/ffi/wasm/cli crates; implement rewrite executor spike; integrate Rust CI; migrate TS prototype to `/reference` | -| 2025-10-25 | Math validation fixtures & Rust test harness | Established deterministic scalar/vector/matrix/quaternion/PRNG coverage in rmg-core | Extend coverage to browser environments and fixed-point mode |BunBun
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
docs/execution-plan.md(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
docs/execution-plan.md
📄 CodeRabbit inference engine (AGENTS.md)
Start each work session by updating Today’s Intent in docs/execution-plan.md
Files:
docs/execution-plan.md
docs/**
📄 CodeRabbit inference engine (AGENTS.md)
Document meaningful design choices in the docs/ directory (specs, diagrams, memorials) and keep impacted docs in sync with code changes
Files:
docs/execution-plan.md
🧠 Learnings (2)
📚 Learning: 2025-10-26T02:42:44.664Z
Learnt from: CR
PR: flyingrobots/echo#0
File: AGENTS.md:0-0
Timestamp: 2025-10-26T02:42:44.664Z
Learning: Applies to docs/execution-plan.md : Start each work session by updating Today’s Intent in docs/execution-plan.md
Applied to files:
docs/execution-plan.md
📚 Learning: 2025-10-26T02:42:44.664Z
Learnt from: CR
PR: flyingrobots/echo#0
File: AGENTS.md:0-0
Timestamp: 2025-10-26T02:42:44.664Z
Learning: Applies to docs/decision-log.md : Record milestones, blockers, decisions, outcomes, and next steps in docs/decision-log.md
Applied to files:
docs/execution-plan.md
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: 7
♻️ Duplicate comments (2)
crates/rmg-core/tests/fixtures/math-fixtures.json (1)
2-5: Good—you finally added tolerances. Tests might now stop flaking across libm/CPU.Exactly what was requested previously. Keep this consistent with the harness. BunBun
crates/rmg-core/tests/math_validation.rs (1)
458-470: Decoupling PRNG int tests from float count is the correct fix.Re-seeding for ints kills hidden state coupling. This prevents “works on my JSON” fragility. BunBun
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
crates/rmg-core/src/math.rs(1 hunks)crates/rmg-core/tests/fixtures/math-fixtures.json(1 hunks)crates/rmg-core/tests/math_validation.rs(1 hunks)docs/execution-plan.md(3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Public Rust APIs across crates (e.g., rmg-core, rmg-ffi, rmg-wasm) must include rustdoc comments explaining intent, invariants, and usage
Files:
crates/rmg-core/tests/math_validation.rscrates/rmg-core/src/math.rs
docs/execution-plan.md
📄 CodeRabbit inference engine (AGENTS.md)
Start each work session by updating Today’s Intent in docs/execution-plan.md
Files:
docs/execution-plan.md
docs/**
📄 CodeRabbit inference engine (AGENTS.md)
Document meaningful design choices in the docs/ directory (specs, diagrams, memorials) and keep impacted docs in sync with code changes
Files:
docs/execution-plan.md
🧠 Learnings (1)
📚 Learning: 2025-10-26T02:42:44.664Z
Learnt from: CR
PR: flyingrobots/echo#0
File: AGENTS.md:0-0
Timestamp: 2025-10-26T02:42:44.664Z
Learning: Applies to docs/decision-log.md : Record milestones, blockers, decisions, outcomes, and next steps in docs/decision-log.md
Applied to files:
docs/execution-plan.md
🧬 Code graph analysis (1)
crates/rmg-core/tests/math_validation.rs (1)
crates/rmg-core/src/math.rs (11)
new(35-37)new(127-129)new(197-199)clamp(12-15)deg_to_rad(18-20)rad_to_deg(23-25)from(114-116)from(184-186)from(313-315)from_axis_angle(211-227)from_seed(326-332)
🪛 markdownlint-cli2 (0.18.1)
docs/execution-plan.md
101-101: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
112-112: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🔇 Additional comments (4)
crates/rmg-core/tests/math_validation.rs (3)
9-14: Finally, an error that tells humans what exploded. Keep this standard.Parsing now panics with file path and serde error. This is the minimum bar. BunBun
28-50: Good: fixture sanity checks prevent “green” tests with zero coverage.This closes a common footgun. Keep extending as new sections appear. BunBun
331-346: Type-mismatch panics now point to the exact offender. About time.Including indices and values saves hours of binary searching the JSON. BunBun
Also applies to: 348-363
crates/rmg-core/src/math.rs (1)
11-15: Core math/PRNG fixes: these are the standards. Keep them.
- clamp asserts in release.
- from_axis_angle guards zero axis.
- PRNG docs now correctly state xoroshiro128+.
- next_int removes modulo bias and handles full i32 ranges.
This is the bar from now on. BunBunAlso applies to: 210-218, 318-344, 353-375
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: 6
♻️ Duplicate comments (9)
crates/rmg-core/src/math.rs (4)
11-15: Clamp validates in release. Finally.Release assertion instead of debug_assert is correct for deterministic behavior.
353-361: PRNG docs now correctly say xoroshiro128+.Accurate and non‑crypto disclaimer is present. Good.
389-397: Float path uses exact 23‑bit mantissa (>> 41).Uniform [0,1) for f32 via bit‑trick is correct.
399-424: Inclusive int range uses rejection sampling and 64‑bit math.No modulo bias; full i32 span safe. Good.
crates/rmg-core/tests/fixtures/math-fixtures.json (1)
1-7: Tolerances included. Good.Absolute/relative 1e‑6 prevent cross‑platform flakiness.
crates/rmg-core/tests/math_validation.rs (4)
14-19: Fixture parsing now debugs itself.Clear panic with file path + error; validation step blocks empty sets. Solid.
336-351: Contextful failures for vec3 length/normalize.Enumerated, self‑describing panic paths. Exactly what you want at 3am.
Also applies to: 353-368
371-381: Multiply tests identify the failing case.Enumerating and passing context improves triage speed.
447-478: Decoupled PRNG int replay.Re-seeding before int generation removes fragile coupling. Keep it.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (5)
crates/rmg-core/src/math.rs(1 hunks)crates/rmg-core/tests/fixtures/math-fixtures.json(1 hunks)crates/rmg-core/tests/math_validation.rs(1 hunks)docs/decision-log.md(1 hunks)docs/execution-plan.md(3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
docs/decision-log.md
📄 CodeRabbit inference engine (AGENTS.md)
Record milestones, blockers, decisions, outcomes, and next steps in docs/decision-log.md
Files:
docs/decision-log.md
docs/**
📄 CodeRabbit inference engine (AGENTS.md)
Document meaningful design choices in the docs/ directory (specs, diagrams, memorials) and keep impacted docs in sync with code changes
Files:
docs/decision-log.mddocs/execution-plan.md
**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
Public Rust APIs across crates (e.g., rmg-core, rmg-ffi, rmg-wasm) must include rustdoc comments explaining intent, invariants, and usage
Files:
crates/rmg-core/tests/math_validation.rscrates/rmg-core/src/math.rs
docs/execution-plan.md
📄 CodeRabbit inference engine (AGENTS.md)
Start each work session by updating Today’s Intent in docs/execution-plan.md
Files:
docs/execution-plan.md
🧬 Code graph analysis (1)
crates/rmg-core/tests/math_validation.rs (1)
crates/rmg-core/src/math.rs (11)
new(44-46)new(145-147)new(229-231)clamp(12-15)deg_to_rad(18-20)rad_to_deg(23-25)from(126-128)from(210-212)from(348-350)from_axis_angle(246-262)from_seed(369-375)
🪛 markdownlint-cli2 (0.18.1)
docs/execution-plan.md
101-101: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
112-112: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below
(MD022, blanks-around-headings)
🔇 Additional comments (2)
docs/decision-log.md (1)
13-13: Decision log entry reads clean; keep timeline sorted.Chronology and scope match execution-plan. No changes needed. Keep adding file/commit refs when available.
docs/execution-plan.md (1)
94-96: Decision table order is chronological; keep it that way.Entries progress 2025‑10‑23 → 10‑24 → 10‑25 → 10‑25 → 10‑26. Good. No action.
Summary
Testing