Skip to content

fix(platform): pause website scans when the knowledge db is unreachable - #3049

Merged
larryro merged 3 commits into
mainfrom
fix/crawler-pause-on-unreachable-corpus
Aug 25, 2026
Merged

larryro merged 3 commits into
mainfrom
fix/crawler-pause-on-unreachable-corpus

Conversation

@larryro

@larryro larryro commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the endless-retry loop behind TALE-PROJECT-106 — Uncaught PostgresError: password authentication failed for user 'neondb_owner', 234 events, 2026-08-01 → 2026-08-21, ~one every 2 h, userCount: 0 (pure background cron on demo.tale.dev).

Problem

scanWebsite acquired the org corpus pool before its try block. For a bring-your-own database, getKnowledgePoolForOrg runs real SQL (the corpus-schema bootstrap), so an invalid credential threw right there and escaped the action uncaught. The catch then recorded status = 'error' into the same unreachable Postgres, so when the database itself was down nothing was recorded anywhere. The Convex websites row never advanced its clock, and the five-minute scheduler re-queued the domain forever — no backoff, no cap, no admin-facing signal.

Fix

  • Classify connection-class errors — isConnectionFailure in knowledge/pool.ts: SQLSTATE classes 08/28, 3D000, 57P03, postgres.js lifecycle codes (CONNECT_TIMEOUT, CONNECTION_CLOSED, …), Node system errors (ENOTFOUND, ECONNREFUSED, …).
  • Wrap pool acquisition and the scan body — connection-class failures are recorded on the Convex websites row (recordScanFailure), the only store still reachable; reachable-but-failed scans keep marking the corpus and now also stamp the Convex row.
  • Backoff — every failed attempt stamps metadata.lastScanAttemptAt; the scheduler (pure policy in websites/scan_scheduling.ts, unit-tested) retries failing sites on min(interval, 2 h) instead of every tick.
  • Pause + notify — after 3 consecutive connection-class failures the site's scans pause (metadata.scanPausedAt) and the org's admins get a one-per-incident bell notification (security category, Slack-mirrored): "Check the connection under Settings → Data residency, then resume scanning from the Websites page."
  • UI — paused rows show a Paused badge (table + view dialog), the row menu gains Resume scanning (clears the pause and kicks a verification scan immediately), and the view dialog explains the pause. Strings ship in en/de/fr, mirrored in NOTIFICATIONS_I18N for the Slack sink, and registered in keys-dynamic.yml (server-emitted keys are invisible to the client-source scanner).

The failure bookkeeping lives in websites.metadata — no schema change, no migration.

Tests

  • pool.test.ts — classifier: unreachable vs statement-level SQLSTATEs (an FK violation like the Jul 18 website_urls incident stays statement-level).
  • scan_scheduling.test.ts — the regression: a failing site is not re-queued on the next tick; bounded failure retry (a 30-day site retries in 2 h, an hourly site stays hourly); paused sites are never due; stuck-scanning takeover unchanged and re-armed by failed attempts.
  • record_scan_failure.test.ts (convex-test) — streak counting, pause at the threshold with exactly one notification, no re-notify while paused, streak reset on reachable-but-failed scans, clearScanFailures, and the scheduler projection.

Observed: 416 tests green across convex/websites, convex/knowledge, convex/notifications, lib/i18n; tsc --noEmit clean; oxlint --type-aware clean over the touched dirs.

Ops follow-up (not in this PR)

The demo org's Neon credential (neondb_owner) is still invalid — last failure 2026-08-21. Rotate/fix it under Settings → Data residency, then hit Resume scanning on the site. The GlitchTip issue should stay open until this ships and the credential is fixed.

CI fixes (reviewer: "fix all ci action errors")

  • UI job — website-row-actions.test.tsx (existing jsdom suite) mocks ../hooks/mutations with an explicit factory, so the new useResumeScanning hook threw "no export defined on the mock". Fixed by extending the mock and locking the new behaviour: the resume item appears only while the site is paused, and clicking it calls the action with the row's websiteId. Full test:ui suite verified locally (434 files / 3338 tests green); the UI job passed on the next CI round.
  • Playwright (web) job — inherited from main, not from this PR: 500eaa3e8 added a first-party analytics tag loading /_a/script.js, a path only the web droplet's Caddy proxy answers in production. Vite's dev/preview servers 404 it, tripping the smoke suite's no-console-errors guard — latent on main because change detection skips the web suite there, surfacing on any PR whose merge ref includes it. Fixed here (fix(web) commit) with a no-op stub served by vite dev/preview only; the built artifact is untouched, and the tale-web:release-feed dev route is preserved. Web smoke suite verified locally against a build carrying the analytics tag. Maintainers may prefer to cherry-pick that one commit straight to main, since every open PR that touches web paths will hit the same failure.

A scheduled crawl of an org with a bring-your-own knowledge database
acquired its corpus pool before the try block, so a connection-class
failure (rotated credential, DNS, refused) escaped the action uncaught,
and the catch recorded the failure into the same unreachable Postgres.
Nothing ever reached the Convex websites row, so the five-minute
scheduler re-queued the domain forever — three weeks of silent 2-hourly
failures on demo.tale.dev (GlitchTip TALE-PROJECT-106, 234 events).

- classify connection-class errors in knowledge/pool.ts
  (isConnectionFailure) and catch them around pool acquisition and all
  corpus SQL in scanWebsite
- record failed attempts on the Convex websites row — the only store
  still reachable — and surface the error in the websites UI
- back failed scans off to a bounded retry window and pause the site
  after 3 consecutive connection failures (websites/scan_scheduling.ts)
- notify org admins once per incident via the notifications bell
  ("check Settings → Data residency"), mirrored for the Slack sink
- add a Paused badge and a "Resume scanning" row action that clears
  the pause and kicks a verification scan
@larryro
larryro force-pushed the fix/crawler-pause-on-unreachable-corpus branch from 80aa8f8 to f489cbe Compare August 23, 2026 09:36
The jsdom suite mocks ../hooks/mutations with an explicit factory, so the
new useResumeScanning hook made WebsiteRowActions throw "no export defined
on the mock" and failed the UI job. Add the hook to the mock and, while
here, lock the new behaviour: the resume item appears only while the
crawler has paused the site, and clicking it calls the action with the
row's websiteId.
main now ships a first-party analytics tag loading /_a/script.js, a path
only the web droplet's Caddy proxy answers in production. Vite's dev and
preview servers have no such upstream, so every page 404s the script into
the browser console and the smoke suite's no-console-errors guard fails —
latent on main (change detection skips the web suite there) and surfacing
on any PR whose merge ref includes it. Serve a no-op stub on exactly that
path in both servers; the built artifact stays untouched, so a broken
droplet proxy still fails loudly in production.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant