fix(db): break probe-failed/restore loop that hangs server startup on sql.js OOM (v3.8.46)#6630
Open
KooshaPari wants to merge 1 commit into
Open
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Contributor
Author
|
References #6628 |
Closed
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.
Summary
Fixes the probe-failed/restore loop that hangs the OmniRoute server on
Starting server...indefinitely when sql.js fails to loadstorage.sqlite. Three layered mitigations insrc/lib/db/core.ts:globalThis.__omnirouteDbInitFataland throw a clear, actionable error. Subsequent callers short-circuit on the cached fatal instead of re-entering the probe.globalThis.__omnirouteDbProbeFailureCount. AfterMAX_CONSECUTIVE_PROBE_FAILURES(3) attempts, abort startup with a clear message pointing at the recovery steps.getDbInstance()is called, kick off a single sharedensureDbInitialized()Promise stored onglobalThis.__omnirouteDbInitPromiseso concurrent callers share onepreInitSqlJsrun instead of each racing their own probe.Root cause
getDbInstance()is not concurrency-safe. On any probe failure, the legacy behaviour renamesstorage.sqlite→storage.sqlite.probe-failed-<ts>. Concurrent subsystems (STARTUP, HealthCheck, ProviderLimitsSync, ModelSync, BATCH, callLogs) all race their firstgetDbInstance()during boot; on the next call each one finds the preserved probe-failed backup inlistProbeFailureBackups(), renames it back tostorage.sqlite, and re-runs the probe, which fails again. The rename/restore cycle repeats indefinitely. The server never reachesOmniRoute is running!.Reproduction (v3.8.46, Windows, Node 26, sql.js)
After this fix, the same probe OOM produces a single, clear fatal error:
Related
Cannot create property 'message' on string 'Database closed'TypeError inregisterInstrumentation(a downstream symptom of the same loop). This PR addresses the upstream loop itself.Validation
core.tsparses cleanly underbun build(the onlybun builderrors are unresolved-import warnings forsql.jsanduuidin the fresh test clone — not present in the realnode_modulesinstall).C:\Users\koosh\.bun\install\global\node_modules\omniroute) patched with this fix:http://localhost:20128/returns 200 (469 KB)./v1/modelsreturns the model catalog JSON.db_recovery_2026-07-07\): fatal fires immediately, message includes the data dir path and recovery steps.Risk
throw epaths are preserved.MAX_CONSECUTIVE_PROBE_FAILURES = 3) is conservative: even on a legitimate transient failure (e.g. the file is briefly locked by a parallel writer), the cap is generous enough that the server will retry at least three times before giving up.runDbInstanceInitSync()helper extracts the existing body ofgetDbInstance()verbatim. No behavioural change for callers that don't hit the OOM/race paths.