Skip to content

Add: Specify the movement subsystem - #56

Open
CubeB wants to merge 5 commits into
mainfrom
spec-movement
Open

CubeB wants to merge 5 commits into
mainfrom
spec-movement

Conversation

@CubeB

@CubeB CubeB commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Spec for movement (ozgb/byte-tactics-moddable#1198, part of ozgb/byte-tactics-moddable#180).

Model: Claude Code / claude-opus-5-5
Lead: lead-c

  • specs/movement.md: every slot of interfaces/movement.h 5.0, the kit's movement entry in full (blocked: judged on the recordings route without budgets), its imports in order and its writes, each pointed at a recording or named as unrecorded.
  • Kit: interfaces-v68 / reference-traces-v55.
  • Self-check: a scratch implementation of every recorded slot replays all 846 calls of tests/replay/movement/ with the same imports in order and the same writes (6 calls differ only by a points write the recordings leave out, section 7, "Gaps in the kit"); every example of section 7 recomputed; tools/speclint.py passes against the kit.
  • Limits of Spec: Reject a malformed effect at delivery #25 for each event kind movement takes: section 4, Apply and ApplyPathEvent.

Kit gaps (section 7): no class word values for goals and targets; publish payloads not recorded; SET_TARGET's new points not written as w; an unset position when a followed unit is gone; no Unit.pitch in the recordings.

Reviews: phase 2 approve at 9a65430 and on the diff to 7238ae4; phase 1 (sandbox) at 9a65430 replayed all 846 recorded calls equal, and its spec-side points are answered in 7238ae4; its other points are kit gaps.

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

CubeB commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Spec reviewer: phase 2 (leakage) of specs/movement.md at 9a65430, kit interfaces-v68 / reference-traces-v55. A fresh reviewer with the source; the spec writer posts it with the push.

Checked

  • speclint.py specs/movement.md --kit <kit> passes.
  • Every section read beside its source: the motion code (its clang branches, which the traces conform to), Apply and the target builders, the targets and goals, the effect payloads, the goal-area helpers, the heading helper and the slope table.
  • Names: every record and field name is in the kit's layout.json (field_26, value_26, saveOnly22, flag_1-flag_3, radiusFlag, headingFlag, pathLockStamp, PathOrderAttach, b19, b22, flying, flags_42, overflowBucket, xWhole checked). No function names, locals, FUN_/DAT_, C syntax or casts.
  • Prose: the ordered lists (the steps of UpdateMotion, the publishes of a cell change, the move-rate scripts, the imports of giving an AI search goal a target) follow the import order; the rest is conditions and arithmetic.

Correct against the source: the record layouts, offsets and goal sizes; the speed cap (slope table, 0x640000, the halving under water, mask 0x81000); the ground steering (the pull-back, D1/D2 as high halves, the widths of k, t, q, r, lim); flying (drag, cap with the heading before the turn, the climb limit, H in double raised to 8, κ, cx, cz, Q8, the speed); the tilt (0xf333, the heading after the turn, n, Q5); carried units (the water line, the signed piece, the ANGLES heading zero-extended); the cell change (formula, clamp, halved speed, publish order, Q7, the move rate); every target's position, cell test, reached test, keep and wanted heading, and its area; each goal's new target and tick (Q6, the thresholds 0xa00000, 0x1400000, 0x100000); Apply (Q1, the flags of each New* slot, Q2, Q3, DESTROY); HasNetState; ApplyPathEvent. The examples recomputed: the disc (43,18), the footprint marker (39,46,17,24), the SET_TARGET points (560,240), (688,400) with flags 11 and the Submit tuple, Step(−1044, 9830) = 964 / −9783, SET_ALTITUDE 2359296; they match orders-air-fights.txt lines 651-686, the missing w line for points included.

Findings (none must-fix)

  1. Optional. Section 4, ApplyPathEvent, FINISHED: a negative count is not specified; state it under the Spec: Reject a malformed effect at delivery #25 limits ("a negative count does nothing").
  2. Optional. Section 5: as for turnrate 0, say the ground steering's 2 × brakerate and the flying drag's maxvelocity of 0 must not trap and are not judged.
  3. Optional. Section 4, Reached, air maneuver: compare Head((0,0,0), other) "as unsigned 16-bit" with heading, as the Pos row does.
  4. Optional. Drop the two reasons: Q2's parenthesis and section 5's "(no moving ground unit has one)".
  5. Optional, an observation: the five target questions (Pos, In, Reached, Keep, Want) are definitions several slots share, not one slot calling another; accepted.
  6. Optional. Section 7, "An unset position": cite Spec: Reject a malformed effect at delivery #25 there, as Apply's limits do.

approve

@CubeB

CubeB commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Spec reviewer: phase 1 (completeness, in the sandbox), specs/movement.md at 9a65430, kit interfaces-v68 / reference-traces-v55. The report as the reviewer wrote it; proxy log: 3 requests, all on the allowlist.

Spec writer's marks: kit gaps (for the maintainer to route) are 1.1 class words, 1.2 and the "add recordings" item (uncovered branches), 1.3 payloads, 1.4 and the Q8 vector, 1.5 Unit.pitch, 1.10 the w lines of new objects, and 2 "Scenario judging" (a prompt and gate matter: a blocked entry is judged on recordings only). The rest is answered in the next revision (turnrate, replay names, ApplyPathEvent limits, offsets outside the block, the full SET_ALTITUDE value, the unread recorded reads and units.LoadUnit). Section 3 is kept as is: the roundings, Q1 and Q6 are behaviour the gate compares, and the field names are layout.json's.


Review of specs/movement.md (phase 1)

Method. Scratch implementation of every slot in Python (/tmp/scratch), on named objects, not Rust, wasm or block bytes. A small replayer feeds it the six recordings and compares imports (order and args), o effects, w writes and results. All 846 recorded calls match. ApplyPathEvent and the queries come from the spec alone and have no recording.

1. Unanswerable from spec and kit

  1. Class words (§3, "Gaps in the kit"). No file gives the value to store for any goal or target class. The engine slots, Apply's target-validity check and ApplyPathEvent's requester check all read them. Replay does not check them either: the replayer stores its own vptr.
  2. No recording covers (found by line coverage of my code):
    • DESTROY, LOAD, SET_SPEED, SET_HEADING, SET_FLIGHT_MODE to grounded, and every refused event.
    • Patrol and packed-position goals, air maneuver targets, the follow offset (0x2), and ApplyPathEvent, HasNetState, TargetType, NewPathOrderToUnitAt, NewAirManeuverOrder, NewPathOrderToUnit for an aircraft.
    • The blocked-cell branch, the carried water-line clamp and the under-water cap.
    • An AI search goal with count ≥ 3, and the re-ask when blocked or count < 2.
    • Ground braking near a waypoint, and SET_ALTITUDE with ground at or below sea level.
  3. Effect payloads are unverified (§7 "Payloads"). Only sizes are recorded. TILT, ANGLES, MOVE_RATE, START_SCRIPT, SET_STATE_BITS and ORDER_FLAGS contents are checked by nothing. Subscribers' o lines constrain only TURN, MOVE, CHANGE_CELL and SET_POSITION.
  4. Q8 is not pinned. Making the scaled x step a float, or using math.hypot for the kit's hypot, still passes all six recordings.
  5. Unit.pitch is never recorded. The slope table F is untested.
  6. Apply's unit limits (§4).
    • Game.units and Game.unitsEnd are not in the recorded read set.
    • The spec does not say how to read a class word at a null or out-of-block offset (a bad target, or a bad requester in ApplyPathEvent) without trapping.
  7. ApplyPathEvent gaps. Unspecified: a kind above 2, and a FINISHED count below 0.
  8. Unlisted reads.
    • Game.width_142a3 and Game.height_142a7 are in every recorded read set but not in §3 "Read".
    • The schema's Apply reads also include Projectile.anglesHeading, Projectile.anglesPitch and Unit.flags.
    • The schema's imports list units.LoadUnit, which the manifest and §2 do not.
  9. SET_ALTITUDE stores the low 16 bits but uses the full value in (g + value) << 16. Is that intended above 16 bits? The replay names of the SET_SPEED and LOAD event fields are also not given.
  10. w lines of fresh objects. They include zero fields for reused names (PathOrder#1 after a SimFree) and omit others (piece −1 is never listed). The "last known value" rule behind this is not in the spec. I had to relax the comparison for new objects.

2. Spec versus kit

  • UnitDef.turnrate. §3 and §5 say unsigned 16-bit. layout.json says short (signed, offset 442). Recorded values are all below 32768, so they cannot decide it.
  • Replay names.
    • §3 names weapons[0].weapon; the recordings read Unit#N.weapon0Def and weapondef#N.range.
    • §3 says PackedPosGoal; the layout says PackedGoal. No recording names it.
  • Scenario judging. The task says the gate also plays full scenarios. §2 blocked and ABI §15 say a blocked entry gets recordings only, with scenarios not_judged.
  • Manifest entry, publish sizes, slot kinds, record layouts and kit version otherwise agree with the kit.

3. Describes the original's coding, not behaviour

  • §5 "Flying, in floating point" and Q8. Prescribes where float and double roundings fall (a compiler artefact). It is needed for bit-exactness, but no recording confirms it.
  • Q1 and Q6. Q1 (GetGroundHeight called twice) is an import-order artefact. Q6 (stale last waypoint) shows only in the points bytes.
  • Decompiler names in §3: flag_1 to flag_3, field_26, value_26, saveOnly22.
  • Mechanism and commentary: "reads g_blockBase" (§2), Q2's parenthesis, and NEW's "a motion it had is not freed".

4. Verdict

changes:

  • Give the class-word values, or say that replay and the engine slots do not check them.
  • Add recordings or vectors for the unrecorded branches in point 2.
  • Record Unit.pitch.
  • Add a vector that separates Q8's float and double steps.
  • Settle turnrate signedness against layout.json.
  • Specify ApplyPathEvent for a kind above 2, a negative count and a bad requester offset.
  • Explain the width, height and Projectile reads, and how a fresh object's w lines are chosen.

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

CubeB commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Spec reviewer: phase 2 (leakage) on the diff 9a65430..7238ae4 of specs/movement.md, kit interfaces-v68 / reference-traces-v55. A fresh reviewer with the source; the spec writer posts it with the push.

The diff answers the optional points of the first phase 2 and the spec-side points of phase 1.

  • Lint: speclint.py (moddable b84e5aaa2, and the tool at the kit's commit) passes. Three problems an older copy of the tool reported, on the recorded route names services.ScheduleMapCanPlaceUnitFootprint and services.SchedPublish, are not problems for the current tool, which reads ABI 9.3's "Routes in the recordings". Withdrawn.
  • Correct against the source and the kit:
    • turnrateUnsigned is at offset 442, unsigned short, beside turnrate.
    • The replay names are weapon0Def and weapondef.
    • PackedPosGoal and LiteGoal both start with PackedGoal.
    • SET_ALTITUDE adds the full int value.
    • ApplyPathEvent acts on kinds 0 to 2 only. Its requester limit and its negative-count limit cite Spec: Reject a malformed effect at delivery #25, and so does the target-validity limit.
    • The three zero divisors: turnrate and 2 × brakerate in the ground steering, maxvelocity in the flying drag.
    • The schema's units.LoadUnit is used only by the target loads of the engine slot LoadTarget.
    • Game.width_142a3 and Game.height_142a7 are in the read sets of all six recordings.
    • The two new kit-gap notes.
    • The air maneuver's reached test compares the angle before it is cut to 16 bits (−32768 to 32768) with heading read unsigned, so a negative angle never matches. The first wording of this revision ("as unsigned 16-bit") was wrong and is fixed in this push.
  • Leakage: none. No C syntax, verbatim stretches, helper breakdown, source-only names, reasons or build advice.

Optional: "An unset position" could say only "this spec answers no".

approve

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
@CubeB

CubeB commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

Spec reviewer: phase 2 (leakage) on the diff 7238ae4..649004a of specs/movement.md, kit interfaces-v110 / reference-traces-v65. A fresh reviewer with the source; the spec writer posts it with the push.

Checked

  • Lint: speclint.py specs/movement.md --kit <v110 export> passes.
  • Leakage: every changed passage read beside the movement source. No control flow as prose, no helper breakdown, no names found only in the decompilation, no C syntax, build advice or reasons. The class names are the kit's class_words names; StartMoving and MoveRate1 are the kit's MovementScript enum.
  • Class words: the passage agrees with ABI 7.1 ("The class word table starts the load_data region"). All nine entries named are in class_words of layout.json at offset 0 (indices 0, 1, 2, 18, 20, 21, 23, 26, 27); PathOrderAttach (22) is written by units.UnitRefInit.
  • The publish format matches the effect row of replay-format's argument table; the CHANGE_CELL example is verbatim at orders-air.txt line 483.
  • Examples: every cited line points at the call named (orders-air-fights 118, 296, 525, 640, 658, 674, 1021, 1055; console-ilose 119; load-targets 52; orders-build-patrol 153, 184; save-midgame 138; orders-air 476, 758, 822; orders-air-repair 255, 300, 308; units-transport 3), and each value and payload matches the recording.
  • Coverage: 2333 calls in the v110 recordings. Kinds NEW 11, DESTROY 2, LOAD 2, SET_MODE 1, SET_TARGET 27, DESTROY_TARGET 12, SET_FLIGHT_MODE 1 (to mode 2), SET_ALTITUDE 8, SET_APPROACH_RADIUS 2; no SET_SPEED, SET_HEADING or outcome 0; no ApplyPathEvent, HasNetState, NewPathOrderToUnitAt or NewAirManeuverOrder calls; no air maneuver, patrol or packed position objects. The new unrecorded list is right, and so is dropping DESTROY, LOAD and TargetType from it.
  • Gaps: pitch runs from −3563 to 3356, so the slope index is −2 to 1, as stated. Dropping the class-word, payload and SET_TARGET-points gaps is right.
  • Section 8 matches the export's MANIFEST and the header majors.

Findings (both optional, both applied in 649004a and re-read: approve)

  • The SimFree size sentence was too broad: an allocation made in the window is freed by its alloc#N name with no size (orders-air-repair.txt line 738).
  • Cite the effect row of the argument table beside "Event arguments".

approve

@CubeB

CubeB commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

Spec writer: re-pinned to interfaces-v110 / reference-traces-v65 at 649004a (ozgb/byte-tactics-moddable#1198). The recordings now carry every publish's payload, the class words come from the kit's class_words table (ABI 7.1), and the new recordings cover DESTROY, LOAD, TargetType and nonzero pitch; section 7 cites them with their payloads, and the class-word, payload and SET_TARGET-points gaps are dropped. speclint passes against the v110 export, and a scratch model built from the spec replays all 2333 recorded calls with the same imports, payloads and writes. Phase 2 on the diff: approve (above). Phase 1 is not re-run: the implementer session on this head is the completeness test.

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 Author

Spec reviewer: phase 2 (leakage) on the diff 649004a..e089b23 of specs/movement.md, kit interfaces-v110 / reference-traces-v65. A fresh reviewer with the source; the spec writer posts it with the push.

The diff adds one bullet, "A freed target's bytes", to section 7, "Gaps in the kit", answering question 1 of the implementer's SPEC-QUESTIONS.md (#92).

Checked

  • Lint: speclint.py specs/movement.md --kit <v110 export> passes.
  • Read beside the DESTROY_TARGET handling, the target classes' destroy paths and the engine's SimFree.
  • Recordings: orders-air.txt tick 4095, the call at index 35 (line 837: UnitRefUnlink PathOrder#1.ref, SimFree PathOrder#1 size 54, no w line); orders-air-repair.txt line 308, tick 670, index 10 (UnitRefUnlink, m PathOrder#1.ref.owner null, SimFree, no w line), where PathOrder#1 last read approachRadius 48, the value the verdict reported.
  • docs/replay-format.md (freed blocks, lines 1376 to 1383 and 1707 to 1715): a freed object is not walked until SimAlloc hands its address out again, so the difference goes against the documented format, and filing it as a kit gap (Replay: Do not compare a freed target's bytes byte-tactics-moddable#1380) is right.

Leakage: none. Every name is a kit or recording name; no control flow, helper breakdown, source text or reasons.

Findings

  • optional (applied in e089b23 with the suggested wording): "the reference writes nothing to the target before its SimFree" was broader than the source supports; state only the recorded fact, that those calls carry no w line for the target and the reference leaves its fields as they were.

approve

Answer finding 5 of the code review's first round: an event's offset is
inside the block when it fits below block_max of the manifest.

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

CubeB commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

Spec reviewer: phase 2 (leakage) on the diff e089b23..d22b9bf of specs/movement.md, kit interfaces-v110 / reference-traces-v65. A fresh reviewer with the source; the spec writer posts it with the push.

The diff answers finding 5 of code review round 1 on #92: which bound "inside the block" uses for an offset an event gives.

Checked

  • Lint: speclint.py against the v110 export passes.
  • Leakage: read beside the event validation and the path event handling of the movement source. No source names, control flow or C. The source checks nothing about where a target or requester lies, so the bound comes only from the Spec: Reject a malformed effect at delivery #25 limits and the ABI.
  • ABI 2.1, 4.1 and 16: block_max is the most the block can grow to and the load data starts at its ceiling; the block's current size is in no manifest field or data word (8.2), so a module builds block_max in as a constant. An offset past the current end but below the ceiling reads bytes never written, whose word names no class, so the outcome is the same as with the current end; the memory runs past the ceiling, so the read cannot trap.
  • Consistency: the target bullet and ApplyPathEvent now share one bound; "Arguments outside the block" (section 2) and "Nothing outside the block" (section 3) mean something else and do not clash.

Findings (all optional, applied in the pushed revision and re-read: approve)

  • Cover "inside or outside the block" for an offset an event gives.
  • State the bound in offset terms, unsigned, so an address sum cannot wrap.
  • Drop the reason clause.
  • Say which record size counts: 4 bytes before the class word is read, the named kind's record size after.

approve

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.

1 participant