[PR #7062] [MERGED] Native hook stamping: every marker names its fragment, and stamping keeps the mod API current #7307

Closed
opened 2026-11-03 06:37:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7062
Author: @arismoko
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: v2/ses_01M6BECNQ499TYMMBQBDF00VJ5-stamp-markers


📝 Commits (2)

  • c488e07 Native hook stamping: every marker names its fragment
  • cee65d7 Native hook stamping keeps the generated mod API current

📊 Changes

17 files changed (+216 additions, -191 deletions)

View changed files

📝 crates/horizon-client/src/game/native_hooks.rs (+85 -85)
📝 crates/horizon-client/src/game/native_server.rs (+1 -0)
📝 crates/horizon-client/src/mod_api/generated.rs (+85 -85)
📝 docs/native-mods.md (+4 -4)
📝 tests/test_stamp_native_hooks.py (+21 -1)
📝 tools/native-hook-fragments/native_player_flower_pot_manipulate.json (+1 -1)
📝 tools/native-hook-fragments/native_player_insert_lectern_book.json (+1 -1)
📝 tools/native-hook-fragments/native_player_item_frame_change.json (+1 -1)
📝 tools/native-hook-fragments/native_player_item_mend.json (+1 -1)
📝 tools/native-hook-fragments/native_player_lectern_page_change.json (+1 -1)
📝 tools/native-hook-fragments/native_player_take_lectern_book.json (+1 -1)
📝 tools/native-hook-fragments/native_spawn_change.json (+1 -1)
📝 tools/native-hook-fragments/native_world_border_bounds_changed.json (+1 -1)
📝 tools/native-hook-fragments/native_world_border_center_changed.json (+1 -1)
📝 tools/native-hook-fragments/native_world_game_rule_change.json (+1 -1)
📝 tools/native-hook-fragments/state_block.json (+1 -2)
📝 tools/stamp_native_hooks.py (+9 -4)

📄 Description

🤖 Opened by Aria's agent swarm, Dyna, not by Aria.

Fixes #7024. The native hook stamp workflow has failed on every push since 2026-11-01. This makes it stamp again, and makes the PR it opens pass generated_output_is_current. It changes no game behaviour; only doc-comment markers move in game code.

Why stamping failed

tools/stamp_native_hooks.py replaces @API:<fragment file stem>@, and only in the files a fragment lists under comments. Three kinds of fragment data broke that:

  1. server_event.json lists game/native_server.rs under comments, but that file had no marker: missing @API:server_event@. The helper's doc comment now ends with API @API:server_event@., as the other helpers' do.

  2. state_block.json lists game/native_hooks.rs, which is always stamped, so the stamper rejects it as a comment path. The entry is gone.

  3. 89 markers named no fragment. Once the first two are fixed, these leave unnumbered text in the docs and the trait docs:

    • 79 are #6801's, which read @API:native_<hook>@ while the fragment is <hook>.json;
    • 10 read @API:<hook>@ while the fragment is native_<hook>.json: the flower pot, the three lectern hooks, item frame, item mend, spawn_change, both world border hooks and world_game_rule_change.

    Each marker is renamed to its fragment's stem. generated.rs is regenerated with cargo run -p xtask -- mod-api, not edited by hand.

Changes to the stamper

Two small changes in tools/stamp_native_hooks.py:

  • Markers in the docs' hook lists are stamped. Some hooks are listed in docs/native-mods.md with their marker, but the stamper only numbered the summary it inserts, so these stayed as text. docs/native-mods.md can't be listed under comments. There are 10 such markers:

    • physical_window_size (twice), portal_create, sleep_finished_time, chorus_fruit_teleport, ender_pearl_teleport;
    • native_spawn_change, native_world_border_bounds_changed, native_world_border_center_changed, native_world_game_rule_change.

    The fix is one line, docs = docs.replace(marker, str(version)), beside the source's.

  • Stamping no longer reorders the generated mod API.

    • xtask mod-api lists the catalog's hooks, then the pending fragments' in file name order. The stamper appended a batch to the catalog in merge order, so a stamped tree failed mod-api --check.
    • The catalog now takes a batch's hooks and helpers in file name order. API numbers still follow merge order.
    • The existing test's catalog assertion changes from [("z", 1), ("a", 1)] to [("a", 1), ("z", 1)]. Catalog order within a batch carries no meaning: an entry's version is the hook's own version, not its API number.
    • This is the first stamp since #6216 added the generated mod API (the last stamp was #6441), which is why it never showed up. It would have saved the hand regenerations in #6720 and #6982.

A test against regressions

test_the_repository_stamps_every_marker copies this checkout's pending fragments, the files they stamp, the catalog, the docs and the mod API files into a scratch repository. It stamps them and fails if stamping errors or leaves any @API:…@ behind.

  • On main it fails with #7024's error (missing @API:server_event@ in crates/horizon-client/src/game/native_server.rs).
  • On this branch it passes: 160 fragments, through API 313.

For open hook PRs

#7005 (Detimes) adds 17 markers in the @API:native_<hook>@ form, such as native_block_damage_abort and native_entity_drop_item. Whichever of the two merges second will need to rename them to the fragment stems for the new test to pass. This is just a heads-up so it doesn't come as a surprise.

Checks

All at head cee65d7ce2:

  • python3 -m unittest tests.test_stamp_native_hooks: 6 passed. The new test fails on main with #7024's error.
  • cargo run -p xtask -- mod-api --check: passed, before stamping and after.
  • pr_ready, below: rustfmt, clippy, 2069 horizon-client and horizon-client-lib tests, and 612 Python tests.

Tested in game

The test route is horizon-machine-sample, used through its trait example (examples/trait-api, the driver that links a Hooks mod).

All at head cee65d7ce2, on the server thread (single player's default):

  1. Stamped as the workflow would. A copy of the head was stamped with python3 tools/stamp_native_hooks.py. It stamped 160 fragments through API 313, NATIVE_HOOKS_API = 313, and left no @API:…@ in the source, docs, catalog or mod API files. cargo run -p xtask -- mod-api --check then passed on the stamped tree. The stamped output is not part of this PR: stamping stays the workflow's job.

  2. The game built from the stamped tree, with the sample's trait mod (machine-hooks, sample commit 25d5b06 plus a throwaway hook) linked into its driver.

  3. A renamed hook ran. The throwaway hook is weather_change, whose marker was @API:native_weather_change@ and is now stamped as API 304. It cancels thunder and lets other weather through:

    fn weather_change(&self, _host: &mut dyn Host, event: &mut WeatherChangeEvent<'_>) -> Flow {
        eprintln!(
            "STAMP_PROOF weather_change dimension={} raining={} thundering={}",
            event.dimension, event.raining, event.thundering
        );
        if event.thundering { Flow::Cancel } else { Flow::Continue }
    }
    

    /weather thunder logged STAMP_PROOF weather_change dimension=minecraft:overworld raining=true thundering=true, and the sky stayed clear at noon. /weather rain then logged STAMP_PROOF weather_change dimension=minecraft:overworld raining=true thundering=false, and it rained.

What could not be tested. A bundle asks for an API number ("hooks": N) only through the launcher. The launcher reads NATIVE_HOOKS_API from GitHub at the revision it builds, so a locally stamped tree can't be asked for. The game never reads the number at runtime. Instead:

  • the stamped native_hooks.rs has the line the launcher's hooks_in reads, pub(crate) const NATIVE_HOOKS_API: u32 = 313;;
  • the renamed hooks' trait docs carry their stamped numbers.

pr_ready

pr_ready (tools/pr_ready.py --quick --base 7ecfbf6db506d88a218a95d8fa4f8beef4f8c023 on f2196cc12001, against 7ecfbf6db5 at 7ecfbf6db, 13 min 0 s)

Check Result
Scope ✅ 17 files, +216 −191
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (32 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 22 s)
tests: horizon-client, horizon-client-lib ✅ 2069 passed (10 min 43 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
mod API up to date ✅ (12 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Merge with a merge commit, please.

🤖 Generated with Dyna.


🔄 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/7062 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `v2/ses_01M6BECNQ499TYMMBQBDF00VJ5-stamp-markers` --- ### 📝 Commits (2) - [`c488e07`](https://github.com/horizon-rust/horizon/commit/c488e079f64a6bf14d060b5ad78546e1466b7120) Native hook stamping: every marker names its fragment - [`cee65d7`](https://github.com/horizon-rust/horizon/commit/cee65d7ce24f7dd04490a6af20a44bc24bd844d4) Native hook stamping keeps the generated mod API current ### 📊 Changes **17 files changed** (+216 additions, -191 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/native_hooks.rs` (+85 -85) 📝 `crates/horizon-client/src/game/native_server.rs` (+1 -0) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+85 -85) 📝 `docs/native-mods.md` (+4 -4) 📝 `tests/test_stamp_native_hooks.py` (+21 -1) 📝 `tools/native-hook-fragments/native_player_flower_pot_manipulate.json` (+1 -1) 📝 `tools/native-hook-fragments/native_player_insert_lectern_book.json` (+1 -1) 📝 `tools/native-hook-fragments/native_player_item_frame_change.json` (+1 -1) 📝 `tools/native-hook-fragments/native_player_item_mend.json` (+1 -1) 📝 `tools/native-hook-fragments/native_player_lectern_page_change.json` (+1 -1) 📝 `tools/native-hook-fragments/native_player_take_lectern_book.json` (+1 -1) 📝 `tools/native-hook-fragments/native_spawn_change.json` (+1 -1) 📝 `tools/native-hook-fragments/native_world_border_bounds_changed.json` (+1 -1) 📝 `tools/native-hook-fragments/native_world_border_center_changed.json` (+1 -1) 📝 `tools/native-hook-fragments/native_world_game_rule_change.json` (+1 -1) 📝 `tools/native-hook-fragments/state_block.json` (+1 -2) 📝 `tools/stamp_native_hooks.py` (+9 -4) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Fixes #7024. The `native hook stamp` workflow has failed on every push since 2026-11-01. This makes it stamp again, and makes the PR it opens pass `generated_output_is_current`. It changes no game behaviour; only doc-comment markers move in game code. ## Why stamping failed `tools/stamp_native_hooks.py` replaces `@API:<fragment file stem>@`, and only in the files a fragment lists under `comments`. Three kinds of fragment data broke that: 1. **`server_event.json`** lists `game/native_server.rs` under `comments`, but that file had no marker: `missing @API:server_event@`. The helper's doc comment now ends with `API @API:server_event@.`, as the other helpers' do. 2. **`state_block.json`** lists `game/native_hooks.rs`, which is always stamped, so the stamper rejects it as a comment path. The entry is gone. 3. **89 markers named no fragment.** Once the first two are fixed, these leave unnumbered text in the docs and the trait docs: - 79 are #6801's, which read `@API:native_<hook>@` while the fragment is `<hook>.json`; - 10 read `@API:<hook>@` while the fragment is `native_<hook>.json`: the flower pot, the three lectern hooks, item frame, item mend, `spawn_change`, both world border hooks and `world_game_rule_change`. Each marker is renamed to its fragment's stem. `generated.rs` is regenerated with `cargo run -p xtask -- mod-api`, not edited by hand. ## Changes to the stamper Two small changes in `tools/stamp_native_hooks.py`: - **Markers in the docs' hook lists are stamped.** Some hooks are listed in `docs/native-mods.md` with their marker, but the stamper only numbered the summary it inserts, so these stayed as text. `docs/native-mods.md` can't be listed under `comments`. There are 10 such markers: - `physical_window_size` (twice), `portal_create`, `sleep_finished_time`, `chorus_fruit_teleport`, `ender_pearl_teleport`; - `native_spawn_change`, `native_world_border_bounds_changed`, `native_world_border_center_changed`, `native_world_game_rule_change`. The fix is one line, `docs = docs.replace(marker, str(version))`, beside the source's. - **Stamping no longer reorders the generated mod API.** - `xtask mod-api` lists the catalog's hooks, then the pending fragments' in file name order. The stamper appended a batch to the catalog in merge order, so a stamped tree failed `mod-api --check`. - The catalog now takes a batch's hooks and helpers in file name order. API numbers still follow merge order. - The existing test's catalog assertion changes from `[("z", 1), ("a", 1)]` to `[("a", 1), ("z", 1)]`. Catalog order within a batch carries no meaning: an entry's `version` is the hook's own version, not its API number. - This is the first stamp since #6216 added the generated mod API (the last stamp was #6441), which is why it never showed up. It would have saved the hand regenerations in #6720 and #6982. ## A test against regressions `test_the_repository_stamps_every_marker` copies this checkout's pending fragments, the files they stamp, the catalog, the docs and the mod API files into a scratch repository. It stamps them and fails if stamping errors or leaves any `@API:…@` behind. - On main it fails with #7024's error (`missing @API:server_event@ in crates/horizon-client/src/game/native_server.rs`). - On this branch it passes: 160 fragments, through API 313. ## For open hook PRs #7005 (Detimes) adds 17 markers in the `@API:native_<hook>@` form, such as `native_block_damage_abort` and `native_entity_drop_item`. Whichever of the two merges second will need to rename them to the fragment stems for the new test to pass. This is just a heads-up so it doesn't come as a surprise. ## Checks All at head cee65d7ce2: - `python3 -m unittest tests.test_stamp_native_hooks`: 6 passed. The new test fails on main with #7024's error. - `cargo run -p xtask -- mod-api --check`: passed, before stamping and after. - pr_ready, below: rustfmt, clippy, 2069 horizon-client and horizon-client-lib tests, and 612 Python tests. ## Tested in game The test route is [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample), used through its trait example (`examples/trait-api`, the driver that links a `Hooks` mod). All at head cee65d7ce2, on the server thread (single player's default): 1. **Stamped as the workflow would.** A copy of the head was stamped with `python3 tools/stamp_native_hooks.py`. It stamped 160 fragments through API 313, `NATIVE_HOOKS_API = 313`, and left no `@API:…@` in the source, docs, catalog or mod API files. `cargo run -p xtask -- mod-api --check` then passed on the stamped tree. The stamped output is not part of this PR: stamping stays the workflow's job. 2. **The game built from the stamped tree**, with the sample's trait mod (`machine-hooks`, sample commit 25d5b06 plus a throwaway hook) linked into its driver. 3. **A renamed hook ran.** The throwaway hook is `weather_change`, whose marker was `@API:native_weather_change@` and is now stamped as API 304. It cancels thunder and lets other weather through: ```rust fn weather_change(&self, _host: &mut dyn Host, event: &mut WeatherChangeEvent<'_>) -> Flow { eprintln!( "STAMP_PROOF weather_change dimension={} raining={} thundering={}", event.dimension, event.raining, event.thundering ); if event.thundering { Flow::Cancel } else { Flow::Continue } } ``` `/weather thunder` logged `STAMP_PROOF weather_change dimension=minecraft:overworld raining=true thundering=true`, and the sky stayed clear at noon. `/weather rain` then logged `STAMP_PROOF weather_change dimension=minecraft:overworld raining=true thundering=false`, and it rained. **What could not be tested.** A bundle asks for an API number (`"hooks": N`) only through the launcher. The launcher reads `NATIVE_HOOKS_API` from GitHub at the revision it builds, so a locally stamped tree can't be asked for. The game never reads the number at runtime. Instead: - the stamped `native_hooks.rs` has the line the launcher's `hooks_in` reads, `pub(crate) const NATIVE_HOOKS_API: u32 = 313;`; - the renamed hooks' trait docs carry their stamped numbers. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base 7ecfbf6db506d88a218a95d8fa4f8beef4f8c023` on f2196cc12001, against 7ecfbf6db506d88a218a95d8fa4f8beef4f8c023 at 7ecfbf6db, 13 min 0 s) | Check | Result | | --- | --- | | Scope | ✅ 17 files, +216 −191 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (32 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 22 s) | | tests: horizon-client, horizon-client-lib | ✅ 2069 passed (10 min 43 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (12 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Merge with a merge commit, please. 🤖 Generated with Dyna. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:37:31 +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#7307
No description provided.