Skip to content

fix(i18n): update rust-i18n so the catalogs stay off the stack - #2687

Open
Ariazonaa wants to merge 2 commits into
AprilNEA:masterfrom
Ariazonaa:fix/rust-i18n-stack
Open

Ariazonaa wants to merge 2 commits into
AprilNEA:masterfrom
Ariazonaa:fix/rust-i18n-stack

Conversation

@Ariazonaa

@Ariazonaa Ariazonaa commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Up to 4.2.3, the initializer that rust_i18n::i18n! generates keeps every entry of all 24 catalogs in one stack frame in an unoptimized build. It is 1.69 MiB on 6a2c6fed and grows with every key and language. That overflows the 1 MiB main thread of the Windows debug GUI, and about 170 more keys would overflow the 2 MiB test threads as well (#2686).

4.2.4 packs each catalog into one literal (longbridge/rust-i18n#148), so the frame is gone.

Changes

  • openlogi-agent, openlogi-core, openlogi-desktop, openlogi-overlay: require rust-i18n 4.2.4, so a later lockfile change can't go back below it.
  • Cargo.lock: rust-i18n 4.2.1 → 4.2.4, which moves serde-saphyr to 1.3.0 and granit-parser to 1.3.0. No other package changes version and none is added.

Also new since 4.2.1: locale() caches the current locale per thread and reloads it after each set_locale (longbridge/rust-i18n#151), so a live language change still reaches every thread.

#2126 gives the debug GUI and overlay a larger main-thread stack for the same frame. With this update the debug GUI starts without it. I did not check whether the overlay's ring opens, so whether #2126 is still useful is up to you and its author.

Testing

On Windows 11 (MSVC), RUSTFLAGS="-D warnings":

  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-targets -- -D warnings
  • cargo test --locked --workspace
  • cargo doc --locked for the non-GUI crates with RUSTDOCFLAGS="-D warnings"
  • cargo +1.99 check --locked --workspace

typos, ast-grep and cargo-deny were not run locally.

The frame and the overflow, before and after:

  • dumpbin finds the 1.69 MiB frame in both debug binaries on 4.2.1. On 4.2.4 the largest frame is 0.28 MiB.
  • The debug GUI, with the default 1 MiB main thread: exits with 0xC00000FD on 4.2.1, opens its window on 4.2.4, three starts each.
  • With 200 dummy keys in every catalog, the bin tests of the desktop, overlay and agent crates overflow on 4.2.1. On 4.2.4, a test that translates passes in each of them with 2000 dummy keys and 1 MiB threads.
  • catalog_init_stack (from downtempo) builds the catalog on a 1 MiB thread: it aborts with STATUS_STACK_OVERFLOW on the lockfile before this PR and passes on 4.2.4.

Not runtime-tested on hardware, and not on macOS or Linux.

To test: build openlogi-desktop in debug on Windows without changing its stack size, and start it.

Fixes #2686

Up to 4.2.3 the initializer of i18n! keeps every entry of all 24 catalogs in
one stack frame in an unoptimized build: 1.69 MiB, growing with each key and
language. That overflows the 1 MiB main thread of the Windows debug GUI and
overlay, and would soon overflow the 2 MiB test threads. 4.2.4 packs each
catalog into one literal.
@Ariazonaa
Ariazonaa requested a review from AprilNEA as a code owner November 30, 2026 03:18
@greptile-apps

greptile-apps Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Raises the rust-i18n minimum to 4.2.4 and adds a focused test for catalog startup on a small thread stack.

  • The desktop app can load translations without overflowing its startup stack.

Reviews (2) · Last reviewed commit: "test(i18n): build the catalog on a 1 MiB..." · Reviewed by Greptile

@davidbudnick davidbudnick added type: bug Something is broken or behaves incorrectly platform: all Cross-platform issue area: deps Dependency management and upstream crates/repositories area: gui Graphical user interface labels Nov 30, 2026
@downtempo

Copy link
Copy Markdown

Tested this on macOS (Apple Silicon) against master at 0cae2818e, unoptimized test build. On 4.2.1 the first lookup fits in a 2 MiB thread and overflows a 1 MiB one. With the update applied (4.2.4, lockfile matching this PR), it passes on 1 MiB.

I've hit the 2 MiB case for real, too. On a fork with a couple hundred more catalog keys, the agent's test threads overflowed in the catalog initializer, which lines up with the estimate in #2686.

Might be worth a regression test, so catalog growth or a later rust-i18n change can't quietly bring this back. Here's the one I used. It's a separate integration test target in openlogi-ui, so its single lookup is the one that builds the catalog, and it pins the thread to 1 MiB so RUST_MIN_STACK can't change the result. I've only run it on macOS.

crates/openlogi-ui/tests/catalog_init_stack.rs
#![expect(
    clippy::tests_outside_test_module,
    reason = "integration tests are test targets by construction"
)]

//! The first `t!` builds the whole catalog, on whichever thread asks first.
//! rust-i18n up to 4.2.3 built it in one stack frame that grows with every
//! key and language (#2686). This target holds only this test, so its lookup
//! is the one that initializes the backend.

rust_i18n::i18n!("locales", fallback = "en");

/// Half of `std::thread`'s 2 MiB default, so the test fails while there is
/// still headroom on real threads. Pinned so `RUST_MIN_STACK` can't hide it.
const LOOKUP_STACK: usize = 1024 * 1024;

#[test]
fn the_first_lookup_fits_a_small_thread_stack() {
    const KEY: &str = "app.show_main_window";
    let translated = std::thread::Builder::new()
        .name("first-lookup".into())
        .stack_size(LOOKUP_STACK)
        .spawn(|| rust_i18n::t!(KEY).into_owned())
        .unwrap()
        .join()
        .unwrap();
    assert_ne!(translated, KEY);
}

plus, in crates/openlogi-ui/Cargo.toml:

[dev-dependencies]
rust-i18n = "4.2.4"

On 4.2.1, cargo test -p openlogi-ui --test catalog_init_stack aborts with "has overflowed its stack". On 4.2.4 it passes.

The first lookup builds the whole catalog on whichever thread asks first,
and rust-i18n up to 4.2.3 did that in one stack frame that grows with the
catalog (AprilNEA#2686). The test pins that thread to 1 MiB, so catalog growth or
a later rust-i18n change cannot bring the overflow back unnoticed.

Co-authored-by: Andy Volk <100514+downtempo@users.noreply.github.com>
@Ariazonaa

Copy link
Copy Markdown
Contributor Author

Thanks! Added it with you as co-author (e951ed8). Same on Windows 11: on the full lockfile from before this PR it aborts with STATUS_STACK_OVERFLOW, and on 4.2.4 it passes. Rolling back rust-i18n alone to 4.2.1 isn't enough, rust-i18n-macro and rust-i18n-support have to go with it, or it still passes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: deps Dependency management and upstream crates/repositories area: gui Graphical user interface platform: all Cross-platform issue type: bug Something is broken or behaves incorrectly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: debug tests overflow their stack once the locale catalogs grow a little more

3 participants