Repository navigation
Reject weave origins that overflow the millimetre conversion - #388
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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 |
|
@coderabbitai review |
|
queue_weave already drops cells outside the island. meters_to_cell now refuses a non-finite or out-of-i32 metre value before the saturating cast, and compile_legacy drops that origin instead of building an ice bound. In-range casts still use the same cell and millimetre values. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
d782564 to
50dbf5a
Compare
There was a problem hiding this comment.
Adversarial review of the millimetre-overflow rejection. The direction is right: in-range freeze bytes stay on the old multiply, queue_weave already refuses origins outside ±2048, and weaving_case_bytes never calls meters_to_cell. No new unsafe, no tick allocation, no RNG, and the new f32 checks are IEEE multiply plus comparisons, so the reject set is cross-OS stable.
The new gate is not closed.
meters_to_cellstill saturates one finite input.i32::MAX as f32is2^31(0x4f000000), somilli > i32::MAX as f32lets that value through andas i32saturates toi32::MAX. Thef32nearest2^31 / 1000(prints as2147483.8) returnsSome(2_147_483)instead ofNone.cell_originthen drops it, socompile_legacyis saved, but the public contract and invariant 13 are false. Usemilli >= i32::MAX as f32(every smaller finitef32is at most2147483392and fits). The negative bound is exact; a scan found no negative hole.- The only production caller,
astraweave-gameplay::apply_weave_op, treats a dropped op as success. It still spends terrain or weather budget and returns the kind's consequence (faction_disposition: 5,weather_shift: Some("frozen")) when geometry was not applied. - Only point
ais bounded. Collapse still doesbx as i32/bz as i32. A finite in-islandaplusb = [1e20, …]saturates toi32::MAX.draw_line_obsthen walks one cell at a time.i32::MAX - negative_aoverflows (debug panic, release wrap). A wrappedsignumof-1never reachesb, so the loop does not terminate. push_icecommits phase writes inpush_commandbefore the new early return. WithISLAND_HALF_CELLS = 2048,CELL_MM = 1000, and au8radius, the product tops out near2.3e6and theNonearm is dead for everyqueue_weavecommand. If a later radius or cell size makes it live, replay bytes keep the stamps and dropsheet_count/nav_count, which breaks invariant 12. Fail the command beforestore_writes, ordebug_assertthe island invariant instead of returning.
far_origin_does_not_saturate_into_a_milli_aabb does not lock any of these. 1e20 is rejected by the coarse range check, and the island-edge case never builds m * 1000 == 2^31, a NaN/±inf origin, a negative edge, or a collapse endpoint. last_verified_commit is still fb1c8ec2 after the 1.9 restamp.
In-range weaving replay bytes are unchanged. I would not merge until the cast bound, the gameplay fail-open, and the collapse endpoint are fixed.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT
meters_to_cell rejects millimetre values at or above 2^31. A dropped legacy op no longer spends budget or returns a consequence. Collapse endpoint b uses the same island check as a. push_ice asserts that bound and still emits the ice sheet after the writes. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
There was a problem hiding this comment.
Adversarial re-review after bc553b45 and 65dee631. The four holes from the review on 50dbf5af are closed.
meters_to_cellrejects non-finite values, and millimetres at or above2^31, before the cast. A scan of every mantissa in the f32 binades around ±2^31, both signs, found no accepted value that saturates inas i32. The negative edge the test locks,(i32::MIN as f32) / 1000, becomes cell-2147484, andcell_origindrops it because that cell is outside ±2048.apply_weave_opbails on a dropped op before it spends budget, writes physics, or callsapply_director_plan. The kind check matchescompile_legacy: fortify for 0/4, collapse for 1,write_countfor 2/3, ice min for 5. A collapse withb == Nonestill returns "Collapse needs A->B" first.- Collapse endpoint
buses the same finite-and-island check asa. A passing origin is within about ±2049 m, so the lateras i32cannot saturate.draw_line_obstherefore never seesi32::MAX, andb.x - a.xstays within a few thousand. The wrapped-signumloop is closed. Terrain amplitudes here are a few hundred metres, under the 2048 m cube, so the Y axis of that check does not reject current casts. push_iceasserts the island cube and still emits the sheet after the writes.queue_weaveis the only enqueue and rejects that cube first. WithCELL_MM = 1000and au8radius the largest corner is(2048 + 255 + 1) * 1000 = 2_304_000, which fits ini32, so the release multiply does not wrap for any queued command. Builtin freeze uses radius 2.weaving_case_bytesnever callsmeters_to_cell. In-range ice products fromchecked_mulmatch the old multiply.
Security and determinism: no new dependencies, astraweave-weaving still has forbid(unsafe_code), and the reject predicate is an IEEE multiply plus comparisons. No wall clock, no RNG, and no allocation on the weave tick. On Rust 1.89, float-to-int casts saturate: 1e20 as i32 is i32::MAX, inf as i8 is 127, NaN as i8 is 0. Wind's (b - a) as i8 is then clamped to -1..=1. A non-finite wind endpoint still passes legacy_geometry_kept for kind 2. PhysicsWorld::set_wind stores zero, because glam's normalize_or_zero rejects a non-finite reciprocal. That spends a weather op and reports windy with a zero vector. It does not write NaN into the wind vector and it does not loop.
compile_legacy has no production caller besides apply_weave_op. The playground still discards that Result with let _ =, so a rejected cast there stays silent. That discard predates this change.
Tests run here: astraweave-weaving legacy module (5) and meters_to_cell_rejects_non_finite_and_the_i32_edge; astraweave-gameplay weaving::tests (16). All passed.
One code fix still belongs on this branch: gravity_conversion_matches_9810 lost its #[test] attribute to the new boundary test, and the test binary warns that the function is never used. The trace restamp should also stop certifying the FreezeWater "no physics mutation" sentence.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT
gravity_conversion_matches_9810 is a test again. A non-finite wind endpoint drops the op before a weather spend. The gameplay trace no longer says FreezeWater leaves physics unchanged. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
There was a problem hiding this comment.
Adversarial re-review of d318ebff (code at ff3724c1). The four holes from the review on 50dbf5af stay closed, and the two follow-ups from the review on 65dee631 are split.
Closed, re-checked against the callers:
meters_to_cellrejects non-finite values and any product>= 2^31before the cast. The greatest finitef32below2^31is0x4effffff=2147483520(ulp 128, not 256). That value fits ini32, and every larger binade step is>= 2^31and rejected.i32::MINis exact; the next more-negativef32is rejected.div_euclidof that edge is-2147484, thencell_origindrops it. No accepted value saturates.apply_weave_opbails on a dropped op before budget, physics, andapply_director_plan. Kind 0/4 requirefortify, kind 1 requirescollapse, kind 5 requiresice_min_milli.- Collapse endpoint
buses the same island check asa. A kept metre is inside about ±2049, soas i32stays inside ±2048.draw_line_obsthen sees a delta of at most 4096.signumcannot wrap, and the loop terminates. push_iceasserts the island cube and still emits the sheet afterstore_writes.queue_weaveis the only enqueue. WithCELL_MM = 1000and au8radius the extreme corner is(2048 + 255 + 1) * 1000 = 2_304_000, which fits ini32. Builtin freeze uses radius 2. Loaded templates never reachpush_ice.gravity_conversion_matches_9810has its#[test]again. Invariant 5 now says a keptFreezeWaterinserts one static AABB.weaving_case_onstill queues integer cells ([0,0,0],[2,0,0],[0,1,0],[0,0,1]) and does not callmeters_to_cell. In-range ice products match the old multiply.astraweave-weavingstill hasforbid(unsafe_code). No new dependencies, no wall clock, no RNG, no tick allocation. The reject predicate is one IEEE multiply plus comparisons, so the reject set is cross-OS stable.
Still open:
- Kind 2 only tests
is_finite. A finite endpoint at or above about1.9e19overflows the square insideVec3::normalize_or_zero(glam 0.30.8).apply_weave_opstill spends a weather op, overwritesPhysicsWorld.windwith zero, and returnswindy. The clampedSetWindwrite is not what physics reads. Details onlegacy.rs. - The comment on
meters_to_cellstill says the cell truncates toward zero, and that every smaller finitef32is at most2147483392.-1.5is locked asSome(-2). The predecessor of2^31is2147483520. The>=comparison is the right one; the sentences are not. Left the existing thread open. - Invariant 5 is fixed. The stage-detail note, the §9 bullet, and the open question still say
apply_weave_opbakes a navmesh atweaving.rs:113. That line isapply_director_plan. Line 20 discardsnav_src. There is noNavMesh::bakein the function.
The playground still discards apply_weave_op's Result with let _ =. That discard predates this change, so a rejected cast there stays silent.
I would not merge until the wind magnitude hole is closed. The comment and the bake citation should be corrected in the same stamp; they do not block on their own.
This run did not re-execute cargo test. The workspace target directory is cold. The float bounds above were checked by decoding the f32 bit patterns, and the wind zero path was checked against glam 0.30.8 Vec3::normalize_or_zero.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT
normalize is only called after the squared length is finite, and that check bails before the weather spend. meters_to_cell's comment now says the conversion floors, and that the f32 before 2^31 is 2147483520. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
There was a problem hiding this comment.
Adversarial re-review of f3abdf06 (code at fbd1d331). The overflow hole from the last review is closed. A squared length of zero is not.
Closed, re-checked against the callers and a standalone f32 probe (same operations as wind_delta_fits and glam 0.30.8 normalize_or):
1.9e19and1e20square to+infand are rejected in bothwind_delta_fitsandwind_direction, before budget spend and beforeset_wind.1e19and the greatest finite square (1.8446743e19,len2 = 3.4028233e38) normalize to1and stay accepted. Three components of1.2e19overflow the sum and are rejected; three of1e19stay finite (3e38).meters_to_cellstill floors (-1.5→-2) and rejects non-finite values and millimetres at or above2^31before the cast. The negative edge rounds to milli-2147483600and cell-2147484, matching the test. The predicate comment now states that.- In-range collapse and fortify coordinates stay inside about ±2048, so
draw_line_obs'sb - ano longer hits thei32overflow that wrappedsignumand failed to terminate.queue_weaveis still the only way intopush_ice, and theweavingreplay still does not callmeters_to_cellorcompile_legacy. No newunsafe, no RNG, no wall clock. The new rejects are IEEE multiply andis_finite, so the reject set does not fork across OS.
Still open:
- A finite squared length of
+0is accepted. Exact zero and any component whose square underflows (0,1e-45,1e-30,1e-23) take that path,normalize_or_zeroreturns zero, andset_windclears the stored wind while the op spendsweather_opsand reportswindy.1e-22still normalizes and must stay accepted. Both gates have to reject the zero square;apply_weave_opdoes not read theSetWindwrite. - The
fbd1d331gameplay stamp still saysapply_weave_opre-bakes a navmesh. It does not.nav_srcis discarded on line 20. The citedweaving.rs:113is the ice AABBmaxvector. The same sentence is still in the §9 bullet and the §11 question.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT
A zero step and squares that underflow to +0 no longer clear the wind or spend a weather op. 1e-22 still redirects. The gameplay trace no longer says apply_weave_op bakes a navmesh. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
There was a problem hiding this comment.
Adversarial re-review of a4166d8c (code at 9403e3b6). The three open findings are closed. I would merge this.
Closed, re-checked against the callers, a standalone f32 probe of the same operations, and the crate tests:
- Zero-square wind is rejected before budget and before
set_wind.wind_delta_fitsrequires a finite square that is strictly positive.wind_directionalso rejects a zero or non-finitenormalize_or_zero. Probe:0,-0,1e-45,1e-30, and1e-23have a zero square.1e-22stays finite and non-zero.1.8446743e19stays (square3.4028233e38);1.8446744e19and1.9e19are+inf. Three components of1e19stay finite (3e38); three of1.2e19overflow the sum.5e-23is the first positive square (3e-45) and normalizes to about0.94;PhysicsWorld::set_windnormalizes again and multiplies by10, so the stored wind is not zero.apply_weave_opdoes not read theSetWindwrite. - The millimetre cast does not saturate. A full mantissa scan of the f32 binades around ±2^31 found no accepted value that saturates in
as i32.(i32::MAX as f32) / 1000multiplies back to bits0x4f000000(2^31) and is rejected by>=. The predecessor0x4effffffcasts to2147483520and fits. The negative edge is exactly-2^31, casts toi32::MIN, anddiv_euclidis-2147484. That cell is outside ±2048, socompile_legacydrops it.cell_to_milli(-2147484)isNone. No current caller multiplies that cell. - A kept collapse endpoint truncates into [-2048, 2048].
draw_line_obs'sb - ais at most 4096,signumcannot wrap, and the loop terminates.-2047.1floors to cell-2048(kept) and truncates to-2047.-2048.1floors to-2049and is dropped. Fortify and collapse still truncate; the island gate floors. In-range integers are unchanged. - The bake citation is gone. Invariant 5 is the ice AABB.
nav_srcis discarded.last_verified_commitis9403e3b6. - No new dependency and no
unsafe(forbid(unsafe_code)remains).queue_weaveis still the only enqueue.push_icemultiplies inside that cube; the extreme corner(2048 + 255 + 1) * 1000 = 2_304_000fits ini32. Theweavingreplay still queues integer cells ([0,0,0],[2,0,0],[0,1,0],[0,0,1]) and does not callmeters_to_cell. The new rejects are IEEE multiply and compare, so the reject set does not fork across OS. Accepted wind still uses glam's libm sqrt, which was already the contract, and that path is not in the replay hash.
Tests run here: astraweave-weaving lib, the 6 named cast and wind tests, all passed (including gravity_conversion_matches_9810). astraweave-gameplay weaving::, 18 tests, all passed (including weave_op_edges_fail_closed and non_finite_wind_endpoint_does_not_spend_weather).
One diagnostic nit, not a merge block: a zero or overflowing wind still reports "weave origin is outside the island", and the weather test locks that sentence. The playground still discards apply_weave_op's Result with let _ = on the collapse and wind keys. That discard predates this change.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT
| let end = op.b.unwrap_or(op.a + vec3(1.0, 0.0, 0.0)); | ||
| Some( | ||
| wind_direction(op.a, end) | ||
| .ok_or_else(|| anyhow::anyhow!("weave origin is outside the island"))?, |
There was a problem hiding this comment.
Non-blocking. This string is now the failure for every wind_direction reject, including a zero delta, a square that underflows (1e-23), and a square that overflows (1.9e19). None of those origins are outside ±2048.
non_finite_wind_endpoint_does_not_spend_weather locks contains("outside the island") for NaN and 1.9e19, so the false reason is part of the test contract. The world effect is still right: budget unchanged, previous wind unchanged (weave_op_edges_fail_closed passed, 18/18). A distinct message would only help the caller tell a bad direction from a bad origin. The same sentence on the geometry bail below is accurate for a dropped cell.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Adversarial re-review of the squash 43b1b48f (the eight touched files match a4166d8c). The overflow, budget, collapse, and zero-square holes from the earlier threads are closed. The change is sound.
Checked against the callers, a full f32 scan of the landed predicate, and glam 0.30.8 normalize_or_zero:
- Every finite
f32throughmeters_to_cell: 2,483,430,623 accepted values, 0 that saturate inas i32.(i32::MAX as f32) / 1000(bits0x4a03126f) isNone. The negative edge isSome(-2147484).div_euclidof that cast does not hiti32::MIN.cell_to_milli(-2147484)does not fit, and that cell is outside ±2048, socompile_legacydrops it before a multiply. The finitef32before2^31(2147483520) casts cleanly; as metres it is cell2147483, which the island gate drops. - Wind squares match both gates and glam.
0,-0,1e-45,1e-30, and1e-23have a zero square and normalize to zero.5e-23(square3e-45) normalizes to about0.94, andset_windof that direction is non-zero.1e-22stays.1e19and1.8446743e19stay (square3.4028233e38).1.8446744e19,1.9e19,1e20,f32::MAX, and(10, 1.9e19, 0)are rejected. Three components of1e19stay; three of1.2e19overflow the sum. Rejection is beforeset_windand before the weather spend. queue_weavestill rejects an origin outside ±2048 beforepush_ice. The extreme corner(2048 + 255 + 1) * 1000 = 2_304_000fits ini32. Builtin freeze radius is 2. Loaded templates do not callpush_ice. Release builds strip thedebug_assert; a queued origin still cannot wrap the product.- A kept collapse endpoint truncates into [-2048, 2048].
draw_line_obs'sb - ais at most 4096, sosignumcannot wrap and the loop terminates.apply_weave_opbails before the budget decrement and beforeadd_static_aabb,set_wind, andapply_director_plan.nav_srcis discarded.add_static_aabbinserts a fixed cuboid. - No new dependency and no
unsafe(forbid(unsafe_code)remains onastraweave-weaving). No RNG and no wall clock on the new path. The reject predicates are IEEE multiply and compare, so the reject set does not fork across OS. Theweavingreplay still passes integer cells throughqueue_weaveand does not callmeters_to_cell. Accepted wind still uses glam's libm sqrt, which was already the contract, and that path is not in the replay hash. Replay hash on ubuntu, windows, and macos succeeded, as did fmt/clippy, cargo-audit, and cargo-deny.
Still open, and not a reason to revert:
- The thread on
weaving.rs:52stands. A zero delta, an underflow (1e-23), and an overflowing square (1.9e19) still report "weave origin is outside the island". The tests lock that sentence. Budget and the previous wind stay unchanged. docs/architecture/gameplay.md§10 still counts 14#[test]s inweaving.rs. The file has 18.last_verified_commitis9403e3b6. That commit is not an ancestor of main after the squash. The landed bytes are43b1b48f.- Fortify and collapse still truncate metres (
as i32) after the floor gate.-1.5is kept and the rect is centered on-1. Integers inside the island are unchanged. The edge tests do not read the obstacle set.
This run did not re-execute cargo test. The float scan and the glam 0.30.8 probe were local. The crate tests are the CI results on this commit.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT
* docs: record the weave origin island on main outside ±2048 cells and does not saturate, and the weaving replay case still hashes NullField. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * docs: record #394, #396, and #397 on the status pages #397 closed #260. The mod host rejects an out-of-island origin before the cast is stored. #394 keeps the retired title out of player-facing assets. The 0.323 ms figure is the cloud_shadow pass. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * docs: correct the weave-origin citations the audit flagged A dropped wind returns from wind_direction before legacy_geometry_kept. A failed mod run drops only that agent's casts. SEC-MOD-2 is the range check already on main. The status pins name which sentences were checked at 49d289e. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * docs: name both Hi-Z flags and the echoes scan draw_into records the pyramid only when hiz_depth_load and sample_hiz are both set. The name gate includes echoes.toml. #269 was cross-referenced by #389. The close was not attributed. compile_legacy drop sites are the empty returns, not cell_origin. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * docs: a failed weave run drops only that call The tick walks scripts, then agents. An earlier Ok for the same agent stays applied. The new test locks that. The scripting trace now says nineteen replay cases, and sample_hiz is the flag that defaults off. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * docs: a later weave success still lands after a failed script The test queues a cast, a failing origin, then another cast, and compares two runs. #217 landed when the required replay set was fifteen. The required set is now nineteen. Revision 1.6 is withdrawn. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> * docs: stamp the scripting trace at the commit that has the test last_verified_commit is 79122e7. That commit contains the three-source weave test and invariant 9. 49d289e is trace 1.5 and does not. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>


Description
Weave origins that cannot become millimetres without overflow are rejected. In-range casts keep the same cells and the same millimetre bounds.
queue_weavealready refused a cell outside ±2048 (ISLAND_HALF_CELLS) and left the queue unchanged. That check stays. The remaining overflow wasmeters_to_cell:(m * 1000.0) as i32saturates, andcompile_legacythen multiplied the cell byCELL_MM.meters_to_cellreturnsNonewhen the metre value is not finite or the millimetre value does not fit ini32, before that cast.compile_legacydrops the op when any origin cell is missing or outside the island. It does not clamp the origin into range.compile_legacyandpush_iceusechecked_mul. A product that does not fit is omitted, not wrapped.origins_outside_the_island_are_rejected_without_saturationstill locks the queue.far_origin_does_not_saturate_into_a_milli_aabblocks the metre path:1e20produces no ice bound, and the island edge2048still freezes at(2048 - 2) * 1000mm. Theweavingreplay case still queues the same in-range cells ([0,0,0],[2,0,0],[0,1,0],[0,0,1]).Fixes #295
Type of change
Security Considerations
i32millimetres, are rejected instead of saturating.Checklist