Skip to content

bug(platform): a knowledge-database restart at backend boot is reported as an error and skips the BM25 index check #4035

Closed

Description

@yannickmonney

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 and all roles) catches the failure and calls reportError(…, { 'tale.lane': 'boot' }).
  • verifyDefaultKnowledgeIndexes(sql) (every role) logs BM25 index verification failed: …. The default corpus's BM25 scan is then skipped for the life of the process.

Two things are wrong with this:

  1. A routine restart reports an error. A short restart of knowledge-db turns into an error-level event with the raw driver title, for example PostgresError: 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.
  2. 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: getKnowledgePoolForOrg skips bootstrapOnce for defaultKnowledgeUrl(). 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, with tale.lane: boot and no transaction;
    • log lines [backend] default corpus bootstrap failed: PostgresError: the database system is shutting down and [knowledge] the deployment-default knowledge database: BM25 index verification failed: the database system is shutting down;
    • the process then served (api listening).
  • Knowledge server down at start: the same, with Error: connect ECONNREFUSED …. It sent one error event per start.

Options (needs a decision)

  1. 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.
  2. 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.

Refs #4030, #4031.

Activity

  1. yannickmonney commented on Oct 1, 2026

    @yannickmonney
    ContributorAuthor

    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.

  2. added
    agent-ready
    on Oct 29, 2026
  3. added a commit that references this issue on Oct 30, 2026
    4dd8bdc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions