Recovery Runbooks
Partially superseded. RB-01…RB-18 remain valid and are referenced from
docs/architecture/OBSERVABILITY-ALERTS-RUNBOOKS.md, which adds the wiring and the whole-app set.
Recovery runbooks
Every runbook states what happened, what the user sees, how to find the trace, whether an external effect happened, whether a replay is safe, and how to verify recovery.
Conventions: OPS=<operation_id>, TASK=<task_id>, MSG=<message_id>. D1 queries are
read-only unless a step says otherwise.
RB-01 — Search appears complete but rows are missing
- What happened:
settleSearchrecorded a status from source outcomes; a source may have returned rows that were rejected at validation, or were truncated by a bound. - User sees:
complete,result_countlower than expected. - Find the trace:
search.settledforOPS; then everyingest.batch.committedwith the sameoperation_id. - Did a source request happen?
scrape.dispatch.startedpersource_id. - D1 committed?
ingest.batch.committedexists; cross-checkSELECT count(*) FROM corpus_job_sources WHERE source_id = ?. - Safe replay? No — the data is already there. First compare
fetchedvsstoredvsskipped; ifskipped > 0, inspectCANONICAL_INVALID_RECORDcounts. - Manual action: if
stored == 0andfetched > 0, run the canonical validation on a sample fromops_scraper_executionsand file a parser defect. - Verify: the same source, re-run as a new search, produces a comparable
fetched.
RB-02 — Search stuck queued / queue backlog
- What happened: messages are not being consumed, or the consumer keeps failing.
- User sees: "queued" for minutes.
- Find: Queue analytics (
oldest_message_age_s),queue.publishedwithoutqueue.consumedforOPS. - Safe replay? Nothing has left the system yet, so yes — replay is safe here.
- Steps: check
CONFIG_BINDING_MISSING; confirm the consumer is deployed with matchingSCRAPE_QUEUE; if a poison message is blocking, move it to the DLQ and continue. - Verify:
queue.consumedappears forOPS, thensearch.settled.
RB-03 — Search stuck running (stale lease)
- What happened: the consumer died between claim and settle (isolate eviction, 15-min wall clock). Today nothing reclaims it — this is the FM-01 gap.
- User sees: permanently "running"; one-active-search rule blocks new searches.
- Find:
task.claimedwith no matchingsearch.settled;updated_atolder than the lease. - Did external calls happen? Possibly — check
scrape.dispatch.*for the sametask_id. - Safe to force-fail? Yes for the row only if no dispatch is in flight. If
scrape.dispatch.startedhas no.completed, treat the source asuncertain, not as "not run" (RB-06). - Steps (current code, manual):
UPDATE searches SET status='failed', held_reason='stale_lease' WHERE id=OPS AND status='running'; - Verify: user can start a new search;
search.settled/manual row showsfailed.
RB-04 — Every source for one search fails
- What happened: scraper service down, missing binding, tenant key rejected, or the gateway has no usable exit.
- User sees:
failed, no rows. - Find:
scrape.dispatch.failed.err_codedistribution forOPS. - Did it leave the system?
SCRAPER_DEPENDENCY_MISSING/CREDENTIAL_REJECTED/ gateway 502 ⇒ no board contact. - Safe replay? Yes for dependency/credential 4xx and gateway 502 (no external effect).
- Steps: fix the binding/key (RB-08) or the gateway (RB-07); re-run the search as a new operation (cap permitting).
- Verify: one
scrape.dispatch.completedwithhttp_status=200for a sample source.
RB-05 — Message in the DLQ
- What happened:
max_retriesexhausted (2) — the failure is systemic or a defect. - User sees:
failedwithexecution_errorafter the second attempt. - Find: DLQ message body (ref + HMAC),
TASK,last_err_code. - Did it leave the system? Check
scrape.dispatch.*for thattask_id. - Safe replay? Only if every dispatch has a terminal
.completed/.failedwith nouncertain. Otherwise treat as uncertain and do not replay automatically. - Steps: consume the DLQ with a manual tool (consumer required — not built), inspect, then either drop or re-enqueue with a new attempt marker.
- Verify: a new
search.settledfor the same logical search, or an explicit decision recorded inops_audit_events.
RB-06 — Uncertain scraper outcome (timeout)
- What happened: the HTTP request timed out after dispatch; the board may have served it and the scraper may have consumed quota.
- User sees:
failed/ (target design)uncertain. - Find:
scrape.dispatch.startedpresent,.completedabsent,.failedwithSCRAPER_TIMEOUT. - Did it happen? Unknown by design. Never auto-retry.
- Steps: query the scraper's own execution log for that attempt id; if the scraper logs
a completed scrape, ingest its result if retrievable; otherwise mark the source
uncertainand let the user re-run deliberately. - Verify: a subsequent deliberate search succeeds;
scrape_uncertain_totalreturns to 0.
RB-07 — Egress blocked / gateway degraded
- What happened: gateway exits cooling, 407 from upstream, or board WAF.
- User sees: source failures with
SCRAPER_UPSTREAM_502/SOURCE_BLOCKED. - Find: gateway
/stats(ready,cooling, per-exit served),scrape.dispatch.failedwitherr_class=upstream. - Safe replay? Yes once the gateway is healthy; no external effect occurred when the gateway itself answered 502.
- Steps: rotate upstream credentials, add exits, confirm
GATEWAY_DIRECTis not set in production; never widen the pool to a policy-blocked source. - Verify: gateway
/health→ok, one source returns 200 with rows.
RB-08 — Missing binding / secret (503)
- Find:
CONFIG_BINDING_MISSING/CONFIG_SECRET_MISSINGnaming the binding. - User sees: 503 naming the dependency (never a generic 500).
- Safe replay? Yes; nothing was charged.
- Steps: set the secret (
wrangler secret put), redeploy, re-run/health. - Verify:
/health200 and a single source fetch succeeds.
RB-09 — Caps / quotas exhausted
- Find:
cap.reachedwithkind, orSCRAPER_BUDGET_EXHAUSTED(402, uncharged). - User sees: "cap reached" or "source budget spent".
- Replay? Not until the UTC window resets. Do not raise a cap to "fix" one user.
- Steps (owner): confirm the cap math (20 searches × 10 source fetches = 200); if a source's per-day budget is genuinely exhausted, that is a capacity decision, not a bug.
- Verify: next-day ledger window opens;
cap.reservedsucceeds.
RB-10 — Auth failures
- Find:
auth.rejectedwithreason;AUTH_OWNER_MISSING⇒ session valid, account row absent (this is a data/identity bug, not a login bug). - Steps: re-authenticate; if
OWNER_MISSINGpersists, checkauth/ensurecreated the user row and thatowner_idmatches across tables. - Never: trust a client-supplied
x-request-idorowner_idto fix this. - Verify:
/api/v1/accountreturns the owner's row.
RB-11 — D1 batch failed / partial write
- Find:
D1_BATCH_FAILED/D1_CONSTRAINT/D1_STATEMENT_LIMIT, withstmtsandsource_id. - What is the state? D1
batch()is not transactional across chunks: chunk N may have committed while chunk N+1 failed. Replay of ingest is safe because it is an upsert keyed oncanonical_urland(source_id, source_job_id). - Steps: re-run the source task (new attempt); never
DELETEcorpus rows to "clean up". - Integrity check:
SELECT count(*) FROM corpus_job_sources s LEFT JOIN corpus_jobs j ON j.id = s.job_id WHERE j.id IS NULL;⇒ must be 0. - Verify: the same source ingest reports
created + updated == stored.
RB-12 — 5xx storm / forged messages
- Find:
http.request.failedgrouped byerr_code;queue.forgedfor HMAC failures (a forged message is acked, never retried). - Steps: if forged messages appear, rotate
QUEUE_HMAC_KEYand redeploy producer and consumer together; investigate who can write to the queue. - Verify:
queue.forgedrate returns to 0; queue depth drains.
RB-13 — R2 object missing / upload interrupted
- Find:
R2_OBJECT_MISSINGon download; row references a key. - Steps: list the owner prefix; if absent, re-upload through the signed-URL flow (the resume file lives on the user's device). Do not fabricate a placeholder document.
- Verify: download succeeds;
r2.getlogs 200 with bytes.
RB-14 — Erasure incomplete
- Find:
ERASURE_INCOMPLETE; the erasure phase set is derived fromops_table_policy. - Steps: re-run the prefix sweep until a pass returns zero objects (by design), then delete rows. Never reverse the order.
- Verify: empty listing + zero rows for the owner across the phase set; record the
completion in
ops_audit_events.
RB-15 — AI provider failure
- Find:
AI_PROVIDER_TIMEOUT/AI_RATE_LIMITED/AI_MALFORMED_RESPONSE. - Safe replay? Yes, past a successful budget reservation; ranking produces drafts, never external effects.
- Steps: check provider config, budget window; fall back to keyword ranking (existing fallback) rather than blocking the page.
- Verify:
/jobs/ranked/aireturns providergroq-match(or the configured provider).
RB-16 — Gmail uncertain send
- Find:
email.send.outcome = uncertain; draft statusunknown. - User sees: "unconfirmed — check your sent mail" with the two-step confirm.
- Never auto-retry. The provider may have accepted it.
- Steps: owner confirms "It went out" (
sent_unrecordedsemantics) or "It did not" (resolveSend), then the cap slot is handled per the existing ledger rules. - Verify: exactly one outbound
emailEventsrow for the draft.
RB-17 — Retention sweep not running
- Find: no
retention.runfor 2 intervals;expiredCountquery returns rows. - Impact: expired jobs are still filtered by reads (design), so this is correctness-safe but growth-unsafe.
- Steps: run the sweep manually via
wrangler dev/scheduled trigger; check the cron binding andscheduled()deployment. - Verify:
SELECT count(*) FROM corpus_jobs WHERE expires_at <= now→ 0.
RB-18 — Logpush gap
- Find: the daily partition check (expected
env/dt=/svcprefixes) missing for a day. - Steps: verify the Logpush job state, re-push the interval if the platform allows it; note the gap explicitly in the incident record rather than claiming complete history.
- Verify: partition exists and line counts are within the expected band (sampling accounted for).