Skip to content

Implementer: impl/movement - #92

Open
ozgb wants to merge 9 commits into
mainfrom
impl/movement
Open

ozgb wants to merge 9 commits into
mainfrom
impl/movement

Conversation

@ozgb

@ozgb ozgb commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Opened by the clean-room broker.

CubeB and others added 5 commits November 28, 2026 00:18
Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-opus-5-5
Re-pin to interfaces-v110 and reference-traces-v65: payloads of every
publish are recorded, class words come from the kit's table, and the new
recordings cover DESTROY, LOAD and TargetType. Examples cite the new
recordings with their payloads; the kit gaps they close are dropped.

Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude Code:claude-sonnet-5-5
Assisted-by: Claude Code:claude-sonnet-5-5
Answer the implementer's first spec question: the replay compares a
freed target's bytes as zero (ozgb/byte-tactics-moddable#1380).

Assisted-by: Claude:claude-opus-5-5
@CubeB

CubeB commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Spec writer: code review round 1 (#1218), a fresh session in the microVM (launch.py --review, /code-review high), on impl/movement at 095645e, base 649004a. Proxy check-log: pass (64 requests, all on the allowlist). The report as the reviewer wrote it; it goes to the implementer unchanged (--review-report).


Findings: 0 bug, 2 risk, 5 nit.

Scope: all of /work/movement/ and git diff 649004a..HEAD. I ran /code-review high. I kept only the findings I could reproduce from the code, the spec or the kit, and dropped the rest. One dropped claim was a null SimAlloc result, which ABI 9.3 rules out. Another was a per-module notes-file convention, which the spec and kit don't state.

I rebuilt the module under /tmp. It is byte-identical to module.wasm, and wasm_fuel.py --check accepts it. The 12 imports, the exports, the data words and the window layout match the spec's manifest entry. The stack top, 628624, is inside the window. I read every slot against spec sections 3-6 and found no departure on a path that has a recording.

I fuzzed math.rs in a debug build with overflow checks, using edge and random inputs for angle_of_vector, rotate_point, hypot, sqrt and ftol. It had no panic, overflow or out-of-range index.

  1. risk — movement/src/lib.rs:1054-1055. The blocked-cell clamp panics when min > max.

    • Ord::clamp asserts min <= max, and the bounds come from centre(), which wraps in 32 bits.
    • For a blocked unit whose u.cell.x (or .y) is 2048 with an even footprint, cx is 0x80000000. Then cx-0x7ffff wraps above cx+0x7ffff.
    • The panic handler is loop {} (:1587), so the slot spins until it runs out of fuel and traps.
    • Spec section 5 ("a module must not trap") and ABI 13 say it must not. Section 4 "Moving" defines the clamp for every cell.
    • Fix: use max(lo).min(hi) or wrapping-safe bounds.
  2. risk — lib.rs:1132. destroy_target zeroes the freed record before SimFree.

    • Spec section 4, DESTROY_TARGET, says only UnitRefUnlink, then SimFree(target).
    • The notes and SPEC-QUESTIONS 1 justify the zeroing by a gate verdict only. Nothing in the spec or kit supports it. ABI 9.3 already makes every SimAlloc zeroed.
    • replay-format.md ("Services", the passage on freed objects) says a freed object is not walked until SimAlloc hands the address out again. Spec section 7, "Gaps in the kit", says a reused name lists fields that are 0.
    • The zeroing changes behaviour. Spec section 3 says a goal keeps its freed target offset. After the zeroing, Reached and Report on that offset see class word 0 and source 0. So Give(g,0) skips the ORDER_FLAGS 0x80 report, which spec section 4 "Give" sends for any old target whose source is not 0.
    • The same applies in DESTROY of a packed goal (:1242). So the notes' answer doesn't hold by the spec. Either the spec should say it, or the zeroing should go.
  3. nit — lib.rs:302. alloc_zeroed re-zeroes every record.

    • Spec section 3 says SimAlloc returns a zeroed record, and ABI 9.3 repeats it.
    • SPEC-QUESTIONS 2 and the notes say the module "does not rely on" that zeroing, yet the code does it for every motion, goal and target. It is redundant work.
  4. nit — lib.rs:1454. UnitTarget reads g + GO_TARGET without checking that the goal is non-null.

    • Its sibling HasNetState does the same through goal_kind, which compares word 0. The spec says "otherwise the goal's target".
    • A motion whose obj is 0, which is malformed state, reads address 4.
  5. nit — lib.rs:281-287 and :1360. The block bound is the manifest's block_max constant, 268435456.

    • Spec section 4 Apply says a target is valid when "its record lies inside the block" and "a module reads nothing outside the block". ABI 2.1 says bytes past the block's end are never read.
    • The block can be as small as block_size. So valid_target and the ApplyPathEvent requester check read the class word of an offset that is past the block's end but under block_max.
    • The module has no way to learn the real end. The spec should say which bound to use.
  6. nit — lib.rs:385-387, :454, :470-490, :1459-1461. Several reads follow a possibly-null reference with no guard: source, Order.unit, self, ref.owner (for flag 0x4 in Reached), u.def and u.player. A target with no source is allowed (spec section 4, "Report"). A disc, ring or footprint marker with no source, or one whose order has no unit, is read through addresses 14 to 126. This doesn't trap, but the result is arbitrary, not a defined answer.

  7. nit — movement/src/tables.rs:1. SIN has 640 entries, but scaled_sine and scaled_cosine (math.rs:533-541) index only & 511. Entries 512-639 are never read, so 256 bytes of data are dead. The kit's vectors/README.md ("Sine table") uses the extra 128 only for the unscaled cosine, which this module never calls.

Checked and matching the spec, no finding:

  • Apply validation, outcomes and sizes.
  • The field offsets against layout.json.
  • The payload sizes of all 15 published effects.
  • PathRequest (56 bytes, every byte written).
  • Q1-Q8.
  • The flying roundings (f32 and f64 steps).
  • The ApplyPathEvent guards.
  • The NewX quirks.
  • UnitRefSetUnit and the table import, kept alive by a never-taken branch on a zero static (lib.rs:1427). The branch is not hit because the loader zeroes the window (ABI 2.2).

The notes' open points stand as they say: the paths no recording reaches (patrol and packed goals, ApplyPathEvent, HasNetState, SET_SPEED, SET_HEADING, air maneuver, follow offset, refused events) follow the spec text and nothing judges them. I read those paths line by line against section 4 and found no departure.

Implementer added 3 commits November 30, 2026 13:44
@CubeB

CubeB commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Spec writer: implementer session 2 (microVM, --review-report of round 1, handed in unchanged) on impl/movement. It merged spec-movement e089b23, fixed findings 1, 3, 4 and 7, answered 2, 5 and 6 in IMPLEMENTATION-NOTES.md, and got req4 equal on all 12 recordings. The new head 4f24005 came through the broker's push only. Proxy check-log: pass (3 requests). Round 2 of the review runs on 4f24005.

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.

2 participants