Repository navigation
Reject out-of-island weave casts in the mod sandbox - #397
Conversation
queue_weave drops a cell outside ±2048 before the cast is stored, so a bad call does not land and does not spend terrain edits. A table covers ids, the island, the 64 cap, and two identical runs. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
|
@coderabbitai review |
|
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 |
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 review of 3bbf29c0 against the weaving queue, the sim sandbox, and the scripting trace.
The island gate itself is sound. queue_weave rejects an origin outside the inclusive cube ±ISLAND_HALF_CELLS (2048) after the i64→i32 conversion and before the WeaveCast is stored. There is no saturating cast. The constant is the one enqueue already uses, so a value that passes the host also passes origin_on_island. At that edge, push_ice's largest product is (2048 + 255 + 1) * CELL_MM = 2_304_000, and the negative corner is -2_303_000. Both fit in i32. No new dependency, no new unsafe, no float, no SimRng, and no wall clock. cargo deny, cargo audit, the clippy gate, and the three-OS replay compare are green on this head.
What this changes is control flow. enqueue already dropped a single out-of-island command and left earlier commands in place, and the host used to return Ok, so the rest of the script ran. An uncaught error now aborts that invocation: earlier casts in the same buffer are not applied, and neither is move_to. MOD_COMMAND_API_VERSION stays 2. That is the fail-closed behavior the two-call test locks. It is a visible change for any existing script that queued a legal cast and then an illegal one.
Invariant 9 overstates that abort. Rhai try/catch is still enabled. A caught error leaves the bad origin unstored and keeps earlier casts when the script returns Ok. Casts already applied for a previous entity stay. apply_weave_casts still commits earlier casts in a buffer if a later queue_weave returns OutsideIsland. The digest used by scripted_system hashes error text and agent positions, not WeaveScratch; this test compares the command log directly, which is the right check. The new edges are not one of the nineteen replay cases. The predicate is integer, so it does not add a cross-OS input. Trace §10 still says fifteen cases.
#260 asks for the #214 wire-up (capability, command API 2, the host call, max_weaves, template TOML). That wire-up is already on main. This PR is the script-side island reject.
Before merge: narrow invariant 9 to the uncaught invocation, and make the sixty-four case assert template and origin. A catch case that shows the bad command stays out of WeaveScratch would lock the property that actually matters.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT
| if origin | ||
| .iter() | ||
| .any(|cell| !(-ISLAND_HALF_CELLS..=ISLAND_HALF_CELLS).contains(cell)) | ||
| { | ||
| return Err(weave_runtime("weave origin is outside the island")); |
There was a problem hiding this comment.
This reject matches enqueue: same ISLAND_HALF_CELLS, inclusive on every axis, after i32::try_from, and before buf.casts is written. i64::MAX / i64::MIN still fail at try_from (origin x) and never saturate into a cell.
An uncaught Err aborts the script. run_one then drops that invocation's WeaveBuf, so a legal cast earlier in the same call is not passed to apply_weave_casts. enqueue does the opposite for a command that reaches it: QueueError::OutsideIsland leaves command_count unchanged and the caller keeps going. SandboxEngine::build disables eval, import, export, print, and debug. It does not disable try / catch. A caught error still refuses the bad origin, and casts already sitting in the buffer are applied if the script returns Ok. A previous entity whose run_one returned Ok has already been written; this Err does not roll that entity back.
The same cube is written out again in origin_on_island and in the push_ice debug_assert. Release push_ice multiplies with * and does not call cell_to_milli. The debug assert is not the release gate. One shared predicate would keep the host, enqueue, and push_ice from drifting.
| "valid cast then outside island drops the script", | ||
| "weaves.queue_weave(1, 0, 0, 0);\nweaves.queue_weave(1, 3000, 0, 0);", | ||
| None, | ||
| vec![], | ||
| Some("outside the island"), | ||
| ), | ||
| ]; | ||
| for (name, script, toml, commands, error) in cases { | ||
| check_case(name, script, toml, &commands, error, None); | ||
| } | ||
| check_case("sixty four casts", &sixty_four, None, &[], None, Some(64)); | ||
| check_case( | ||
| "sixty fifth cast drops the script", | ||
| &sixty_five, | ||
| None, | ||
| &[], | ||
| Some("full"), | ||
| Some(0), |
There was a problem hiding this comment.
valid cast then outside island drops the script is the case that locks the new abort. A lone queue_weave(1, 2049, 0, 0) also leaves the log empty when only enqueue rejects, and that path's error text (weave origin is outside the island for template …) still contains outside the island. The single-cast row does not distinguish the two layers.
The cube check is origin.iter().any(...), so y and z use the same bound, but the table never leaves the cube on those axes (-2049, y = 2049, z = 2049). enqueue's own test does. There is no try { queue_weave(1, 3000, 0, 0); } catch row, which is the path that keeps an earlier legal cast.
sixty four casts asserts len == 64 and skips the command list (commands is &[] whenever count is set). Sixty-four commands at the wrong template or origin would pass. The sixty-fifth row does lock an empty log and full.
| | 6 | A script swap recorded as `(tick, path, content hash, source)` and replayed from `ScriptReplayLog` matches the live digest. | Yes | `reload_mid_run_replays_to_the_identical_hash` | | ||
| | 8 | `build_app` installs `ModScriptPlugin` after `register_mod_runtime`. A mod loaded onto that app, including a mid-run swap in `ScriptReplayLog`, replays to the same digest. Manifest script map keys are the relative manifest paths. | Yes | `mod_loaded_through_build_app_replays_identically`, `load_mod_dir_keys_are_manifest_paths` | | ||
| | 9 | `queue_weave` is capability `Weave` at command API 2. The script passes a template id and an origin. The host fills tick, seq, and caster and calls `astraweave_weaving::queue_weave`. Ids 1 through 7 are engine ids. Ids outside `u16` are rejected before the cast. `max_weaves` defaults to 64 and does not spend `terrain_edits`. Two runs through `build_app` enqueue the same commands. | Yes | `queue_weave_is_a_weave_command_and_weaves_do_not_spend_terrain`, `queue_weave_through_build_app_replays_identically`, `parse_rejects_engine_ids_and_accepts_modifier_data` | | ||
| | 9 | `queue_weave` is capability `Weave` at command API 2. The script passes a template id and an origin. The host fills tick, seq, and caster and calls `astraweave_weaving::queue_weave`. Ids 1 through 7 are engine ids. Ids outside `u16`, and cells outside ±2048, are rejected in the script call before a cast is stored. A script error applies none of that script's casts. `max_weaves` defaults to 64 and does not spend `terrain_edits`. Two runs enqueue the same commands. | Yes | `queue_weave_is_a_weave_command_and_weaves_do_not_spend_terrain`, `queue_weave_through_build_app_replays_identically`, `queue_weave_edges_fail_closed` | |
There was a problem hiding this comment.
The new sentence covers a narrower state than it states. An uncaught queue_weave error drops the casts of that run_one invocation, including a legal cast earlier in the same script. A caught error does not. Casts apply_weave_casts already wrote for another entity stay. If a cast reaches apply_weave_casts and queue_weave returns OutsideIsland, earlier slots in that buffer are kept; the host check is what keeps script origins off that arm.
queue_weave_is_a_weave_command_and_weaves_do_not_spend_terrain checks COMMANDS, API 2, and that a BudgetLimits constructed with terrain_edits: 0 is still 0. It does not run a script. The host and enqueue never read terrain_edits, so the budget claim holds by inspection of those two functions.
§10 of this trace still says scripted_system is one of fifteen cross-OS cases. The required set is nineteen. This bump does not change the hash 362e4c6d…, and the three-OS replay compare on this head stayed green.
| load_before: Vec::new(), | ||
| scripts: vec!["scripts/tick.rhai".into()], | ||
| weaves: vec!["weaves/extra.toml".into()], | ||
| capabilities: Default::default(), |
There was a problem hiding this comment.
validate_manifest_file rejects an empty capability list. This LoadedMod is inserted directly, and mod_script_system never reads LoadedMod.capabilities. execute_deterministic refuses an empty allowlist and then eval_ast_with_scopes the body; it does not check the called name. call_deterministic does. SandboxProfile::sim() registers queue_weave on the shared engine for every mod script.
This fixture does prove the template mount (id 8 keeps until == 4, engine id 1 is refused and the engine cast still queues). It does not prove capability Weave.
* 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
queue_weavewas already on the mod sandbox from #214: capabilityWeave, command API 2,max_weaves64, and the host call intoastraweave_weaving::queue_weave. This closes the script-side hole and locks the edges.A cell outside ±2048 is rejected in the script call, before the cast is stored. The script then applies none of its casts. Ids that do not fit
u16, unknown ids, and engine-id TOML stay rejected. Ids 1 through 7 still enqueue. A loaded id 8 keeps its duration. Sixty-four casts land; a sixty-fifth drops that script. Two runs produce the same commands and the same errors. Terrain edits stay at 0.queue_weave_edges_fail_closedis the table.queue_weave_through_build_app_replays_identicallystill matches.Fixes #260
Type of change
Security Considerations
queue_weaverejects origins outside the island and template ids that do not fitu16before a cast is stored.Checklist