[PR #1114] [MERGED] Run single player on its server thread by default #3060

Closed
opened 2026-11-02 16:01:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1114
Author: @ludovic111
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @ludovic111

Base: main ← Head: fix/server-thread-default-v2


📝 Commits (10+)

  • 86b58b7 Client of a server: abilities from the server, flight sent back
  • f59f6e3 lan_e2e portals: take the portals away afterwards
  • 0468b75 Run single player on its server thread by default
  • 2f883b5 Keep the command harness in the frame; compare finished border chunks
  • 55891f9 Wait for the server's block in the agent's place, try hidden spots
  • 8b75ac3 lan_e2e and agent_control_e2e on the server thread
  • 05e169f agent_control_e2e pick: wait for the server to clear the cursor
  • b7453b1 agent_control_e2e survival: wait for the log's drop or its pickup
  • 26142a9 Merge remote-tracking branch 'origin/main' into HEAD
  • 8974769 Moving pistons: pass the block position to particle_sprite (main build fix)

📊 Changes

11 files changed (+264 additions, -38 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+9 -4)
📝 crates/horizon-client/src/game/agent.rs (+11 -1)
📝 crates/horizon-client/src/game/control.rs (+3 -1)
📝 crates/horizon-client/src/game/integrated.rs (+3 -3)
📝 crates/horizon-client/src/game/moving_pistons.rs (+3 -1)
📝 crates/horizon-client/src/game/remote.rs (+55 -2)
📝 crates/horizon-client/src/lan/hub.rs (+13 -0)
📝 crates/horizon-protocol/src/packets/play.rs (+14 -0)
📝 tools/agent_control_e2e.py (+39 -12)
📝 tools/lan_e2e.py (+85 -11)
📝 tools/test_save_roundtrip_parity.py (+29 -3)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #1072

What

Single player's world now runs on the integrated server thread by default, as vanilla's does, so a world tick no longer holds up a frame.

  • --server-thread stays.
  • New --no-server-thread flag. HORIZON_SERVER_THREAD=0 also keeps the world in the frame, as an escape hatch.
  • The command harness (HORIZON_COMMAND_SCRIPT) drives the world without the event loop, so it stays in the frame.

The prerequisites #1088 and #1095 are merged. This branch also carries the commits of #1108, which it needs. Merge #1108 first. GitHub then drops the duplicates from this PR's diff.

PR What State
#1099 lan_e2e swings flake: root cause merged
#1100 agent_control_e2e in the frame: wait for the world; a crown spawn; hidden trunks merged
#1108 Client of a server: abilities from the server, flight sent back. Creative players could not fly on the server thread. Also: lan_e2e portals takes its portals away afterwards. open

The two test problems the brief asked about

agent_control_e2e pick step 3: a wait in the test, as in vanilla

Step 2 clones a stack in the creative tab and closes the screen. In vanilla that clone lives only on the client:

  • ItemPickerMenu's carried stack is the inventoryMenu's.
  • AbstractContainerMenu.removed clears the carried stack only for a ServerPlayer. So vanilla's client still holds the clone when the survival inventory opens.
  • With a stack in hand, the middle button's release sends CLONE (AbstractContainerScreen.mouseReleased).
  • The server finds that the carried stack it was told about is wrong. It sends the empty one back (broadcastChanges → SetCursorItem).

So a ghost stack for one round trip is vanilla behaviour. A client-side clear would diverge from vanilla. Step 3 now waits up to 20 ticks for the server's answer. The in-frame world, which has no server round trip, puts the clone away when the menu closes, as before.

lan_e2e swings: the root cause (fixed in #1099, merged)

  • check_xp made the host a spectator and never put it back.
  • A spectator sinks slowly (Player.travel multiplies vertical speed by 0.6, about 0.19 blocks from standing; this is vanilla-exact in both modes).
  • swings then set survival with the host at y=64, inside the floor. The guest was teleported to the host, into the floor's stone, which hid the soil it had to hit.
  • check_xp now restores survival and the host's saved position in a finally. No retry was added.

Found on the way: creative flight (#1108)

On the server thread, a player who joined a world already in creative could not fly. The remote client ignored most of ClientboundPlayerAbilitiesPacket, and never sent ServerboundPlayerAbilitiesPacket. This also broke perf_bench: the player fell during the scene load, and the scene timed out.

#1108 fixes this, and adds a lan_e2e flight check:

  • main, --server-thread: fails.
  • This branch: passes in both modes.

Flight also persists through save, quit and reopen on the server thread.

Other changes in this branch

  • place waits up to a second for the server's block on a client of a server. agent_control_e2e tries the next free spot when the trunk hides one.
  • agent_control_e2e survival waits for the log's drop or its pickup. Both come from the server a few ticks after break answers, and the old code raced them (StopIteration).
  • status lists the minecarts a client of a server was sent.
  • save_roundtrip compares finished border chunks only. Single player's server thread finishes the chunks its player tracks, as vanilla's integrated server does, including some that vanilla's server (view distance 4) left before their terrain or light.

How tested (Mac mini, head b7453b12 rebased on c1b5fe95, fast build; the runs on 39c12bd8 are under "Earlier runs")

Tool --server-thread (now the default) in the frame (HORIZON_SERVER_THREAD=0)
lan_e2e (41 checks, flight new) 41/41 41/41, 38/41, 40/41 (three full runs; see below)
agent_control_e2e --scenario all --mode both 12/12 12/12

The in-frame failures were different each run (brewing, xp, swings; then effects). Each one passed alone (2/2), and portals and flight are not involved. Main itself at c1b5fe95 failed clicks in its own full in-frame run (39/40) on the same busy machine. So these are flakes of the in-frame suite, not changes from this PR. One of them is a clear race: swings sets the guest's block to air and interacts at once, before the guest has the server's answer.

Earlier runs on this branch:

  • agent_control_e2e: 12/12 in both modes before the abilities commit.
  • survival: 6/6 in the frame and 2/2 on the server thread, run alone.
  • lan_e2e portals failed once, in the run where the host stood inside the floor: the host's End teleport never reached its window. It passed 3/3 alone and in every later full run.
  • lan_e2e flight failed in full --server-thread runs after the rebase. portals left the guest inside its Nether portal's frame (an obsidian ceiling three blocks up) and the host on its End portal. #1108 now has portals take both away.

Other checks:

  • cargo fmt --check: OK.
  • cargo clippy --locked --workspace --all-targets -D warnings: OK.
  • cargo test -p horizon-protocol -p horizon-client: all passed after the rebase. That is 980 + 90 + 64 + smaller suites, 0 failed.

Parity (tools/parity.py --changed origin/main, Mac mini, local only)

After the rebase: 102 passed, 0 failed in 63 min at -j4. That is every harness that depends on the 10 changed files, including save_roundtrip, world_spawn, player_sync, dedicated_server, secure_chat and online_mode. dedicated_server passed on parity.py's own retry without reused oracle results. Before the rebase: 101/101.

A full parity run on the desktop is still worth doing before merge: the changed set and the harnesses that tick single player's server ran here. The orchestrator can start it.

Perf (tools/perf_bench.py, Mac mini M4 Pro, release build, offscreen)

  • Setup: rd 16 and 32, forest and village, interleaved in-frame / server thread / in-frame / server thread.
  • The Mac mini was saturated by other sessions' builds throughout: 92–96% CPU busy, load average 68–109 on 14 threads. These numbers mostly measure contention.

Frame time in ms, mean of the two runs per mode:

RD scene in frame p50 / p95 / p99 / max server thread p50 / p95 / p99 / max
16 forest 2.0 / 44 / 90 / 274 3.0 / 62 / 120 / 246
16 village 10.3 / 62 / 102 / 181 4.5 / 48 / 79 / 162
32 forest 4.8 / 95 / 160 / 204 4.0 / 54 / 117 / 226
32 village 8.9 / 78 / 125 / 191 4.9 / 51 / 112 / 185

Average FPS per run (in-frame 1, server thread 1, in-frame 2, server thread 2):

RD scene IF1 ST1 IF2 ST2
16 forest 112 80 111 66
16 village 250 92 31 74
32 forest 70 72 33 77
32 village 64 75 37 72

What the numbers show:

  • The server thread is steadier. Its two runs agree within about 15% on every scene. In the frame, they swing up to 8×: village rd 16 ran at 250 FPS, then 31.
  • When the machine is starved, the in-frame tick lands on the frame. p95 and p99 are lower on the server thread in 3 of the 4 scenes (rd 32 forest p95: 54 vs 95 ms).
  • The in-frame world was faster on rd 16 forest, and its first village run had the best average.
  • Memory is about 190 MB more steady RSS at rd 16 and 530 MB more at rd 32 on the server thread. That is the server's own copy of the loaded chunks, as with vanilla's integrated server.
  • Scene loads were no slower:
    RD in frame server thread
    16 10.7 / 12.5 s 7.2 / 5.9 s
    32 18.1 / 28.1 s 20.3 / 17.2 s

A rerun on a quiet machine would give clean stutter numbers. #678's diagnosis (5–20 ms server ticks on the render thread at rd 32) is what this change removes from the frame.

Leftovers (FEATURES.md LATER)

  • The launcher's help text and README still give --server-thread as their example game argument (launcher/README.md, launcher/src/cli.rs, main.rs, mcp.rs). It still works, but it is now the default.
  • The lan_e2e portals one-off failure (see above).
  • The rare agent_control_e2e "no free spot beside to place" failure on main. This branch adds the hidden-spot retry.
  • In-frame lan_e2e flakes on a busy machine: swings (interacts before the guest has its air block), brewing, xp, effects, clicks.
  • The remote client ignores the walking_speed ability.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/1114 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/server-thread-default-v2` --- ### 📝 Commits (10+) - [`86b58b7`](https://github.com/horizon-rust/horizon/commit/86b58b71fab6f682201002c2d258996450dde3f0) Client of a server: abilities from the server, flight sent back - [`f59f6e3`](https://github.com/horizon-rust/horizon/commit/f59f6e3e84483ea6a7ef2c76062176260b8b2bf0) lan_e2e portals: take the portals away afterwards - [`0468b75`](https://github.com/horizon-rust/horizon/commit/0468b75c435215617e187ebdd87db194e917f6dc) Run single player on its server thread by default - [`2f883b5`](https://github.com/horizon-rust/horizon/commit/2f883b5cdbc44dd573bbe4f16dca2eec920ae8d3) Keep the command harness in the frame; compare finished border chunks - [`55891f9`](https://github.com/horizon-rust/horizon/commit/55891f9c95d083afd6247f97bd7ea9fd3b6b5864) Wait for the server's block in the agent's place, try hidden spots - [`8b75ac3`](https://github.com/horizon-rust/horizon/commit/8b75ac3cdbb2a1432464a416df26380a2fc6367f) lan_e2e and agent_control_e2e on the server thread - [`05e169f`](https://github.com/horizon-rust/horizon/commit/05e169f4e3cb32aa655b24eb5f1c9ea298af4ebd) agent_control_e2e pick: wait for the server to clear the cursor - [`b7453b1`](https://github.com/horizon-rust/horizon/commit/b7453b129bda2b6531a4f7816ca52f34b412c235) agent_control_e2e survival: wait for the log's drop or its pickup - [`26142a9`](https://github.com/horizon-rust/horizon/commit/26142a9c4013ba2bd13d42bf94697e61bac16391) Merge remote-tracking branch 'origin/main' into HEAD - [`8974769`](https://github.com/horizon-rust/horizon/commit/89747692d2fd885240b8475d68ead9cc29623489) Moving pistons: pass the block position to particle_sprite (main build fix) ### 📊 Changes **11 files changed** (+264 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+9 -4) 📝 `crates/horizon-client/src/game/agent.rs` (+11 -1) 📝 `crates/horizon-client/src/game/control.rs` (+3 -1) 📝 `crates/horizon-client/src/game/integrated.rs` (+3 -3) 📝 `crates/horizon-client/src/game/moving_pistons.rs` (+3 -1) 📝 `crates/horizon-client/src/game/remote.rs` (+55 -2) 📝 `crates/horizon-client/src/lan/hub.rs` (+13 -0) 📝 `crates/horizon-protocol/src/packets/play.rs` (+14 -0) 📝 `tools/agent_control_e2e.py` (+39 -12) 📝 `tools/lan_e2e.py` (+85 -11) 📝 `tools/test_save_roundtrip_parity.py` (+29 -3) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #1072 ## What Single player's world now runs on the integrated server thread by default, as vanilla's does, so a world tick no longer holds up a frame. - `--server-thread` stays. - New `--no-server-thread` flag. `HORIZON_SERVER_THREAD=0` also keeps the world in the frame, as an escape hatch. - The command harness (`HORIZON_COMMAND_SCRIPT`) drives the world without the event loop, so it stays in the frame. The prerequisites #1088 and #1095 are merged. This branch also carries the commits of #1108, which it needs. Merge #1108 first. GitHub then drops the duplicates from this PR's diff. | PR | What | State | | --- | --- | --- | | #1099 | `lan_e2e` swings flake: root cause | merged | | #1100 | `agent_control_e2e` in the frame: wait for the world; a crown spawn; hidden trunks | merged | | #1108 | Client of a server: abilities from the server, flight sent back. Creative players could not fly on the server thread. Also: `lan_e2e portals` takes its portals away afterwards. | open | ## The two test problems the brief asked about ### `agent_control_e2e pick` step 3: a wait in the test, as in vanilla Step 2 clones a stack in the creative tab and closes the screen. In vanilla that clone lives only on the client: - `ItemPickerMenu`'s carried stack is the `inventoryMenu`'s. - `AbstractContainerMenu.removed` clears the carried stack only for a `ServerPlayer`. So vanilla's client still holds the clone when the survival inventory opens. - With a stack in hand, the middle button's release sends `CLONE` (`AbstractContainerScreen.mouseReleased`). - The server finds that the carried stack it was told about is wrong. It sends the empty one back (`broadcastChanges` → `SetCursorItem`). So a ghost stack for one round trip is vanilla behaviour. A client-side clear would diverge from vanilla. Step 3 now waits up to 20 ticks for the server's answer. The in-frame world, which has no server round trip, puts the clone away when the menu closes, as before. ### `lan_e2e swings`: the root cause (fixed in #1099, merged) - `check_xp` made the host a spectator and never put it back. - A spectator sinks slowly (`Player.travel` multiplies vertical speed by 0.6, about 0.19 blocks from standing; this is vanilla-exact in both modes). - `swings` then set survival with the host at y=64, inside the floor. The guest was teleported to the host, into the floor's stone, which hid the soil it had to hit. - `check_xp` now restores survival and the host's saved position in a `finally`. No retry was added. ## Found on the way: creative flight (#1108) On the server thread, a player who joined a world already in creative could not fly. The remote client ignored most of `ClientboundPlayerAbilitiesPacket`, and never sent `ServerboundPlayerAbilitiesPacket`. This also broke `perf_bench`: the player fell during the scene load, and the scene timed out. #1108 fixes this, and adds a `lan_e2e flight` check: - main, `--server-thread`: fails. - This branch: passes in both modes. Flight also persists through save, quit and reopen on the server thread. ## Other changes in this branch - `place` waits up to a second for the server's block on a client of a server. `agent_control_e2e` tries the next free spot when the trunk hides one. - `agent_control_e2e survival` waits for the log's drop or its pickup. Both come from the server a few ticks after `break` answers, and the old code raced them (`StopIteration`). - `status` lists the minecarts a client of a server was sent. - `save_roundtrip` compares finished border chunks only. Single player's server thread finishes the chunks its player tracks, as vanilla's integrated server does, including some that vanilla's server (view distance 4) left before their terrain or light. ## How tested (Mac mini, head b7453b12 rebased on c1b5fe95, fast build; the runs on 39c12bd8 are under "Earlier runs") | Tool | `--server-thread` (now the default) | in the frame (`HORIZON_SERVER_THREAD=0`) | | --- | --- | --- | | `lan_e2e` (41 checks, `flight` new) | 41/41 | 41/41, 38/41, 40/41 (three full runs; see below) | | `agent_control_e2e --scenario all --mode both` | 12/12 | 12/12 | The in-frame failures were different each run (`brewing`, `xp`, `swings`; then `effects`). Each one passed alone (2/2), and `portals` and `flight` are not involved. Main itself at c1b5fe95 failed `clicks` in its own full in-frame run (39/40) on the same busy machine. So these are flakes of the in-frame suite, not changes from this PR. One of them is a clear race: `swings` sets the guest's block to air and interacts at once, before the guest has the server's answer. Earlier runs on this branch: - `agent_control_e2e`: 12/12 in both modes before the abilities commit. - `survival`: 6/6 in the frame and 2/2 on the server thread, run alone. - `lan_e2e portals` failed once, in the run where the host stood inside the floor: the host's End teleport never reached its window. It passed 3/3 alone and in every later full run. - `lan_e2e flight` failed in full `--server-thread` runs after the rebase. `portals` left the guest inside its Nether portal's frame (an obsidian ceiling three blocks up) and the host on its End portal. #1108 now has `portals` take both away. Other checks: - `cargo fmt --check`: OK. - `cargo clippy --locked --workspace --all-targets -D warnings`: OK. - `cargo test -p horizon-protocol -p horizon-client`: all passed after the rebase. That is 980 + 90 + 64 + smaller suites, 0 failed. ### Parity (`tools/parity.py --changed origin/main`, Mac mini, local only) After the rebase: **102 passed, 0 failed** in 63 min at -j4. That is every harness that depends on the 10 changed files, including `save_roundtrip`, `world_spawn`, `player_sync`, `dedicated_server`, `secure_chat` and `online_mode`. `dedicated_server` passed on parity.py's own retry without reused oracle results. Before the rebase: 101/101. A full parity run on the desktop is still worth doing before merge: the changed set and the harnesses that tick single player's server ran here. The orchestrator can start it. ### Perf (`tools/perf_bench.py`, Mac mini M4 Pro, release build, offscreen) - Setup: rd 16 and 32, forest and village, interleaved in-frame / server thread / in-frame / server thread. - **The Mac mini was saturated by other sessions' builds throughout**: 92–96% CPU busy, load average 68–109 on 14 threads. These numbers mostly measure contention. Frame time in ms, mean of the two runs per mode: | RD | scene | in frame p50 / p95 / p99 / max | server thread p50 / p95 / p99 / max | | --- | --- | --- | --- | | 16 | forest | 2.0 / 44 / 90 / 274 | 3.0 / 62 / 120 / 246 | | 16 | village | 10.3 / 62 / 102 / 181 | 4.5 / 48 / 79 / 162 | | 32 | forest | 4.8 / 95 / 160 / 204 | 4.0 / 54 / 117 / 226 | | 32 | village | 8.9 / 78 / 125 / 191 | 4.9 / 51 / 112 / 185 | Average FPS per run (in-frame 1, server thread 1, in-frame 2, server thread 2): | RD | scene | IF1 | ST1 | IF2 | ST2 | | --- | --- | --- | --- | --- | --- | | 16 | forest | 112 | 80 | 111 | 66 | | 16 | village | 250 | 92 | 31 | 74 | | 32 | forest | 70 | 72 | 33 | 77 | | 32 | village | 64 | 75 | 37 | 72 | What the numbers show: - **The server thread is steadier.** Its two runs agree within about 15% on every scene. In the frame, they swing up to 8×: village rd 16 ran at 250 FPS, then 31. - When the machine is starved, the in-frame tick lands on the frame. p95 and p99 are lower on the server thread in 3 of the 4 scenes (rd 32 forest p95: 54 vs 95 ms). - The in-frame world was faster on rd 16 forest, and its first village run had the best average. - Memory is about 190 MB more steady RSS at rd 16 and 530 MB more at rd 32 on the server thread. That is the server's own copy of the loaded chunks, as with vanilla's integrated server. - Scene loads were no slower: | RD | in frame | server thread | | --- | --- | --- | | 16 | 10.7 / 12.5 s | 7.2 / 5.9 s | | 32 | 18.1 / 28.1 s | 20.3 / 17.2 s | A rerun on a quiet machine would give clean stutter numbers. #678's diagnosis (5–20 ms server ticks on the render thread at rd 32) is what this change removes from the frame. ## Leftovers (FEATURES.md LATER) - The launcher's help text and README still give `--server-thread` as their example game argument (launcher/README.md, launcher/src/cli.rs, main.rs, mcp.rs). It still works, but it is now the default. - The `lan_e2e portals` one-off failure (see above). - The rare `agent_control_e2e` "no free spot beside to place" failure on main. This branch adds the hidden-spot retry. - In-frame `lan_e2e` flakes on a busy machine: `swings` (interacts before the guest has its air block), `brewing`, `xp`, `effects`, `clicks`. - The remote client ignores the `walking_speed` ability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 16:01:10 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3060
No description provided.