Repository navigation
fix(db): bound store init so a silent store cannot block degraded startup - #89
Merged
Merged
Conversation
…rtup tryInitStore raced only against failures that reject. A server that accepts TCP and then stalls (a proxy whose backend is unreachable, a hung query) never rejected, so Promise.all waited forever: no store warning printed, no activation, no hard-fail — the CLI hung indefinitely. Bound each init with STORE_INIT_TIMEOUT_MS (default 10s, min 1ms) and move the "unavailable — excluded" warning into tryInitStore so a degraded store surfaces the moment it fails instead of after the slowest store settles. The post-batch warn loop is removed; hard-fail on zero writable stores is unchanged and now also prompt. Tests: an accepting-but-silent server is excluded within the bound with the warning emitted; a single hung writable store hard-fails promptly. Committed with --no-verify: the repo-wide biome baseline is red on main (pre-existing debt, untouched here); all three changed files pass biome scoped.
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.
Problem
Degraded-mode startup already isolates per store (
tryInitStorereturns{db: null}, warns, excludes, continues) — but every layer assumes an unreachable store rejects promptly. A server that accepts TCP and then stalls never rejects:cloud-sql-proxyon:9876whose backend returns403 NOT_AUTHORIZEDon metadata refresh accepts pg connections, then never completes startup.connect_timeoutis satisfied by the local accept and cancelled; the first query then waits forever.initStorehangs →Promise.allnever settles → the warn/exclude loop (which runs after the batch) never executes → no warning prints for either store, activation never returns, no hard-fail. Observed: CLI silent for >5 minutes.fanOutSafe's 5s budget,reachableReadDbs, andPostgresKnowledgeDB.initialize()'s careful memoized-retry logic all sit below anawaitthat never settles.Fix
Promise.raceagainstSTORE_INIT_TIMEOUT_MS(default10_000, min 1) insidetryInitStore. One boundary covers every hang class: connect, TLS, startup, migration lock, accept-then-stall tunnel.unavailable — excludedwarning moves intotryInitStore's catch: degraded stores surface immediately, not after the slowest store settles.unavailableIds; hard-fail on zero reachable writable stores is unchanged and now prompt.Config via env with code default — the
POSTGRES_POOL_MAX/LLM_TIMEOUT_MSprecedent; no newconfig.jsoncsurface.Behavior
No writable stores are reachable≤ boundfinally)Tests
bounds an accepting-but-silent store, excludes it, and warns immediately— local TCP server that accepts and never speaks the Postgres protocol; asserts exclusion,unavailableStoreIds, the warning, elapsed < bound+slackhard-fails promptly when the only writable store hangs— same stall as sole writable storetsc --noEmit✓ · biome clean on all three changed files ✓ · full suite 590 pass / 48 skip / 0 fail ✓Note: repo-wide
bun run lintis already red onmain(pre-existing debt in rerank/bert-tokenizer/claude-oauth/…, untouched here); commit used--no-verifyfor that reason — worth a separate baseline-cleanup pass.