Przejdź do treści
Biblioteka skilli
Programowanie · Przegląd i audyt

ractor-readiness

/ractor-readiness

Sprawdza, czy kod Ruby lub zależności działają w Ractorach, pomaga uczynić kod bezpiecznym dla Ractorów i dodaje bramkę CI na Ruby 4.0+.

Repozytorium
audition ↗
Licencja
MIT
Ostatnia zmiana repozytorium
16.09.2026

Ocena i bezpieczeństwo

90/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść25 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 16.09.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Sprawdza, czy kod Ruby lub zależności działają w Ractorach, pomaga uczynić kod bezpiecznym dla Ractorów i dodaje bramkę CI na Ruby 4.0+.

Oryginalny opis (EN)

Use when asked whether Ruby code (a gem, script, Rack or Rails app, or all Gemfile.lock dependencies) can run inside Ractors, when making code Ractor-safe or Ractor-compatible on Ruby 4.0+, when adding a CI gate for Ractor readiness, or when errors mention Ractor::IsolationError, Ractor::UnsafeError, can not access global variables from non-main Ractor, ractor unsafe method called from not main ractor, non-shareable objects, or an un-shareable Proc.

Jak działa

  1. Overview
  2. Quick reference
  3. The protocol
  4. Reading the report
  5. Native extensions (C, Rust, and Zig)
  6. What the fixer refuses (human work)
  7. Common mistakes
Sekcje z nagłówków SKILL.md, w oryginale · 173 linii, 1 182 słów
Podgląd SKILL.md
---
name: ractor-readiness
description: Use when asked whether Ruby code (a gem, script,
  Rack or Rails app, or all Gemfile.lock dependencies) can run
  inside Ractors, when making code Ractor-safe or
  Ractor-compatible on Ruby 4.0+, when adding a CI gate for
  Ractor readiness, or when errors mention
  Ractor::IsolationError, Ractor::UnsafeError, can not access
  global variables from non-main Ractor, ractor unsafe method
  called from not main ractor, non-shareable objects, or an
  un-shareable Proc.
license: MIT
---

# Checking and fixing Ractor readiness with Audition

## Overview

Audition (a Ruby gem) probes any target for Ractor readiness:
script, gem, directory, Rack app, Rails root, or a whole
Gemfile.lock. Static Prism and rubydex checks plus a dynamic
probe that loads the target inside a real Ractor; every finding
carries a why and a fix, and mechanical fixes are automated. Do
not hand-roll Ractor analysis or re-verify Ruby 4.0 Ractor
semantics; the tool encodes them, verified empirically. Written
against Audition 0.4.x.

## Quick reference

| Goal | Command |
|---|---|
| Audit one target | `audition --plain <target>` |
| Fast iteration | add `--static-only` |
| Preview fixes | `--fix-unsafe --dry-run` |
| Apply fixes | `--fix` (safe), `--fix-unsafe` |
| Rank all dependencies | `audition <dir>/Gemfile.lock` |
| CI gate | `-f github` or `-f json`, `--fail-on warning` |
| CI, non-blocking | add `--exit-zero` (= `--fail-on never`) |
| Git hook | `audition --static-only --plain <staged .rb files>` |
| Incremental adoption | `--write-baseline`, `.audition.yml`, pragmas |

The tool runs on Ruby 4.0+ (targets may support older Rubies).
Install once with `gem install audition`. Run it OUTSIDE
`bundle exec` so the dynamic probe resolves the target's own
gems. Exit code is 1 when findings reach `--fail-on` (default:
error), 0 when the gate is clean.

## The protocol

Battle-tested on a dozen real gems (i18n, sinatra, mail,
tzinfo, addressable, jwt, liquid, faraday, money, and more).
Order matters:

1. Baseline the target's own test suite; record the results.
   Fixes need a writable, git-clean tree: never point `--fix`
   at an installed gem path; clone or copy the source first.
2. `audition --plain --static-only <target>` for the picture.
3. `--fix`, then `--fix-unsafe`. Preview with `--dry-run`;
   after applying, review `git diff` and revert hunks you
   disagree with instead of hand-writing everything. House
   styles (line length and such) belong to your own projects,
   not to targets you are fixing.
4. Before accepting fixes that contain Ractor APIs
   (`store_if_absent`, `Ractor.current`), check the target
   gemspec's `required_ruby_version`: those APIs need Ruby
   3.4+ or 4.0+. Plain-Ruby fixes (`.freeze`, frozen
   constants) have no version floor.
5. Re-run the target's suite. Full parity with the baseline,
   including pre-existing failures, is the bar.
6. Encode accepted residuals so re-runs gate cleanly:
   `# audition:disable <check>` pragmas on intentionally
   main-only lines (Rake loading, ENV mutation),
   `.audition.yml` `exclude:` for deliberately lazy trees
   (test mixins, optional integrations), `--write-baseline`
   for bulk adoption.
7. Full run (drop `--static-only`) for dynamic ground truth.

## Reading the report

| Verdict | Meaning |
|---|---|
| ready | clean; info notes do not taint it |
| risky | warnings only |
| blocked | own code clean, dependencies dirty; not this target's bug |
| not_ready | own errors |

"Frozen memoization; warm on the main Ractor" info notes mean:
call the memoizing methods once at boot, before spawning
Ractors; the end of the gem's main file or an on_load hook is
the natural place.

"Proxied to the main Ractor" is the `@x || on_main(self) { @x
||= v }` escape hatch: accepted, serializing, and only safe when
the memoized value is shareable; prefer deleting or warming the
memo.

"Shareable in the dynamic probe" on a class-level-state note
means the probe saw only shareable values there after boot:
reads are legal from any Ractor; keep writes on the main
Ractor. Static warnings on constants the probe proved shareable
are dropped outright, so a full run (no `--static-only`) is the
one to trust on a gem that makes its state shareable at boot.

`instance-memoization` is the compute-on-freeze rule: a class
that freezes itself in initialize cannot memoize lazily (move
the value into initialize), and a class with a `freeze`
override must warm every memo inside it before `super`.

On a Rails target, `runtime-unshareable-proc` names a callback
block Rails could not make shareable, at the Proc's definition
site; fix the capture (freeze the local, inline it, or hoist a
Symbol). A `dynamic-rails` finding after `ractorize!` names the
first object the freeze rejected, or the line where a request
on the frozen app or inside a Ractor broke; without Rails 8.2
an info note says the graph was not frozen.

## Native extensions (C, Rust, and Zig)

Audition cannot read native code, but it reports the one
fact that decides its Ractor behavior. Ractor::UnsafeError
("ractor unsafe method called from not main ractor") is not
an IsolationError: it means a compiled extension never
declared rb_ext_ractor_safe, so every method it defines
raises on first call from a non-main Ractor, whether the
extension is C, Rust, or Zig. The `native-extension` check
byte-scans every compiled file in the target (*.bundle on
macOS, *.so elsewhere) for that import and warns when it is
missing; an unbuilt checkout is scanned at the source level
instead, beside the build file that compiles it. A declared extension gets an info note: the
declaration is the maintainer's assertion, not a proof, and
only real calls from a Ractor (script and Rack probes, or the
gem's own tests under Ractor.new) verify it.

The require and Rails probes extend it to dependencies: the
harness records every compiled file the load pulled in and
byte-scans those too, reporting silent ones as
`runtime-native-extension` warnings attributed to the
dependency. Three things still hide: extensions loaded
lazily on a code path the probe never runs, Ruby's own
archdir extensions (left to Ruby: ripper and coverage raise
from Ractors, encoding and digest plug-ins define no
methods), and whatever a Rack app loads (the Rack probe
exercises real calls instead, so an UnsafeError shows up as
a boot or call failure). For those, check the binary the
same way:

    nm -u ext.bundle | grep rb_ext_ractor_safe    # macOS
    nm -D -u ext.so | grep rb_ext_ractor_safe     # Linux

A match means the extension declares Ractor safety; silence
means its methods raise from Ractors. For silent extensions:
keep those calls on the main Ractor, try a newer release, or
ask upstream to audit the native code for process-global
state and declare rb_ext_ractor_safe(true) (from Rust:
rb_sys::rb_ext_ractor_safe(true)) first thing in Init_*.

## What the fixer refuses (human work)

Registries and accumulators (`@x ||= {}` then mutated),
constructor singletons (`@instance ||= new`), computed config
setters, settings DSLs (sinatra-style), sync primitives,
cross-file-mutated tables. These need a copy-on-write redesign;
the pattern study has worked recipes for it, including
the frozen private constant for configuration-free memos,
freezing value objects at the end of initialize, and the
snapshot-and-rehydrate protocol for lock-bearing singletons:
https://github.com/yaroslav/audition/blob/main/docs/rails_core_best_practices.md

## Common mistakes

- Pointing `--fix` at an installed gem path: fixes need a
  writable checkout.
- Auditing under `bundle exec` from another project: the
  dynamic probe fails on missing target gems.
- Treating `blocked` as the target's failure: it is a
  dependency finding; report it as such.
- Hand-porting fixes the fixer already generates: apply,
  review, revert selectively.
- Fixing without a suite baseline: pre-existing failures get
  blamed on the fixes.
- Leaving accepted findings as prose instead of encoding them
  with pragmas, config, or the baseline.
- Reading a `native-extension` info note as proof of safety:
  the byte scan says declared or silent, never safe; only real
  calls from a Ractor verify the declaration.

Wersje

W bazie nie ma innych skilli o nazwie ractor-readiness.

Migawka bazy z 13.11.2026 · wersja paczki 25f0b458d5bf (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 86ruby-on-rails
    Podpowiada konwencje i wytyczne Ruby on Rails przy pracy z plikami rb.
  • 100ruby-idioms
    Stosuje zwykłe idiomy Ruby: obiekty wartości, obsługę błędów, pattern matching, Ractors i YJIT, bez wzorców typowych dla Rails.
  • 100ruby
    Podpowiada idiomy języka Ruby 3.x: pattern matching, Ractors, RBS, obsługę błędów i optymalizację wydajności czystego kodu Ruby.
  • 90ruby-pro
    Pisze idiomatyczny Ruby z metaprogramowaniem, wzorcami Rails i optymalizacją wydajności, a także przy testach i gemach.
  • 90ruby-rails
    Pomaga budować aplikacje Ruby on Rails: kontrolery, ActiveRecord, obiekty serwisowe, tryb API, zadania w tle i testy RSpec.
  • 100ruby-script
    Pisze skrypt w Ruby według szablonu, z konwencjami projektu i wymaganymi wzorcami dla skryptów.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.