fix(oxlint): patch panics to allow programmatic usage#21899
Merged
camc314 merged 3 commits intoMay 18, 2026
Conversation
`oxlint::lint` is exposed via napi and can therefore be invoked more
than once in the same Node process (e.g. from a long-lived linter
daemon, a build-tool worker, or an LSP host). Today the second call
panics in one of three places:
1. `init_tracing` calls `.init()` on a `tracing_subscriber::registry()`,
which internally `set_global_default(...).unwrap()`s. The second
call returns `Err(SetGlobalDefaultError("a global default trace
dispatcher has already been set"))` and panics.
2. `init_miette` calls `miette::set_hook(...).unwrap()`. `set_hook`
returns `Err` if a hook is already installed, so it panics on the
second call.
3. `LintCommand::init_rayon_thread_pool` calls
`rayon::ThreadPoolBuilder::new()...build_global().unwrap()`. The
second call returns
`Err(ThreadPoolBuildError { kind: GlobalPoolAlreadyInitialized })`
and panics.
All three are one-shot global inits that should silently no-op on
repeat invocation. Wrap the first two in a `OnceLock` and discard the
result; replace the `.unwrap()` on `build_global` with `let _ = ...`.
`oxfmt` already uses the same `OnceLock` + `try_init` pattern at
`apps/oxfmt/src/core/utils.rs`, so this brings oxlint in line.
Caveat for users: rayon's global pool keeps the thread count from the
first call. Subsequent calls with a different `--threads` value are
silently ignored. That matches rayon's documented semantics and is the
only sensible behaviour without tearing down and recreating the pool.
This change unblocks the daemon-style worker pattern at
https://github.com/MatissJanis/oxlint-lage-repro, which on the Datadog
web-ui codebase (~7,500 packages) cuts cold-cache lint runtime from
~20 minutes to ~10 minutes by amortising oxlint's ~1.6s startup across
many packages handled by the same lage worker thread.
camc314
requested changes
Apr 29, 2026
Address review feedback on oxc-project#21899. Now that the panic-prone init calls live inside `OnceLock::get_or_init`, the closure runs at most once per process, so the inner result is safe to `.unwrap()` instead of swallowing with `let _ = ...`. Also wrap the rayon `build_global` call in its own `OnceLock` so it follows the same pattern.
camc314
approved these changes
Apr 29, 2026
Contributor
There was a problem hiding this comment.
Thanks! Just as a note, we are providing no guarentees that this won't break in the future.
@overlookmotel do you mind reviewing this as well
…entrant-lint # Conflicts: # apps/oxlint/src/command/lint.rs
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes oxlint’s global initialization paths idempotent so the NAPI lint() entry point can be invoked multiple times in a long-lived process.
Changes:
- Wraps miette and tracing initialization in
OnceLock. - Wraps Rayon global thread pool initialization in
OnceLock. - Documents first-call-wins behavior for thread count selection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
apps/oxlint/src/init.rs |
Makes miette/tracing initialization run only once per process. |
apps/oxlint/src/command/lint.rs |
Makes Rayon global thread pool setup run only once per process. |
camc314
pushed a commit
that referenced
this pull request
May 18, 2026
# Oxlint ### 🚀 Features - 1ae291e linter/no-underscore-dangle: Add `allowInUsingDeclarations` option (#22483) (吴杨帆) - 0440b0f linter/eslint: Implement `id-match` rule (#22379) (Vladislav Sayapin) - 65bf119 linter: Implement react no-object-type-as-default-prop (#22481) (uhyo) - 2a6ddce linter/eslint: Implement `no-implied-eval` rule (#22391) (Vladislav Sayapin) - d3a3c1d linter: Auto detect agents from CLI and transition to the agent output format (#22068) (Jovi De Croock) - 625758a linter/vitest: Implement padding-around-after-all-blocks rule (#21788) (kapobajza) - 37680b0 linter: Implement react no-unstable-nested-components (#22248) (Jovi De Croock) - d8d9c74 linter: Implement import/newline-after-import rule (#19142) (Ryuya Yanagi) ### 🐛 Bug Fixes - 3f59e03 linter: Only call rayon/miette/tracing inits once (#21899) (Matiss Janis Aboltins) - 602dfd6 linter/promise/no-return-wrap: Detect Promise calls in all branches (#22474) (zennnnnnn11) - e182aee linter: Allow dialogs and popovers for no_autofocus (#22289) (mehm8128) - 7ffb710 linter/jest/vitest: Jest/no-standalone-expect ignores additionalTestBlockFunctions option for jest/vitest hooks (#22477) (kapobajza) - c6f2d3f linter: Add more expression support for iframe-has-title (#22460) (mehm8128) - 5747ff1 linter: Avoid enabling jest with vitest plugin (#22499) (camc314) - 863984f linter/no-find-dom-node: Run on all files (#22479) (bab) ### ⚡ Performance - 2afef79 linter: Optimize `no-loop-func` (#22491) (camchenry) - 4c9ca72 oxlint: Align walker thread count with rayon pool (#22494) (Boshen) ### 📚 Documentation - f7967c7 linter/id-match: Clarify `onlyDeclarations` config docs (#22523) (camc314) - 1e0c97f linter: Fix closing code block in documentation for `padding-around-after-all-blocks` rule. (#22513) (connorshea) - a9049fd linter: Exclude directly provide autoFocus to dialog pattern (#22510) (mehm8128) # Oxfmt ### 🐛 Bug Fixes - 8ee946f formatter/sort_imports: Use label to classify lines (#22512) (leaysgur) - 8c1da44 formatter: Normalize destructuring keys in DCR (#22478) (camc314)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Discord conversation: https://discord.com/channels/1079625926024900739/1498648746433445988
Long story short: we are looking to move from eslint to oxlint in a large (>15m LOC) monorepo. Internally we use lage for fast runs of lint + caching. Eslint exposes a programmatic API that we can use to share the same instance of eslint across different node processes. Thus saving us time in startup. However, oxlint does not currently expose a programmatic API. The workaround: reach deep into oxlint built source to extract
lint()API (fromdist/bindings.js) and use that. Yes - it is very hacky. But it allows us to use oxlint + lage. Reproduction of this hacky solution can be found here: https://github.com/MatissJanis/oxlint-lage-reproIn order for the hacky solution to work: we need to fix a few instances of panic. Hence the PR.
Hope we can make this work!
Full disclosure: this was built using claude code (opus 4.7).