Skip to content

Global enrichment failure: /admin/reindex returns HTTP 522 from Worker self-call #523

Closed

Description

@neuromechanist

Surfaced during the 228-dataset bulk reindex run after v0.8.18 deployed (epic #514 / Phase 2 follow-through).

Symptom

POST /admin/datasets/<id>/reindex returns enrichment: HTTP 522: error code: 522 for every single dataset attempted (0/228 succeeded enrichment in the bulk run, including a single-dataset retry on on005262).

Reindex loop summary:

  • 228 datasets total
  • 0 OK (= enrichment succeeded)
  • 161 WARN (= cols written, enrichment failed)
  • 67 FAIL (= entire reindex request failed at CLI level)

D1 metadata columns DID get written for the 161 WARN cases (the #512 fix is operational). Only the LLM enrichment is broken.

What 522 means here

runEnrichmentForDataset in backend/src/services/dataset-reindex.ts does a Worker self-call:

const res = await fetch(`${env.API_BASE_URL}/webhooks/llm-enrich`, { method: "POST", ... });

HTTP 522 = "Cloudflare cannot connect to origin within the connection timeout (~15s)". Since the origin IS this same Worker, the inner enrichment Worker invocation isn't responding to the outer Worker's fetch within the deadline.

Likely causes (need diagnosis):

  1. OpenRouter latency — Claude Haiku 4.5 call inside the enrichment handler is slow enough that the inner Worker exceeds the 30s wall-clock, returns 5xx, and the outer fetch sees 522.
  2. Subrequest amplification — the enrichment handler issues many GitHub API calls (tree fetch + N blob reads + commit) + the OpenRouter call. Cumulative time can exceed the budget.
  3. NLM MeSH validation API (Stage 2b) — external HTTP call from inside the enrichment handler; if NLM is slow, the inner handler blocks.
  4. OpenRouter API key/quota — if the key is missing/expired/over quota in prod, the call would 5xx the inner handler quickly. Verify via Cloudflare logs.

How to reproduce

nemar admin reindex on005262
# Output: enrichment: HTTP 522: error code: 522

Suggested investigation

  1. npx cfman wrangler --account neuromechanist tail -c backend/wrangler.toml while running nemar admin reindex on005262. Look at the inner /webhooks/llm-enrich invocation: does it complete, throw, or timeout?
  2. Verify OPENROUTER_API_KEY is set on prod: npx cfman wrangler --account neuromechanist secret list -c backend/wrangler.toml | grep OPENROUTER.
  3. If OpenRouter latency: consider Stage 2b (MeSH validation) being run in parallel with Stage 2a (LLM extraction) instead of serial.
  4. Consider Workers paid: 50s CPU time, 30s wall clock — if the LLM call alone is >30s wall, the architecture needs reshaping (e.g., enqueue to a Cloudflare Queue, process async, write result back).

Acceptance

  • nemar admin reindex on005262 produces enrich:ok sync:skipped cols:written (not enrich:failed).
  • Bulk reindex of 228 datasets has >90% enrichment success rate.
  • data.nemar.org/<id>/metadata.json returns LLM-extracted description, keywords (MeSH), methods for on* datasets.

Related

Activity

  1. added
    bug
    P1
    on May 16, 2026
  2. added 3 commits that reference this issue on May 16, 2026
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

    P1bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions