Skip to content
This repository was archived by the owner on Nov 16, 2026. It is now read-only.

Make I18n.fallbacks and INTERPOLATION_PATTERN readable from non-main Ractors - #5

Open
mhenrixon wants to merge 1 commit into
Shopify:ractor_supportfrom
mhenrixon:ractor-fallbacks-ivar
Open

mhenrixon wants to merge 1 commit into
Shopify:ractor_supportfrom
mhenrixon:ractor-fallbacks-ivar

Conversation

@mhenrixon

@mhenrixon mhenrixon commented Oct 18, 2026 •

Copy link
Copy Markdown

This fixes the two things @yaroslav reported on ruby-i18n#741 (comment).

I18n.fallbacks falls through to @@fallbacks whenever the current fiber has no :i18n_fallbacks, and Ruby 4.0 refuses every class variable read from a non-main Ractor, even when the value is shareable. Two cases hit it:

  • An app that never sets I18n.fallbacks, once i18n/backend/fallbacks is loaded. Action View then reads it for every lookup context (register_detail(:locale) in action_view/lookup_context.rb:48), so every rendered page in a Ractor raises.
  • A Ractor whose code runs in a fiber with its own storage (Fiber.new(storage: {})), even when fallbacks were set at boot.

The value now lives in a module instance variable, and i18n/ractorize makes it deeply shareable. The setter still freezes shallowly, so calling I18n.fallbacks.map(...) during boot keeps working.

INTERPOLATION_PATTERN gets back its .freeze.

Tests

test/ractor_test.rb runs each case in a child Ruby, because i18n/ractorize makes the configuration shareable for the rest of the process. The tests skip below Ruby 4.0.

  • Before the change: all three fail, with can not access class variables from non-main Ractors (@@fallbacks from I18n) and can not access non-shareable objects in constant I18n::INTERPOLATION_PATTERN.
  • After: bundle exec rake test gives 1610 runs, 0 failures on Ruby 4.0.7. On Ruby 3.4 the three new tests skip and the rest pass.

I found this while running pghero's test suite with Rails.application.ractorize! (ankane/pghero#548).

Conformance case

test/ractor_test.rb:12: "I18n.fallbacks is readable from a non-main Ractor when it was never set"

bundle exec ruby -Ilib -Itest test/ractor_test.rb
  • Without the fix (58aa1dc), Ruby 4.0.7: fails with Ractor::IsolationError: can not access class variables from non-main Ractors (@@fallbacks from I18n); the INTERPOLATION_PATTERN test fails with can not access non-shareable objects in constant I18n::INTERPOLATION_PATTERN by non-main Ractor.
  • With this PR: passes on Ruby 4.0.7.

Each test runs require "i18n/ractorize" in a child Ruby and then reads the value in a Ractor, so it fails again if something ractorize should cover stops being shareable; it skips below Ruby 4.0.

…Ractors

I18n.fallbacks fell through to @@fallbacks whenever the fiber had no
:i18n_fallbacks (fallbacks never set, or a fiber with its own storage),
and Ruby 4.0 refuses every class variable read from a non-main Ractor.
It is now a module instance variable, which i18n/ractorize makes
shareable; I18n.fallbacks= still freezes shallowly, so #map keeps working
outside Ractors. INTERPOLATION_PATTERN gets back its .freeze.

Both were reported by @yaroslav in ruby-i18n#741.
@mhenrixon mhenrixon moved this to Waiting on maintainers in Ractor-safe Rails Oct 18, 2026
mhenrixon added a commit to zoolutions/conformance-kit that referenced this pull request Oct 19, 2026
…ails main

`conformance-kit check --ractorize` boots `ractorize.app` the way Rails
8.2 runs an app across Ractors: in production, with
`ActiveSupport::Ractors.unshareable_proc_action = :raise`, then
`Rails.application.ractorize!` and `require "i18n/ractorize"`. Each
`ractorize.requests` path is served inside a non-main Ractor; a failure
names the root cause and its first frame, also when the app's error page
swallowed it (env["action_dispatch.exception"]). Then the audit runs on
`ractorize.audit_namespaces` (default audit.namespace) in the same
process. It skips with the reason below Ruby 4.0 or on a Rails without
ractorize!.

- New .conformance.yml keys: ractorize.app, .requests,
  .audit_namespaces, .setup (validated like the rest: unknown key exits 2).
- config/ractorize.gemfile: the repo's Gemfile with Rails main, Rack main
  and Shopify/i18n#5 swapped in (it drops the repo's own lines for them,
  since Bundler refuses a gem declared twice).
- conformance.yml: a Ractorize job, only when ractorize.app is set,
  continue-on-error until Rails 8.2 ships ractorize!.
- main.yml: a report-only "Ractorize lane" (Ruby 4.0, the same gemfile)
  runs the fixture specs: a boot violation (a route block appended from
  an initializer) and a render violation (a shallow-frozen class ivar)
  must fail, naming the file and line; a conforming engine must pass.

Refs #22

Claude-Session: https://claude.ai/code/session_01JCaQrTh5yGHrueUmq69PKs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant