fix(oxlint): patch panics to allow programmatic usage#21899
Open
MatissJanis wants to merge 2 commits intooxc-project:mainfrom
Open
fix(oxlint): patch panics to allow programmatic usage#21899MatissJanis wants to merge 2 commits intooxc-project:mainfrom
MatissJanis wants to merge 2 commits intooxc-project:mainfrom
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
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).