Repository navigation
Description
Summary
When the knowledge database is unavailable as a backend process boots (restarting, still starting, or refusing), the boot's knowledge steps report it at error level and boot carries on without them:
ensureDefaultCorpusSchema()(backend/main.ts, worker andallroles) catches the failure and callsreportError(…, { 'tale.lane': 'boot' }).verifyDefaultKnowledgeIndexes(sql)(every role) logsBM25 index verification failed: …. The default corpus's BM25 scan is then skipped for the life of the process.
Two things are wrong with this:
- A routine restart reports an error. A short restart of
knowledge-dbturns into an error-level event with the raw driver title, for examplePostgresError: the database system is shutting down(the title of GlitchTip tale/tale#343, see bug(platform): a backend that starts during a database restart reports an error and exits #4030). The docs say a database restart is not reported as an error. - The scan does not happen. "Every role verifies the default corpus's BM25 indexes BEFORE a job or a request can write to them" (
main.ts) holds only if the knowledge database answers at that exact moment. The default corpus never bootstraps lazily:getKnowledgePoolForOrgskipsbootstrapOncefordefaultKnowledgeUrl(). So nothing re-checks the indexes until the next process restart, and the BM25 write guard is never armed for an index that a crash-mode stop corrupted.
In compose, backend-api and backend-worker declare depends_on for db and object-store only, not knowledge-db. A start that races knowledge-db is therefore an ordinary event, not a corner case.
#4031 makes the app database wait at boot (runBootMigrations). It deliberately leaves these steps alone, because going quiet here would hide the skipped scan.
Local evidence (isolated PostgreSQL 16 servers, a fake error-tracking ingest, no production contact)
The app database ran on one server and the knowledge database on a second server. Backend ROLE=all, branch of #4031; these knowledge steps are unchanged from main.
- Knowledge server in its shutdown phase (new connections refused with 57P03) while the backend starts:
- 1 error event
PostgresError: the database system is shutting down, withtale.lane: bootand no transaction; - log lines
[backend] default corpus bootstrap failed: PostgresError: the database system is shutting downand[knowledge] the deployment-default knowledge database: BM25 index verification failed: the database system is shutting down; - the process then served (
api listening).
- 1 error event
- Knowledge server down at start: the same, with
Error: connect ECONNREFUSED …. It sent one error event per start.
Options (needs a decision)
- Wait out the knowledge database at boot, as fix(platform): wait out a restarting database when the backend boots #4031 does for the app database. This is bounded by
ROUTINE_RESTART_MS.- Cost: when the knowledge database is down, a process stops answering for up to a minute more, including the api role, which verifies the indexes before it serves.
- On a persistent outage it reports and continues as today.
- Retry in the background once the knowledge database answers. The process starts at once.
- The skipped scan and bootstrap run as soon as the knowledge database is back.
- Report only an outage that outlasts
ROUTINE_RESTART_MS, once. - Requires checking that
applyIndexHealthReport's effects (audit, bell, re-queue) are idempotent if the step is retried after a partial run.
Either option should keep "the scan was skipped" visible while it is skipped, as a warning line or the existing audit or bell, rather than dropping it.
Activity
yannickmonney commentedon Oct 1, 2026
Manager decision: choose automatic recovery after the knowledge database returns (option 2). Keep unrelated API operations available during a persistent knowledge outage. A bounded foreground wait may reuse the existing restart budget, but waiting and then permanently skipping the scan is insufficient.
Keep bootstrap/verification visibly pending until it actually completes, and complete that pending boot check before the affected corpus accepts mutations. Reuse the existing single-flight/retry/lifecycle and corpus-health mechanisms. An unavailable verifier must not be reclassified as a corrupt index: preserve the established health/degraded policy once an actual report is available. Check idempotency of partial announcements, rebuild scheduling and requeue effects, plus shutdown cleanup.
Please handle this in a separate PR after the current #4031/#4033 review. Prove local recovery for api and worker/all, outages shorter and longer than the routine window, concurrent callers, partial effects and known corrupt indexes, with real owned PostgreSQL and inert reporting. Keep #4031's scope unchanged. This decision is based on the current source and the issue's reported local evidence; it is not an independent reproduction or a fix claim.
fix(platform): wait out a knowledge database restart at boot
fix(platform): wait out a knowledge outage at boot and in jobs alike
fix(platform): wait out a knowledge outage at boot and in jobs alike