QVAC-12232 fix: handle unhandled worker process termination in Bare runtime#1480
Merged
simon-iribarren merged 7 commits intoApr 16, 2026
Conversation
opaninakuffo
previously approved these changes
Apr 13, 2026
- Remove unused isStaleWorkerLock export from worker-lock.ts - Use optional chaining in unloadAllModels (model-registry.ts)
Introduces server/utils/qvac-paths.ts with getQvacPath(...subPaths) as the single place that resolves paths under ~/.qvac. Updated worker-lock, cache, config-registry, and hyperdrive to use it instead of manually constructing path.join(HOME_DIR, ".qvac", ...) each time.
2eb511f
641243e to
2eb511f
Compare
NamelsKing
approved these changes
Apr 15, 2026
lauripiisang
approved these changes
Apr 16, 2026
opaninakuffo
approved these changes
Apr 16, 2026
Contributor
Author
|
/review |
Contributor
Tier-based Approval Status |
This was referenced Apr 22, 2026
simon-iribarren
added a commit
that referenced
this pull request
Apr 22, 2026
Bumps @qvac/registry-client from 0.4.0 to 0.4.1 to release the corestoreOpts constructor option added by #1480, unblocking the SDK follow-up that enables corestoreOpts: { wait: true }.
simon-iribarren
added a commit
to simon-iribarren/qvac
that referenced
this pull request
Apr 22, 2026
…VAC-12232) Bumps @qvac/registry-client to ^0.4.1 and enables waitForLock semantics on the Corestore backing the registry client. This prevents tryLock collisions when multiple SDK instances on the same machine contend over ~/.qvac/registry-corestore/<key>, which was the motivating failure mode for tetherto#1480. Blocked on: release PR tetherto#1698 (@qvac/registry-client v0.4.1 publish). bun.lock update + review-ready flip will follow once v0.4.1 is on npm.
Victor-Rodzko
pushed a commit
that referenced
this pull request
Apr 30, 2026
The bare worker leaks indefinitely when started while another SDK process
holds the registry corestore lock. Root cause: `corestoreOpts: { wait: true }`
issues a blocking `flock(LOCK_EX)` on a libuv worker thread that JS cannot
cancel, so when SIGTERM/IPC-disconnect arrives, the in-flight `client.ready()`
never resolves (cleanup early-returns with `registryClient = null`) and
`process.exit()` cannot terminate Bare while the native handle is held.
The OS process wedges forever, breaking the three `no-lingering-bare-*`
e2e tests in mixed-suite runs.
`wait: true` was deliberately added by #1480 (QVAC-12232) to tolerate
transient lock contention during another SDK's startup/shutdown; reverting
to the bare default would re-introduce that bug. Instead, switch to
`wait: false` (tryLock) and provide an equivalent JS-bounded retry budget
in the existing retry loop:
- 8 attempts, 250 ms base backoff, capped by a 10 s deadline
- each step is a fresh non-blocking syscall — `EBUSY` surfaces to JS
immediately, so shutdown remains cancellable at every point
- exhausted budget propagates the underlying error, hitting the
existing `closeRegistryClient` early-return on `null` and letting
`process.exit()` terminate the worker cleanly
As defense in depth, arm a 3-second SIGKILL safety net in
`shutdownBareDirectWorker` (unrefed timer) before calling `process.exit`,
so any future blocking-handle bug can't survive shutdown.
Covered by existing `no-lingering-bare-{sigterm,close,ipc-disconnect}`
e2e tests, which now pass in mixed-suite runs.
simon-iribarren
added a commit
that referenced
this pull request
May 1, 2026
#1835) The bare worker leaks indefinitely when started while another SDK process holds the registry corestore lock. Root cause: `corestoreOpts: { wait: true }` issues a blocking `flock(LOCK_EX)` on a libuv worker thread that JS cannot cancel, so when SIGTERM/IPC-disconnect arrives, the in-flight `client.ready()` never resolves (cleanup early-returns with `registryClient = null`) and `process.exit()` cannot terminate Bare while the native handle is held. The OS process wedges forever, breaking the three `no-lingering-bare-*` e2e tests in mixed-suite runs. `wait: true` was deliberately added by #1480 (QVAC-12232) to tolerate transient lock contention during another SDK's startup/shutdown; reverting to the bare default would re-introduce that bug. Instead, switch to `wait: false` (tryLock) and provide an equivalent JS-bounded retry budget in the existing retry loop: - 8 attempts, 250 ms base backoff, capped by a 10 s deadline - each step is a fresh non-blocking syscall — `EBUSY` surfaces to JS immediately, so shutdown remains cancellable at every point - exhausted budget propagates the underlying error, hitting the existing `closeRegistryClient` early-return on `null` and letting `process.exit()` terminate the worker cleanly As defense in depth, arm a 3-second SIGKILL safety net in `shutdownBareDirectWorker` (unrefed timer) before calling `process.exit`, so any future blocking-handle bug can't survive shutdown. Covered by existing `no-lingering-bare-{sigterm,close,ipc-disconnect}` e2e tests, which now pass in mixed-suite runs. Co-authored-by: Dmytro Medvinskyi <functionsilence@gmail.com>
simon-iribarren
added a commit
that referenced
this pull request
May 1, 2026
#1842) The bare worker leaks indefinitely when started while another SDK process holds the registry corestore lock. Root cause: `corestoreOpts: { wait: true }` issues a blocking `flock(LOCK_EX)` on a libuv worker thread that JS cannot cancel, so when SIGTERM/IPC-disconnect arrives, the in-flight `client.ready()` never resolves (cleanup early-returns with `registryClient = null`) and `process.exit()` cannot terminate Bare while the native handle is held. The OS process wedges forever, breaking the three `no-lingering-bare-*` e2e tests in mixed-suite runs. `wait: true` was deliberately added by #1480 (QVAC-12232) to tolerate transient lock contention during another SDK's startup/shutdown; reverting to the bare default would re-introduce that bug. Instead, switch to `wait: false` (tryLock) and provide an equivalent JS-bounded retry budget in the existing retry loop: - 8 attempts, 250 ms base backoff, capped by a 10 s deadline - each step is a fresh non-blocking syscall — `EBUSY` surfaces to JS immediately, so shutdown remains cancellable at every point - exhausted budget propagates the underlying error, hitting the existing `closeRegistryClient` early-return on `null` and letting `process.exit()` terminate the worker cleanly As defense in depth, arm a 3-second SIGKILL safety net in `shutdownBareDirectWorker` (unrefed timer) before calling `process.exit`, so any future blocking-handle bug can't survive shutdown. Covered by existing `no-lingering-bare-{sigterm,close,ipc-disconnect}` e2e tests, which now pass in mixed-suite runs. Co-authored-by: Simon Iribarren <simon.ig13@gmail.com> Co-authored-by: Dmytro Medvinskyi <functionsilence@gmail.com>
Proletter
pushed a commit
that referenced
this pull request
May 24, 2026
Bumps @qvac/registry-client from 0.4.0 to 0.4.1 to release the corestoreOpts constructor option added by #1480, unblocking the SDK follow-up that enables corestoreOpts: { wait: true }.
Proletter
pushed a commit
that referenced
this pull request
May 24, 2026
…untime (#1480) * fix: handle unhandled worker process termination in Bare runtime (QVAC-12232) - Add uncaughtException/unhandledRejection handlers to trigger cleanup on crash - Add IPC socket close detection to handle parent process termination - Add PID-based lock file (~/.qvac/.worker.lock) with stale detection on startup - Fix unloadAllModels to close FilesystemDL loaders (aligned with single-model path) - Use exit code 1 for crash shutdowns, 0 for graceful Made-with: Cursor * fix: add fd-lock retry with backoff and corestoreOpts plumbing for registry client - Add retry with exponential backoff (3 attempts, 500/1000/2000ms) on fd-lock errors in getRegistryClient() - Plumb corestoreOpts through QVACRegistryClient constructor to Corestore (registry-server) - Add corestoreOpts to QVACRegistryClientOptions type definition - SDK will pass wait: true once @qvac/registry-client dep is bumped * fix: make getRegistryClient single-flight to prevent concurrent fd-lock contention * fix: address review comments on worker termination PR - Remove unused isStaleWorkerLock export from worker-lock.ts - Use optional chaining in unloadAllModels (model-registry.ts) * fix: instantiate Corestore in constructor, remove _corestoreOpts property * fix: remove homeDir param from worker-lock, resolve via getEnv internally * chore: add getQvacPath utility, consolidate ~/.qvac path resolution Introduces server/utils/qvac-paths.ts with getQvacPath(...subPaths) as the single place that resolves paths under ~/.qvac. Updated worker-lock, cache, config-registry, and hyperdrive to use it instead of manually constructing path.join(HOME_DIR, ".qvac", ...) each time.
Proletter
pushed a commit
that referenced
this pull request
May 24, 2026
#1835) The bare worker leaks indefinitely when started while another SDK process holds the registry corestore lock. Root cause: `corestoreOpts: { wait: true }` issues a blocking `flock(LOCK_EX)` on a libuv worker thread that JS cannot cancel, so when SIGTERM/IPC-disconnect arrives, the in-flight `client.ready()` never resolves (cleanup early-returns with `registryClient = null`) and `process.exit()` cannot terminate Bare while the native handle is held. The OS process wedges forever, breaking the three `no-lingering-bare-*` e2e tests in mixed-suite runs. `wait: true` was deliberately added by #1480 (QVAC-12232) to tolerate transient lock contention during another SDK's startup/shutdown; reverting to the bare default would re-introduce that bug. Instead, switch to `wait: false` (tryLock) and provide an equivalent JS-bounded retry budget in the existing retry loop: - 8 attempts, 250 ms base backoff, capped by a 10 s deadline - each step is a fresh non-blocking syscall — `EBUSY` surfaces to JS immediately, so shutdown remains cancellable at every point - exhausted budget propagates the underlying error, hitting the existing `closeRegistryClient` early-return on `null` and letting `process.exit()` terminate the worker cleanly As defense in depth, arm a 3-second SIGKILL safety net in `shutdownBareDirectWorker` (unrefed timer) before calling `process.exit`, so any future blocking-handle bug can't survive shutdown. Covered by existing `no-lingering-bare-{sigterm,close,ipc-disconnect}` e2e tests, which now pass in mixed-suite runs. Co-authored-by: Dmytro Medvinskyi <functionsilence@gmail.com>
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.
🎯 What problem does this PR solve?
SIGTERM/SIGINTfor cleanup — uncaught exceptions, unhandled rejections, parent crashes, andSIGKILLall leave resources lockedunloadAllModelsskipsFilesystemDL.close()that the single-modelunloadModelpath performs, leaking file handles during shutdowngetRegistryClient()fails instantly on fd-lock contention with no retry — any transient lock (e.g., previous process still releasing) causes immediateModelLoadFailedErrorQVACRegistryClientcreates Corestore withwait: false(default), usingtryLockinstead ofwaitForLock— concurrent SDK instances on the same machine collide on~/.qvac/registry-corestore/<key>Related: Slack thread from Zbigniew documenting the fd-lock error chain in production
📝 How does it solve it?
A. Crash handlers (
worker-core.ts)uncaughtExceptionandunhandledRejectionhandlers onbare-processto trigger full cleanup on unexpected crashesB. IPC disconnect detection (
create-server.ts,worker-core.ts)closeevent in desktop mode — fires when parent process (Electron) crashes or is killedC. Stale lock file (
server/utils/worker-lock.ts)~/.qvac/.worker.lockwritten on startup, removed on graceful shutdownSIGKILL, OOM, power loss)process.kill(pid, 0)for cross-platform liveness checkD. Fix
unloadAllModels(model-registry.ts)loader.close()beforemodel.unload(), matchingunloadModelbehaviorE. Registry client fd-lock retry (
registry-client.ts)getRegistryClient()up to 3 times with exponential backoff (500ms, 1000ms, 2000ms) on "File descriptor could not be locked" errorsF. Corestore
waitoption plumbing (qvac-lib-registry-server/client)QVACRegistryClientnow acceptscorestoreOptsand passes them to theCorestoreconstructorcorestoreOpts?: { wait?: boolean }corestoreOpts: { wait: true }once@qvac/registry-clientdependency is bumped (TODO in code)🧪 How was it tested?
Manual verification — no existing test infrastructure covers worker lifecycle. Suggested e2e tests as follow-up:
setTimeout(() => { throw ... }, 3000)in worker → verify cleanup runs and lock file removedkill -9→ verify lock file persists → restart → verify stale detection and no "resource busy"Files changed
packages/sdk/server/utils/worker-lock.tspackages/sdk/server/worker-core.tspackages/sdk/server/rpc/create-server.tsonDisconnectcallback option tocreateIPCClient, socket close listenerpackages/sdk/server/bare/registry/model-registry.tsunloadAllModelsto close loaders, add per-model error handlingpackages/sdk/server/bare/registry/registry-client.tspackages/qvac-lib-registry-server/client/lib/client.jscorestoreOptsthrough tonew Corestore()packages/qvac-lib-registry-server/client/index.d.tscorestoreOptstoQVACRegistryClientOptionstypeFollow-up needed
@qvac/registry-client→ release withcorestoreOptssupport@qvac/registry-clientdep → enablecorestoreOpts: { wait: true }