# Edits as commands: optimistic, reconciled by seq/ack and a hash Round `net-edit`, 2026-10-27: step (c) of `docs/net-entity.md` §10. Scratch, scripts and raw runs: `logs/net-edit/` (`runs/`, `owner/`). Measurement code: branch `net-edit-meas` (NOT FOR MERGE) and the detached base `net-edit-base-meas` (main 20d4dbe2 plus the browser probe). ## Answer - **Built** (branch `net-edit`): every terrain and entity edit, undo and redo travels as a command with a client sequence number. The editor applies it locally at once with the shared code; the server applies commands in arrival order and sends the **command** (not the result bytes) to every session holding the region or structure at full detail, each region's version pair and post-edit hash attached; the editor's copy is its ack. Holders replay it and check the hash. One rule for regions and structures (§1). - **Click → visible, browser on utsuho** (headed Chromium, RX 5700; §3): main **170 / 219 / 445 ms** p50 (LAN / 40 ms ±10, 1 % / 100 ms ±10, 2 %), p95 247 / 320 / 781 → branch **8 / 12 / 12 ms** p50, p95 22 / 18 / 24: the next frame after the click, at every condition. - **Bytes per edit** (sphere r 12, editor and each peer; §2): fixture **206 KB → 76 B**; natural terrain **2.9 MB → 100 B** (main sent ~3 MB because every edit re-sent its region and all 26 neighbours' full trees). - **Realtime state while editing** (§2): at 100 ms / 2 % entity state was 0.9 s old at p50 and 2.6 s at p95 on the fixture (13 s / 34 s on natural terrain); with commands it is the same as without edits (55 / 165 ms). - **Determinism** (§4): **0 hash mismatches** in 8 721 predictions and 17 636 replays over 10 two-editor soaks (sphere / box / rotated box / rotated stamp, carve and fill, overlapping masked brushes, undo and redo, two editors on the same spot) at all three conditions (Bun / JSC); the browser (V8, server JSC) replayed 2 118 soak commands with 0 mismatches; entity edits 0 in 1 328 predictions and 2 655 replays. The soaks found three bugs, all fixed (§4.2): a prediction leak, undo predicted on a stale mirror, and regions bloating with orphan slots. - **Snaps** (§4): with two players hammering the same 48³ voxel spot every 300 ms, 12–20 % of predictions settle with a visible instant snap, median ~1 000 voxels (they were reordered at the server). A single editor never snaps. - **Floating bodies** (§5): a body resting on terrain the player carves keeps floating for **126 / 220 / 354 ms** (p50; p95 538 / 659 / 427), against 86 / 749 / 2 088 ms on main (where the hole itself also showed only after 78 / 190 / 369 ms). Owner decision. - **Client CPU** (§6): a predicted or replayed sphere edit costs 2.5–5 ms per region on the fixture and 4.7–8.6 ms on natural terrain (Bun, r 4–24, normals included; the browser measured 5–6 ms p50), a rotated stamp ~65 ms (owner decision). A brush drag at 60 edits/s holds its ack at one RTT on every link (4.6 KB/s); main could not carry even 10/s under loss. - **Deleted** (§1.7): whole-region undo restore, the 26-neighbour full-tree halo re-broadcast, the structure in-place re-broadcast, `applySculptOp`, and the full-tree subtree-flag walk at the end of every CSG edit. - **Middle option** (voxel diff to peers, §7): 7.9 KB (fixture) / 10.7 KB (natural) per peer per r 12 edit as sent, against 76–100 B for the command; peer CPU within ±1.5 ms for spheres, 30 vs 65 ms for a rotated stamp. Default kept: the command. - **Left for step d** (§8). ## 1. Design ### 1.1 One rule for terrain regions and entity structures A region and a structure are both one SVT64 tree. An edit command carries its brushes (world-space for terrain, entity-local for an entity), and every holder — the server, the editor's prediction, each peer — turns it into bytes with the same code in `common/src/edit-command.ts`: - `applyRegionCsg(coord, bytes, palette, brushes, resolver)`: translate the brushes into the region, clip their box (`regionBrushBbox`), run `applyCsgEditFull`. `applyStructureCsg` is the same at the origin. - `svtStateHash(bytes, palette)`: a 32-bit hash of the result, carried in the command so each holder checks it reproduced the server's bytes. - `diffRegionVoxels`: undo / redo as a voxel patch (§1.4). - `haloNeighbourBoxes`: which neighbours' normals an edit's box can change (only the facing layer, only if the box reaches the region's outer layer). The server keeps copy-on-write and interning for structures; the command names the structure it applied to and the one it produced. ### 1.2 Wire | message | id | dir | payload | |---|---|---|---| | `EditTerrain` | 0x05 | C→S | `[seq:u32][len:u32][brushes]` | | `EditEntity` | 0x0b | C→S | `[seq:u32][entityId:u32][len:u32][brushes]` | | `Undo` / `Redo` | 0x17 / 0x18 | C→S | `[seq:u32]` | | `RequestStructure` | 0x22 | C→S | `[structureId:u32]`: a replay whose hash failed | | `RegionEditCmd` | 0xa2 | S→C | `[own:u8][seq:u32][order:u32][isPatch:u8][n:u16]`, `n ×` `[rx ry rz:i32][baseVersion:u32][version:u32][hash:u32]`, then the brushes or, for undo / redo, one `RegionVoxelDelta` per region | | `EntityEditCmd` | 0xa3 | S→C | `[own:u8][seq:u32][order:u32][entityId][from][to][hash][len][brushes]` | - The editor's copy (`own = 1`) is its **ack**. It lists every region the brushes overlap, changed or not, so each prediction resolves. - `order` is the server's apply order, one counter for all edits. - A sphere edit inside one region is **76 B** (sphere) to **105 B** (stamp). ### 1.3 Server (`server/src/net/edit-commands.ts`) - Applies commands in arrival order (`applyTerrainEdit`, `applyRegionPatches`, `EntityManager.editEntity`). - Sends the command to every session holding an affected region at full detail (`servedLevel` 0), and to the editor. It goes straight to the socket, or on the bulk lane behind a message still queued for one of its regions (the lane now orders a message against several regions). - Result bytes go only where a command cannot be replayed: - the editor, for a region it does not hold at full detail (as before); - a peer holding the region **pruned**: it is re-anchored, and the streamer re-serves it at the peer's own level (`reanchorRegionServe`); - holders of a neighbour whose normals changed but who did not get the command (rare: they hold the neighbour but not the edited region); - a holder whose replay failed the hash (`RequestRegion` / `RequestStructure`). - Stamp sources: before a stamp command, each replayer is sent the prefab's preview structure if it does not hold it. - The neighbour normals refresh now covers only the layer an edit reaches (`haloNeighbourBoxes`), and a refresh that left a neighbour's normals unchanged is not broadcast. Main refreshed and re-sent all 26 neighbours' full trees on every edit: most of the ~205 KB (fixture) and ~3 MB (natural terrain) per edit. ### 1.4 Undo / redo Main restored whole-region snapshots: an undo also reverted other players' later edits anywhere in the region, and peers needed the bytes. Now an undo writes back only the voxels that differ from the snapshot **inside the undone edit's own box** (`diffRegionVoxels`), and travels as that voxel patch; every holder replays it with `applyVoxelDelta` (deterministic, the CA path's twin of the Rust apply). Redo is the same towards the `after` state. The editor predicts it from its mirrored undo history (the verified states before and after each of its acked edits). ### 1.5 Client (`client/src/world/region-edits.ts`, `client/src/parts/entity-edits.ts`) - **Predict.** `WorldClient.sendEditTerrain` encodes the brushes, decodes them back (the wire stores f32, so the client predicts with exactly the server's inputs), applies them to every region it holds at full detail, refreshes normals over the box and the neighbours' facing layers, then sends. Stamps resolve against the preview structures the client holds. - **Replay.** Commands go through the ingest queue in order with the region's other messages (never coalesced away), are version-gated like CA deltas (a skipped version asks for the region), replayed, and their hash checked. A failed hash asks for the region: the re-served bytes replace the state. - **Reconcile.** A region with predictions in flight keeps its server-verified bytes. Commands and server bytes advance the verified state in server order; a peer's command is also shown at once on top of the predictions. When the last prediction is acked, the shown state is compared with the verified one; if they differ (a reordered or rejected prediction) it **snaps instantly** to the verified bytes, normals re-derived over the box where they can differ. No blend (owner, 2026-10-27). - **Entities.** The prediction is registered under a client-only structure id (`client-structure-ids.ts`, shared with interned model structures) and the entity points at it; a peer's command shows at once on top of it; `core/structure` changes are held while predictions are in flight; the ack points the entity at the server's structure holding the verified bytes. - **Robustness.** The ingest queue announces each command before its per-region entries: the client mirrors the server's undo history per command, and a prediction on a region the ack does not list resolves as unchanged. Undo / redo are predicted only when no own edit is in flight, and their acks always apply the server's patch. A prediction unacked for 10 s is abandoned for the server's bytes. - **Display.** A resident region whose bytes changed requests a GPU sync on the next frame (it waited for the region manager's 200 ms catch-up tick before), for predicted, replayed and server-sent edits alike. ### 1.6 Determinism - Same code, same inputs: brushes as decoded from the wire, the same translation and clipping (moved into `common/`), the same stamp source. - The CSG and normals code uses only IEEE-exact operations; `Math.hypot` in the stamp surface probe became `Math.sqrt(x² + y² + z²)` (hypot is engine-approximated, and Chromium is V8 while the server is JSC). - Normals are not hashed: a client reads a pruned or absent neighbour as air (as for CA deltas), so frontier normals may differ; the material is checked. ### 1.7 What was deleted - `restoreRegionSnapshot` (whole-region undo restore). - The structure in-place re-broadcast (`StructureManager.updateInPlace` no longer sends; the caller sends the command or the bytes). - `applySculptOp` (sculpt now only computes brushes; they run as an ordinary command). - The 26-neighbour full-tree halo re-broadcast on every edit (§1.3). - The full-tree subtree-flag walk at the end of every CSG edit: it now walks only where the brushes reach (4.4 of 5.9 ms on a 1 MB natural region; output identical, `svt64-edit-flags.test.ts`). - The input-relative compaction threshold of `applyCsgEditFull`: an edited region is now compacted once its pool exceeds 1.5× its **live** tree (`compactSvtIfBloated`), and undo / redo patches compact by the same rule (`applyRegionPatch`). Under the old rule a region edited 600 times held 5.3 MB for a 130 KB tree (40×), every edit copied and walked all of it (server edits slowed to 70–270 ms in the soak) and every holder now replays edits; on main the same creep was there for the server alone. ## 2. Headless runs: latency, bytes, realtime age (main 20d4dbe2 vs branch) **Method.** - Server: main 20d4dbe2 (detached worktree `net-edit-base`) or the branch (`net-edit-meas`, the branch plus measurement code), fresh per run, in a private network namespace on nazrin (`logs/net-edit/netns.sh`: a veth pair; netem delay and jitter per direction, loss on the server→client side, pfifo child, offloads off; no host firewall or sysctl change). - Clients: `scripts/net-edit/editclient.ts` (branch `net-edit-meas`, NOT FOR MERGE) on the host, running the **real client code** (`region-ingest`, `region-edits`, the region manager's receive functions, the entity interpolator) against a stub GPU. An editor E and a watcher W at the same spot; E carves / fills a sphere r 12 every 2 s. - Scenes: the fixture (`surface-gi-motion`, slab) and natural terrain (`WORLD_GEN=terrain`, seed 42691, fresh world each run, at spawn). - Benches start settled: edits from 30 s (fixture) / 100 s (natural, with the netem condition applied at 80 s, after the cold arrival). - Conditions: LAN, 40 ms ±10 + 1 %, 100 ms ±10 + 2 % (RTT). - Two reps per cell (58 edits), pooled. The `diff` arm is §7's middle option. - "Editor visible" for the branch is the local apply incl. normals (Bun); §3 has the browser. "Peer visible" is the arrival of what changes the peer's view. Realtime age is the NetProbe stamp age (`docs/net-latency.md`). | cond | scene | arm | edits | editor visible p50/p95/max ms | ack p50/p95/max | peer visible p50/p95/max | editor B/edit | peer B/edit | realtime age editing p50/p95/p99 | idle p50/p95/p99 | mismatch | snaps | |---|---|---|---|---|---|---|---|---|---|---|---|---| | LAN | fixture | main | 58 | 35/49/109 | – | 34/43/104 | 206,260 | 206,260 | 0/1/1 | 0/1/1 | 0 | 0 | | LAN | fixture | branch | 58 | 5/22/30 (local) | 11/31/56 | 11/31/54 | 76 | 76 | 0/1/1 | 0/1/1 | 0 | 0 | | LAN | fixture | diff | 58 | 5/23/30 (local) | 15/34/53 | 15/34/53 | 76 | 7,941 | 0/1/1 | 0/1/1 | 0 | 0 | | LAN | natural | main | 58 | 358/418/442 | – | 356/415/440 | 2,938,320 | 2,938,268 | 0/1/14 | 0/1/1 | 0 | 0 | | LAN | natural | branch | 58 | 16/27/56 (local) | 95/109/114 | 97/109/113 | 100 | 100 | 0/1/1 | 0/0/1 | 0 | 0 | | LAN | natural | diff | 58 | 15/27/59 (local) | 95/121/139 | 92/119/137 | 100 | 10,659 | 0/1/1 | 0/0/1 | 0 | 0 | | 40 ms ±10, 1 % | fixture | main | 58 | 214/369/540 | – | 161/280/411 | 206,260 | 206,260 | 24/518/709 | 22/31/82 | 0 | 0 | | 40 ms ±10, 1 % | fixture | branch | 58 | 5/22/31 (local) | 53/84/108 | 56/81/91 | 76 | 76 | 22/42/88 | 22/35/86 | 0 | 0 | | 40 ms ±10, 1 % | fixture | diff | 58 | 5/21/29 (local) | 56/72/91 | 60/139/200 | 76 | 7,941 | 22/38/88 | 22/51/94 | 0 | 0 | | 40 ms ±10, 1 % | natural | main | 58 | 1097/2681/3495 | – | 528/2132/2428 | 1,054,312 | 1,033,957 | 3199/8664/9674 | 20/27/91 | 0 | 0 | | 40 ms ±10, 1 % | natural | branch | 58 | 16/29/58 (local) | 130/164/184 | 128/158/178 | 100 | 100 | 20/25/84 | 20/25/88 | 0 | 0 | | 40 ms ±10, 1 % | natural | diff | 58 | 16/26/59 (local) | 139/163/173 | 138/170/192 | 100 | 10,659 | 20/29/91 | 20/25/84 | 0 | 0 | | 100 ms ±10, 2 % | fixture | main | 58 | 545/1689/2318 | – | 289/651/964 | 194,935 | 198,949 | 870/2630/3866 | 54/149/184 | 0 | 0 | | 100 ms ±10, 2 % | fixture | branch | 58 | 6/22/31 (local) | 116/227/257 | 122/231/263 | 76 | 76 | 54/165/204 | 57/171/212 | 0 | 0 | | 100 ms ±10, 2 % | fixture | diff | 58 | 5/23/29 (local) | 120/198/234 | 159/330/451 | 76 | 7,941 | 55/171/215 | 54/164/199 | 0 | 0 | | 100 ms ±10, 2 % | natural | main | 58 | 3881/9368/9941 | – | 1694/13108/19108 | 305,770 | 323,906 | 13363/33947/36649 | 51/111/180 | 0 | 0 | | 100 ms ±10, 2 % | natural | branch | 58 | 16/27/60 (local) | 187/219/289 | 188/252/302 | 100 | 100 | 51/138/190 | 51/87/170 | 0 | 0 | | 100 ms ±10, 2 % | natural | diff | 58 | 16/27/59 (local) | 194/285/398 | 209/374/496 | 100 | 10,659 | 51/141/192 | 51/141/190 | 0 | 0 | **Reading.** - The edit shows at once for the editor; the ack (≈ RTT + the server's apply) and the peer see it after the same one-way trip. - Natural terrain's ack (95 ms on the LAN) is the server's own edit cost on two 1 MB regions (apply, persist, caches); main paid that too, then ~3 MB of results. - Main under loss: the result bytes stall entity state (age p95 0.5–2.6 s on the fixture, 9–34 s on natural terrain). Commands remove that: the age while editing equals the idle age. - Main's natural-terrain bytes at 40 / 100 ms fall to 1.0 / 0.3 MB per edit only because peers fell behind the lane's high-water and were skipped (re-served later). ## 3. Browser: click → visible frame (headed Chromium on utsuho) **Method.** Headed Chromium on utsuho (RX 5700, 60 Hz) at the fixture viewpoint; the server in the netns on nazrin, reached through a userspace TCP proxy on nazrin (`logs/net-edit/tcpproxy.ts`) so the browser's link carries netem. The condition is applied after the cold arrival. 24 bench `edit` commands per cell (sphere r 12, carve / fill), each through `WorldClient.sendEditTerrain`; a NOT-FOR-MERGE probe stamps the send, the end of the local apply, the arrival of the ack (branch) or `RegionEdit` (main), and the GPU re-upload of the edited region (`onRegionRePromoted`, the frame it shows in). Under `logs/utsuho.lock`. | condition | main visible p50 / p95 / max ms | main result arrival p50 / p95 | branch visible p50 / p95 / max | branch local apply p50 / p95 | branch ack p50 / p95 | |---|---|---|---|---|---| | LAN | 170 / 247 / 249 | 53 / 70 | **8 / 22 / 30** | 6 / 21 | 15 / 30 | | 40 ms ±10, 1 % | 219 / 320 / 338 | 92 / 229 | **12 / 18 / 31** | 5 / 17 | 56 / 69 | | 100 ms ±10, 2 % | 445 / 781 / 846 | 357 / 659 | **12 / 24 / 30** | 5 / 22 | 115 / 217 | - A first branch run showed 111–172 ms p50: the local apply took 6 ms but the region manager re-uploaded edited regions only on its 200 ms catch-up sync while the camera was still. Fixed on the branch (an edited resident region requests a sync on the next frame), which also cuts main's ~100 ms average wait after a `RegionEdit` arrives. - The local apply (V8) is 5–6 ms p50, 17–22 ms p95 (sphere r 12 on the fixture, normals included). ## 4. Determinism and snaps ### 4.1 Soaks **Method.** Two editors on the same spot, each sending every 300 ms a random command from: sphere carve, sphere fill, box, rotated box (any yaw), rotated die stamp (any yaw), three overlapping brushes with a mask, undo, redo; plus a watcher. 150 s per run (~500 commands per editor), the real client code (`region-edits.ts`); the server's hash in every command checks every holder's result. Runs after the §4.2 fixes: | condition | runs | predictions | acked | replays (editors + watcher) | **hash mismatches** | snaps all / visible (% of predictions) | visible snap voxels p50 / p95 / max | send → visible snap p50 / p95 ms | |---|---|---|---|---|---|---|---|---| | LAN | 3 | 2 712 | 2 708 | 5 396 | **0** | 586 / 318 (11.7 %) | 1 022 / 11 242 / 59 210 | 213 / 396 | | 40 ms ±10, 1 % | 2 | 1 748 | 1 744 | 3 493 | **0** | 588 / 292 (16.7 %) | 948 / 11 180 / 48 470 | 241 / 432 | | 100 ms ±10, 2 % | 5 | 4 261 | 4 252 | 8 747 | **0** | 1 648 / 869 (20.4 %) | 1 234 / 16 738 / 107 168 | 247 / 513 | - Unacked = still in flight at the end of the run. - **Browser (V8)**: Chromium on utsuho watching a two-editor soak replayed 1 123 commands at LAN and 995 at 100 ms / 2 %, **0 mismatches** (the server is Bun / JSC, the browser V8). - **Entity edits** (two editors predicting carves / fills on one die every 400 ms, copy-on-write on the first edit then in place, plus a watcher; `scripts/net-edit/editclient.ts` mode `entsoak`): 1 328 predictions, 2 655 replays, **0 mismatches** (LAN and 100 ms / 2 %). After showing peers' edits on top of predictions (as terrain does), snaps at 100 ms / 2 % fell from 201 to 26 per 221 predictions for the editor that lost the race. - A "snap" here is a settle whose shown state's bytes differed from the verified ones; half of them change no voxel (the same voxels in a different tree layout) and are invisible. Visible snaps are 13–21 % of predictions in this deliberately adversarial soak (two players overlapping brushes on the same 48³ spot, both every 300 ms): each is a prediction the server applied after a peer's overlapping edit. The time from send to snap is 180–220 ms p50 (370–490 p95), mostly the queue of in-flight edits before the last ack. ### 4.2 Bugs the soaks found (fixed) - **Unacked predictions leaked** (a client OOM at 3 GB): an undo predicted on a region the server's undo did not list was never acked, and kept every later state. Now each command is announced before its regions are queued; predictions of that seq on regions it does not list resolve as unchanged, and the undo history is mirrored per command, exactly when the server records one. A prediction unacked for 10 s is abandoned for the server's bytes (0 in every later soak). - **Undo predicted on a stale mirror**: an undo sent while the previous edit was still unacked predicted undoing the edit before it; the ack's fast path then failed the hash (2 mismatches at 100 ms / 2 %). Undo / redo are no longer predicted while an own edit is in flight, and a patch ack always applies the server's patch (a wrong guess snaps). - **Regions bloated with orphan slots** (the two-editor soak: server edits slowed to 70–270 ms and the browser watching it dropped its session): see §1.7, compaction against the live tree. Every soak above except the two most recent ones ran with the old rule. - Before the first two fixes one 100 ms / 2 % run showed 1 hash failure in ~850 predictions with no undo involved; it did not recur in 5 later lossy runs and was not explained. Every failure self-heals (`RequestRegion`). ## 5. Bodies on carved terrain (the floating body) **Method.** Headless editor (real interpolator). Every 4 s a die is spawned on untouched slab, and 3 s later the player carves a sphere r 56 under it (wider than the die). "Floating" = from the carve becoming visible to the editor (the local apply on the branch; the result's arrival on main) to the frame the interpolated die is 0.1 v below its rest height. Two reps of 12 carves per cell, pooled. | condition | arm | n | hole visible after click ms | ack / result | first falling pose arrives | body visibly falls p50 / p95 | **floating p50 / p95** | |---|---|---|---|---|---|---|---| | LAN | main | 24 | 78 | 78 | 126 | 164 / 2 684 | 86 / 1 585 | | LAN | branch | 24 | 36 (local) | 50 | 120 | 153 / 785 | **126 / 538** | | 40 ms ±10, 1 % | main | 22 | 190 | 190 | 889 | 915 / 4 673 | 749 / 4 483 | | 40 ms ±10, 1 % | branch | 24 | 36 (local) | 91 | 160 | 243 / 832 | **220 / 659** | | 100 ms ±10, 2 % | main | 10 | 369 | 369 | 1 949 | 2 379 / 5 971 | 2 088 / 5 619 | | 100 ms ±10, 2 % | branch | 24 | 20 (local) | 154 | 215 | 378 / 513 | **354 / 427** | - On the branch the float is the ack's round trip, the server's own time from the edit to the first falling pose (~60–70 ms: wake, the physics mirror's terrain update, the next 30 Hz pose batch), and the display delay D for that body (~30–160 ms). - Main's numbers under loss are worse because the result bytes delay the poses too; on the LAN main floats less only because its hole appears late. **Options (owner decision).** | option | float at LAN / 40 / 100 ms (p50) | cost | rules | |---|---|---|---| | A. Accept until step d | 126 / 220 / 354 ms | none | – | | B. Server: send a woken body's first falling pose at once (skip the wait for the next look tick, wake bodies on the edit before the physics mirror catches up) | estimated −20 to −50 ms | small; server only | none | | C. Client: render bodies touching a locally carved box with zero display delay until the server's falling pose arrives | −D (30–160 ms) | small | a per-body delay switch: a visible mode shift — **not recommended** | | D. Step d: a body whose support the player's own edit removed counts as *touched* and enters the local lane at rest (the approved entry E3), so it falls at local-frame latency | → ~1 frame | part of step d | none (entered at rest, no blend) | Recommendation: **A now, D in step d** (one line in the lane's entry rule), B only if measured to matter after d. ## 6. Client CPU Per region, Bun, p50 / p95 ms (`scripts/net-edit/cpu-bench.ts`; a fixture slab region and a 1 MB natural-terrain region at spawn; sphere carves at the surface, a rotated die stamp): | region | edit | CSG apply | normals refresh | hash | **total (predict = replay)** | |---|---|---|---|---|---| | fixture | sphere r 4 | 0.23 / 0.46 | 2.27 / 3.84 | 0.02 | **2.5** | | fixture | sphere r 12 | 0.59 / 1.00 | 2.29 / 4.08 | 0.02 | **2.9** | | fixture | sphere r 24 | 1.34 / 1.65 | 3.50 / 3.82 | 0.03 | **4.9** | | fixture | rotated stamp | 55.5 / 59.0 | 9.3 / 11.7 | 0.09 | **65** | | natural | sphere r 4 | 1.67 / 2.07 | 2.46 / 3.31 | 0.59 | **4.7** | | natural | sphere r 12 | 2.04 / 3.39 | 2.83 / 4.95 | 0.60 | **5.5** | | natural | sphere r 24 | 2.96 / 4.00 | 5.04 / 7.71 | 0.60 | **8.6** | | natural | rotated stamp | 54.7 / 61.5 | 9.2 / 10.3 | 0.73 | **65** | - Before the windowed flag walk (§1.7) a natural-terrain sphere's CSG apply was 6–6.5 ms; it is the same function on the server. - In the browser (V8) the local apply of a fixture sphere r 12 is 5–6 ms p50, 17–22 ms p95 (§3). An edit spanning two regions costs twice. - A rotated stamp samples its source per target voxel over its whole box; every holder now pays the server's ~55 ms (owner decision 2). - **Brush drag** (fixture, sphere r 8 along a line; the editor and a watcher, 60 s): | condition | rate | branch ack p50 / p95 ms (first third → last third p50) | branch KB/s per client | main KB/s delivered | |---|---|---|---|---| | LAN | 10 / 20 / 30 / 60 per s | 5 / 7 → 5 / 7 → 5 / 6 → 5 / 7 (flat) | 0.7 / 1.5 / 2.2 / 4.6 | 1 848 / 3 719 / 5 514 / 6 672 | | 40 ms ±10, 1 % | 10 / 20 / 30 / 60 | 47 / 81 → 45 / 69 → 45 / 59 → 46 / 70 (flat) | 0.7 / 1.5 / 2.2 / 4.6 | 460 / 445 / 542 / 584 | | 100 ms ±10, 2 % | 10 / 20 / 30 / 60 | 107 / 186 → 108 / 207 → 108 / 204 → 112 / 208 (flat) | 0.7 / 1.5 / 2.2 / 4.5 | 135 / 118 / 138 / 141 | The branch holds the ack at ≈ RTT at 60 edits/s on every link; the cost is CPU (≈ 2 ms per fixture edit in Bun; §6 table for natural terrain). Main needs ~185 KB per edit, so under 1 % loss it delivers ~2.5 edits/s and under 2 % ~0.7/s; the rest queue (and peers fall behind and are re-served). ## 7. The middle option: a voxel diff to peers Implemented in the measurement branch (`EDIT_PEER_MODE=diff`: peers get each region's changed voxels as a `RegionVoxelDelta`, applied through the CA path's `applyVoxelDelta` and a bbox-scoped normals refresh; the editor still gets the command). Sizes and CPU per region (Bun, `scripts/net-edit/cpu-bench.ts`): | region | edit | command: bytes | command: peer CPU | diff: voxels | diff: bytes raw / deflated | diff: peer CPU (apply + normals) | diff: server CPU | result (main): own region deflated | |---|---|---|---|---|---|---|---|---| | fixture | r 4 | 76 | 2.5 | 149 | 447 / 188 | 0.2 + 2.4 = 2.6 | 0.1 | 20 KB | | fixture | r 12 | 76 | 2.9 | 3 788 | 8 729 / 1 147 | 0.5 + 2.3 = 2.8 | 1.9 | 24 KB | | fixture | r 24 | 76 | 4.9 | 29 751 | 64 869 / 4 750 | 2.1 + 3.7 = 5.8 | 12.5 | 34 KB | | fixture | stamp | 105 | 65 | 265 408 | 563 465 / 22 844 | 20.9 + 9.1 = 30 | 62.8 | 39 KB | | natural | r 4 | 76 | 4.7 | 131 | 450 / 233 | 0.9 + 2.5 = 3.4 | 0.2 | 202 KB | | natural | r 12 | 76 | 5.5 | 3 674 | 9 037 / 1 447 | 1.3 + 2.7 = 4.0 | 3.0 | 206 KB | | natural | r 24 | 76 | 8.6 | 29 495 | 66 110 / 5 772 | 2.6 + 4.5 = 7.1 | 19.0 | 217 KB | | natural | stamp | 105 | 65 | 268 410 | 575 760 / 25 956 | 19.8 + 8.9 = 29 | 81.8 | 223 KB | (main also re-sent every neighbour's full tree: ~206 KB / 2.9 MB per edit in total, §2.) A brush drag by another player at 20 edits/s costs a peer ~2.5–5.5 ms × 20 = 50–110 ms of CPU per second with either option (the drag's spheres are small); the bytes are 1.5 KB/s with commands and ~20–170 KB/s with diffs. - Live, sphere r 12 (§2 `diff` rows): 7.9 KB (fixture) / 10.7 KB (natural) per peer per edit as sent today (deltas are not deflated), against 76 / 100 B for the command and 206 KB / 2.9 MB for main. Peer latency is the same or slightly worse (more bytes). - **Default kept: the command.** The diff is 6–5 000× the bytes (deflated 2–250×) and costs the server 0.1–80 ms to compute; peer CPU is within ±1.5 ms for spheres. Only rotated stamps differ: 65 ms to replay as a command, 30 ms to apply as a diff. It would matter only if replay CPU on peers became the bottleneck (e.g. many players stamping rotated prefabs), and could then be chosen per command (diff for stamps, command for spheres). ## 8. Left ready for step d - The client's shown terrain is the predicted state: a local physics lane can collide with exactly what the player sees (`region-manager` entries hold it; the verified state sits beside it in `region-edits.ts`). - Commands carry a client seq and the server's apply order; acks resolve per region / structure. A grab or a local-lane hand-off can reuse the same seq / ack / order machinery. - Structures predicted under client-only ids (`client-structure-ids.ts`) and `core/structure` repoint holding: a locally simulated body can show a predicted shape before the server confirms it. - §5 option D: "own edit removed its support" is a ready trigger for the lane's entry at rest. ## 9. Owner decisions 1. **Floating bodies** (§5): A (accept until step d, then D) — recommended; or B (server-side, ~20–50 ms) now. 2. **Rotated stamps are expensive to replay**: 55–65 ms of main-thread CPU per region per holder (the server pays it too). Options: accept; replay stamps in a worker; or send stamps' results as a voxel diff (§7) so peers only apply. 3. **Undo semantics changed** (§1.4): undo now reverts only the undone edit's own box instead of restoring the whole region (which reverted other players' later edits anywhere in that region). Confirm. 4. **Snaps under contention** (§4.1): 13–21 % visible snaps when two players hammer the same spot; a single editor never snaps. Accept (the approved instant snap), or later order-independent brushes. ## 10. Hygiene - Every server under `systemd-run` (10 G), clients 3 G, benches 6 G; at most two heavy jobs; ports 3960–3979; no timing run while a `/tmp/gi-gate*.lock` was held; utsuho runs under `logs/utsuho.lock`. - netem only on the private veth pair (`nev0` / `nev1` in netns `nens`), cleared after every run. - Scratch: `logs/net-edit/` (`runs/`, `matrix.sh`, `run.sh`, `clients.sh`, `soak.sh`, `entsoak.sh`, `float2.sh`, `extra.sh`, `bdrive.sh`, `bsoak.sh`, `edrive.mjs`, `tcpproxy.ts`, `anal.py`, `pool.py`, `anal_extra.py`, `soakan.py`, `bana.py`).