[PR #7227] [MERGED] A panic in a native mod's hook names the mod and the hook #7426

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

📋 Pull Request Information

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

Base: main ← Head: v2/ses_01M6BECNQ499TYMMBQBDF00VJ5-panic-mods


📝 Commits (6)

  • 6fc2bd3 A panic in a native mod's hook names the mod and the hook
  • e21b51b Merge remote-tracking branch 'upstream/main' into panic-mods
  • 19419be Merge main into #7227
  • 9e79fa3 Mod API entries and regenerated output for #7227
  • bc83bdd Merge main into #7227
  • f90ca63 Mod API dispatch regenerated for the hooks main added

📊 Changes

6 files changed (+633 additions, -394 deletions)

View changed files

📝 crates/horizon-client-render/src/crash.rs (+93 -6)
📝 crates/horizon-client/src/mod_api.rs (+87 -0)
📝 crates/horizon-client/src/mod_api/generated.rs (+380 -380)
📝 docs/native-mods.md (+6 -0)
📝 launcher/src/native_mods/api.rs (+42 -5)
📝 xtask/src/mod_api.rs (+25 -3)

📄 Description

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

A panic in a native mod's hook now names the mod and the hook. This is #6452's "Panic attribution" item. Listing the build's native mods in crash reports is the other half: #7222.

Before, a panicking trait mod unwound through the generated dispatch into the game:

  • on the dedicated server, "The server thread panicked: …";
  • on the single-player server thread, a log line;
  • on the window's thread, a crash report.

None of them said which mod it was. Now the panic's message, in the crash report and the server thread's error line, ends with:

in native mod machine_sample, hook level_tick_pre

The panic still unwinds as before, so the game stops the same way. Nothing is caught.

How

  • crash: the crash handler has a thread-local "inside native mod call", entered with a guard. The guard puts back the outer call when it drops, including while a panic unwinds. The panic hook runs before the unwind, and its panic_message appends the call it finds. So everything the hook writes names the mod: crash reports, contain's message, and the server thread's error line.
    • The dedicated server's own stop line ("The server thread panicked: …") is left as it is. It is built from the payload after the unwind, so it gives the panic text only, and the crash report written beside it names the mod.
  • The generated dispatch loops over mod_api::entered(mods, "<hook>") instead of mods. That iterator enters each mod's call as it yields the mod. This is the whole generated.rs change: one line per dispatch.
  • Ids: mod_api::name_mods(&[ids]) sets the bundles' [mod] ids once, beside the mod list, in dispatch order. A build that never calls it gives the mod's place instead (in native mod #1, hook …).
  • The launcher's generated main calls name_mods before entry::main_with when the staged revision has it. A pinned older revision gets the main it always did.

Dispatch signatures are unchanged

Every dispatch_<hook> still takes &[Box<dyn Hooks>], and Mods is still Arc<[Box<dyn Hooks>]>. So the dispatch calls that mods' own tests make keep working: #7073's Hooks test, and #7153's documented dispatch_<hook>(&mut host, &[Box<dyn Hooks>], …).

Not covered yet

Render hooks (RenderHooks, called on the render thread through their own list) and trait injections (generated by horizon-mixins, not by this dispatch) aren't named yet. docs/native-mods.md says so.

NeoForge counterpart: crash reports name the mod a failure came from (CrashReportExtender in the public javadoc). This follows its result for hooks: the report names the mod. It doesn't follow its mechanism, the stack-trace annotation.

Tests

  • mod_api::tests::a_panic_in_a_hook_names_the_mod_and_the_hook: two named mods, the second panicking in component_types.
    • The panic report's error ends with in native mod broken, hook component_types.
    • The panic still reaches the caller.
    • A panic after the dispatch has unwound names no mod.
  • crash tests: nested calls name the inner one, a dropped guard puts back the outer, and a real panic's report carries the line.
  • xtask mod_api tests: the generated dispatch enters each mod under the hook's name, and a cancel stops after the first mod.
  • Launcher tests:
    • the generated main names the mods, in order, before main_with, only for a revision with name_mods;
    • staging writes the bundle's id.

Tested in game

The bundle was the sample's trait mod (trait-api-example), repinned to this branch and built through the launcher with native-build --trust-native-code. The bundle id was panic-proof. It had two throwaway panics: one in level_tick_pre on server tick 100, and one in key on K.

Where What showed
Single-player server thread, tick panic The log's panic line ends in native mod panic-proof, hook level_tick_pre
Window, K pressed (horizon-ctl key k tap) The crash report's error ends in native mod panic-proof, hook key
Dedicated server export (native-build --server-output, then --dedicated), tick panic The crash report names in native mod panic-proof, hook level_tick_pre. The stop lines give the panic text only, as described above: The server thread panicked: PROOF panic in level_tick_pre

The launcher's generated main at this branch:

let mods: horizon_client::mod_api::Mods = vec![
    mod_0::hooks(),
].into();
horizon_client::mod_api::name_mods(&["panic-proof"]);
horizon_client::entry::main_with(mods);

These ran at 6fc2bd3256. The head adds a merge of main, bringing in #7197's hooks and #7153's tests, and regenerates the API. The diff to generated.rs is still only the dispatch loop line, one per hook.

The recommended end-to-end route for native mods is horizon-machine-sample. It was used here: its trait-mod bundle (trait-api-example), built through the launcher at 6fc2bd3256, with throwaway panics in level_tick_pre and key.

pr_ready

pr_ready (tools/pr_ready.py --quick --base 8ee7236892 on f2196cc12001, against 8ee7236892 at 8ee723689, 17 min 21 s)

Check Result
Scope ⚠️ 6 files, +605 −366; 965 lines of code: over 500, split it if it can ship in parts; mixes game, launcher
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (33 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 19 s)
tests: horizon-client-lib, horizon-client-render, xtask ✅ 2617 passed (12 min 41 s)
doc tests ✅ 0 passed (18 s)
content root tests ➖ content root untouched
mod API up to date ✅ (11 s)
tokens.css up to date ✅
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (45 s)
launcher tests ✅ 445 passed (1 min 26 s)
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)

On scope:

  • 702 of the 965 lines are the regenerated generated.rs: the same one-line loop change in each of its 351 dispatch functions.
  • The hand-written change is about 260 lines.
  • The game and launcher parts ship together: the launcher's main is what names the mods, and it checks for name_mods before calling it, so either order of builds works.

🤖 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/7227 **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-panic-mods` --- ### 📝 Commits (6) - [`6fc2bd3`](https://github.com/horizon-rust/horizon/commit/6fc2bd325630b597c0806cf0606fd82d35937d5d) A panic in a native mod's hook names the mod and the hook - [`e21b51b`](https://github.com/horizon-rust/horizon/commit/e21b51bf9410747aa2c8093f6ffb4b9756a523cf) Merge remote-tracking branch 'upstream/main' into panic-mods - [`19419be`](https://github.com/horizon-rust/horizon/commit/19419bea3d4682f63269617d492614f06260d74b) Merge main into #7227 - [`9e79fa3`](https://github.com/horizon-rust/horizon/commit/9e79fa3966abad58a1d045c44f228e66a218caea) Mod API entries and regenerated output for #7227 - [`bc83bdd`](https://github.com/horizon-rust/horizon/commit/bc83bdd5821a447180e5f5708ed12e98d1847e9c) Merge main into #7227 - [`f90ca63`](https://github.com/horizon-rust/horizon/commit/f90ca6390d5fd5622b8b154192f44107f019f083) Mod API dispatch regenerated for the hooks main added ### 📊 Changes **6 files changed** (+633 additions, -394 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/crash.rs` (+93 -6) 📝 `crates/horizon-client/src/mod_api.rs` (+87 -0) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+380 -380) 📝 `docs/native-mods.md` (+6 -0) 📝 `launcher/src/native_mods/api.rs` (+42 -5) 📝 `xtask/src/mod_api.rs` (+25 -3) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. A panic in a native mod's hook now names the mod and the hook. This is #6452's "Panic attribution" item. Listing the build's native mods in crash reports is the other half: #7222. Before, a panicking trait mod unwound through the generated dispatch into the game: - on the dedicated server, "The server thread panicked: …"; - on the single-player server thread, a log line; - on the window's thread, a crash report. None of them said which mod it was. Now the panic's message, in the crash report and the server thread's error line, ends with: ``` in native mod machine_sample, hook level_tick_pre ``` The panic still unwinds as before, so the game stops the same way. Nothing is caught. ## How - **`crash`:** the crash handler has a thread-local "inside native mod call", entered with a guard. The guard puts back the outer call when it drops, including while a panic unwinds. The panic hook runs before the unwind, and its `panic_message` appends the call it finds. So everything the hook writes names the mod: crash reports, `contain`'s message, and the server thread's error line. - The dedicated server's own stop line ("The server thread panicked: …") is left as it is. It is built from the payload after the unwind, so it gives the panic text only, and the crash report written beside it names the mod. - **The generated dispatch** loops over `mod_api::entered(mods, "<hook>")` instead of `mods`. That iterator enters each mod's call as it yields the mod. This is the whole `generated.rs` change: one line per dispatch. - **Ids:** `mod_api::name_mods(&[ids])` sets the bundles' `[mod] id`s once, beside the mod list, in dispatch order. A build that never calls it gives the mod's place instead (`in native mod #1, hook …`). - **The launcher's generated `main`** calls `name_mods` before `entry::main_with` when the staged revision has it. A pinned older revision gets the `main` it always did. ### Dispatch signatures are unchanged Every `dispatch_<hook>` still takes `&[Box<dyn Hooks>]`, and `Mods` is still `Arc<[Box<dyn Hooks>]>`. So the dispatch calls that mods' own tests make keep working: #7073's `Hooks` test, and #7153's documented `dispatch_<hook>(&mut host, &[Box<dyn Hooks>], …)`. ### Not covered yet Render hooks (`RenderHooks`, called on the render thread through their own list) and trait injections (generated by horizon-mixins, not by this dispatch) aren't named yet. `docs/native-mods.md` says so. NeoForge counterpart: crash reports name the mod a failure came from (`CrashReportExtender` in the public javadoc). This follows its result for hooks: the report names the mod. It doesn't follow its mechanism, the stack-trace annotation. ## Tests - **`mod_api::tests::a_panic_in_a_hook_names_the_mod_and_the_hook`:** two named mods, the second panicking in `component_types`. - The panic report's error ends with `in native mod broken, hook component_types`. - The panic still reaches the caller. - A panic after the dispatch has unwound names no mod. - **`crash` tests:** nested calls name the inner one, a dropped guard puts back the outer, and a real panic's report carries the line. - **`xtask` `mod_api` tests:** the generated dispatch enters each mod under the hook's name, and a cancel stops after the first mod. - **Launcher tests:** - the generated `main` names the mods, in order, before `main_with`, only for a revision with `name_mods`; - staging writes the bundle's id. ## Tested in game The bundle was the sample's trait mod (`trait-api-example`), repinned to this branch and built through the launcher with `native-build --trust-native-code`. The bundle id was `panic-proof`. It had two throwaway panics: one in `level_tick_pre` on server tick 100, and one in `key` on K. | Where | What showed | | --- | --- | | Single-player server thread, tick panic | The log's panic line ends `in native mod panic-proof, hook level_tick_pre` | | Window, K pressed (`horizon-ctl key k tap`) | The crash report's error ends `in native mod panic-proof, hook key` | | Dedicated server export (`native-build --server-output`, then `--dedicated`), tick panic | The crash report names `in native mod panic-proof, hook level_tick_pre`. The stop lines give the panic text only, as described above: `The server thread panicked: PROOF panic in level_tick_pre` | The launcher's generated `main` at this branch: ```rust let mods: horizon_client::mod_api::Mods = vec![ mod_0::hooks(), ].into(); horizon_client::mod_api::name_mods(&["panic-proof"]); horizon_client::entry::main_with(mods); ``` These ran at 6fc2bd3256. The head adds a merge of main, bringing in #7197's hooks and #7153's tests, and regenerates the API. The diff to `generated.rs` is still only the dispatch loop line, one per hook. The recommended end-to-end route for native mods is [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample). It was used here: its trait-mod bundle (`trait-api-example`), built through the launcher at 6fc2bd3256, with throwaway panics in `level_tick_pre` and `key`. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base 8ee7236892` on f2196cc12001, against 8ee7236892 at 8ee723689, 17 min 21 s) | Check | Result | | --- | --- | | Scope | ⚠️ 6 files, +605 −366; 965 lines of code: over 500, split it if it can ship in parts; mixes game, launcher | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (33 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 19 s) | | tests: horizon-client-lib, horizon-client-render, xtask | ✅ 2617 passed (12 min 41 s) | | doc tests | ✅ 0 passed (18 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (11 s) | | tokens.css up to date | ✅ | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (45 s) | | launcher tests | ✅ 445 passed (1 min 26 s) | | 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) | On scope: - 702 of the 965 lines are the regenerated `generated.rs`: the same one-line loop change in each of its 351 dispatch functions. - The hand-written change is about 260 lines. - The game and launcher parts ship together: the launcher's `main` is what names the mods, and it checks for `name_mods` before calling it, so either order of builds works. 🤖 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:39:21 +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#7426
No description provided.