Skip to Content
JobWzrd Docs

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

  1. What happened: settleSearch recorded a status from source outcomes; a source may have returned rows that were rejected at validation, or were truncated by a bound.
  2. User sees: complete, result_count lower than expected.
  3. Find the trace: search.settled for OPS; then every ingest.batch.committed with the same operation_id.
  4. Did a source request happen? scrape.dispatch.started per source_id.
  5. D1 committed? ingest.batch.committed exists; cross-check SELECT count(*) FROM corpus_job_sources WHERE source_id = ?.
  6. Safe replay? No — the data is already there. First compare fetched vs stored vs skipped; if skipped > 0, inspect CANONICAL_INVALID_RECORD counts.
  7. Manual action: if stored == 0 and fetched > 0, run the canonical validation on a sample from ops_scraper_executions and file a parser defect.
  8. Verify: the same source, re-run as a new search, produces a comparable fetched.

RB-02 — Search stuck queued / queue backlog

  1. What happened: messages are not being consumed, or the consumer keeps failing.
  2. User sees: "queued" for minutes.
  3. Find: Queue analytics (oldest_message_age_s), queue.published without queue.consumed for OPS.
  4. Safe replay? Nothing has left the system yet, so yes — replay is safe here.
  5. Steps: check CONFIG_BINDING_MISSING; confirm the consumer is deployed with matching SCRAPE_QUEUE; if a poison message is blocking, move it to the DLQ and continue.
  6. Verify: queue.consumed appears for OPS, then search.settled.

RB-03 — Search stuck running (stale lease)

  1. 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.
  2. User sees: permanently "running"; one-active-search rule blocks new searches.
  3. Find: task.claimed with no matching search.settled; updated_at older than the lease.
  4. Did external calls happen? Possibly — check scrape.dispatch.* for the same task_id.
  5. Safe to force-fail? Yes for the row only if no dispatch is in flight. If scrape.dispatch.started has no .completed, treat the source as uncertain, not as "not run" (RB-06).
  6. Steps (current code, manual): UPDATE searches SET status='failed', held_reason='stale_lease' WHERE id=OPS AND status='running';
  7. Verify: user can start a new search; search.settled/manual row shows failed.

RB-04 — Every source for one search fails

  1. What happened: scraper service down, missing binding, tenant key rejected, or the gateway has no usable exit.
  2. User sees: failed, no rows.
  3. Find: scrape.dispatch.failed.err_code distribution for OPS.
  4. Did it leave the system? SCRAPER_DEPENDENCY_MISSING / CREDENTIAL_REJECTED / gateway 502 ⇒ no board contact.
  5. Safe replay? Yes for dependency/credential 4xx and gateway 502 (no external effect).
  6. Steps: fix the binding/key (RB-08) or the gateway (RB-07); re-run the search as a new operation (cap permitting).
  7. Verify: one scrape.dispatch.completed with http_status=200 for a sample source.

RB-05 — Message in the DLQ

  1. What happened: max_retries exhausted (2) — the failure is systemic or a defect.
  2. User sees: failed with execution_error after the second attempt.
  3. Find: DLQ message body (ref + HMAC), TASK, last_err_code.
  4. Did it leave the system? Check scrape.dispatch.* for that task_id.
  5. Safe replay? Only if every dispatch has a terminal .completed/.failed with no uncertain. Otherwise treat as uncertain and do not replay automatically.
  6. Steps: consume the DLQ with a manual tool (consumer required — not built), inspect, then either drop or re-enqueue with a new attempt marker.
  7. Verify: a new search.settled for the same logical search, or an explicit decision recorded in ops_audit_events.

RB-06 — Uncertain scraper outcome (timeout)

  1. What happened: the HTTP request timed out after dispatch; the board may have served it and the scraper may have consumed quota.
  2. User sees: failed / (target design) uncertain.
  3. Find: scrape.dispatch.started present, .completed absent, .failed with SCRAPER_TIMEOUT.
  4. Did it happen? Unknown by design. Never auto-retry.
  5. 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 uncertain and let the user re-run deliberately.
  6. Verify: a subsequent deliberate search succeeds; scrape_uncertain_total returns to 0.

RB-07 — Egress blocked / gateway degraded

  1. What happened: gateway exits cooling, 407 from upstream, or board WAF.
  2. User sees: source failures with SCRAPER_UPSTREAM_502 / SOURCE_BLOCKED.
  3. Find: gateway /stats (ready, cooling, per-exit served), scrape.dispatch.failed with err_class=upstream.
  4. Safe replay? Yes once the gateway is healthy; no external effect occurred when the gateway itself answered 502.
  5. Steps: rotate upstream credentials, add exits, confirm GATEWAY_DIRECT is not set in production; never widen the pool to a policy-blocked source.
  6. Verify: gateway /health → ok, one source returns 200 with rows.

RB-08 — Missing binding / secret (503)

  1. Find: CONFIG_BINDING_MISSING / CONFIG_SECRET_MISSING naming the binding.
  2. User sees: 503 naming the dependency (never a generic 500).
  3. Safe replay? Yes; nothing was charged.
  4. Steps: set the secret (wrangler secret put), redeploy, re-run /health.
  5. Verify: /health 200 and a single source fetch succeeds.

RB-09 — Caps / quotas exhausted

  1. Find: cap.reached with kind, or SCRAPER_BUDGET_EXHAUSTED (402, uncharged).
  2. User sees: "cap reached" or "source budget spent".
  3. Replay? Not until the UTC window resets. Do not raise a cap to "fix" one user.
  4. 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.
  5. Verify: next-day ledger window opens; cap.reserved succeeds.

RB-10 — Auth failures

  1. Find: auth.rejected with reason; AUTH_OWNER_MISSING ⇒ session valid, account row absent (this is a data/identity bug, not a login bug).
  2. Steps: re-authenticate; if OWNER_MISSING persists, check auth/ensure created the user row and that owner_id matches across tables.
  3. Never: trust a client-supplied x-request-id or owner_id to fix this.
  4. Verify: /api/v1/account returns the owner's row.

RB-11 — D1 batch failed / partial write

  1. Find: D1_BATCH_FAILED / D1_CONSTRAINT / D1_STATEMENT_LIMIT, with stmts and source_id.
  2. 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 on canonical_url and (source_id, source_job_id).
  3. Steps: re-run the source task (new attempt); never DELETE corpus rows to "clean up".
  4. 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.
  5. Verify: the same source ingest reports created + updated == stored.

RB-12 — 5xx storm / forged messages

  1. Find: http.request.failed grouped by err_code; queue.forged for HMAC failures (a forged message is acked, never retried).
  2. Steps: if forged messages appear, rotate QUEUE_HMAC_KEY and redeploy producer and consumer together; investigate who can write to the queue.
  3. Verify: queue.forged rate returns to 0; queue depth drains.

RB-13 — R2 object missing / upload interrupted

  1. Find: R2_OBJECT_MISSING on download; row references a key.
  2. 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.
  3. Verify: download succeeds; r2.get logs 200 with bytes.

RB-14 — Erasure incomplete

  1. Find: ERASURE_INCOMPLETE; the erasure phase set is derived from ops_table_policy.
  2. Steps: re-run the prefix sweep until a pass returns zero objects (by design), then delete rows. Never reverse the order.
  3. Verify: empty listing + zero rows for the owner across the phase set; record the completion in ops_audit_events.

RB-15 — AI provider failure

  1. Find: AI_PROVIDER_TIMEOUT / AI_RATE_LIMITED / AI_MALFORMED_RESPONSE.
  2. Safe replay? Yes, past a successful budget reservation; ranking produces drafts, never external effects.
  3. Steps: check provider config, budget window; fall back to keyword ranking (existing fallback) rather than blocking the page.
  4. Verify: /jobs/ranked/ai returns provider groq-match (or the configured provider).

RB-16 — Gmail uncertain send

  1. Find: email.send.outcome = uncertain; draft status unknown.
  2. User sees: "unconfirmed — check your sent mail" with the two-step confirm.
  3. Never auto-retry. The provider may have accepted it.
  4. Steps: owner confirms "It went out" (sent_unrecorded semantics) or "It did not" (resolveSend), then the cap slot is handled per the existing ledger rules.
  5. Verify: exactly one outbound emailEvents row for the draft.

RB-17 — Retention sweep not running

  1. Find: no retention.run for 2 intervals; expiredCount query returns rows.
  2. Impact: expired jobs are still filtered by reads (design), so this is correctness-safe but growth-unsafe.
  3. Steps: run the sweep manually via wrangler dev/scheduled trigger; check the cron binding and scheduled() deployment.
  4. Verify: SELECT count(*) FROM corpus_jobs WHERE expires_at <= now → 0.

RB-18 — Logpush gap

  1. Find: the daily partition check (expected env/dt=/svc prefixes) missing for a day.
  2. 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.
  3. Verify: partition exists and line counts are within the expected band (sampling accounted for).

On this page