Repository navigation
Description
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):
- 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.
- 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.
- NLM MeSH validation API (Stage 2b) — external HTTP call from inside the enrichment handler; if NLM is slow, the inner handler blocks.
- 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: 522Suggested investigation
npx cfman wrangler --account neuromechanist tail -c backend/wrangler.tomlwhile runningnemar admin reindex on005262. Look at the inner/webhooks/llm-enrichinvocation: does it complete, throw, or timeout?- Verify
OPENROUTER_API_KEYis set on prod:npx cfman wrangler --account neuromechanist secret list -c backend/wrangler.toml | grep OPENROUTER. - If OpenRouter latency: consider Stage 2b (MeSH validation) being run in parallel with Stage 2a (LLM extraction) instead of serial.
- 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 on005262producesenrich:ok sync:skipped cols:written(notenrich:failed).- Bulk reindex of 228 datasets has >90% enrichment success rate.
data.nemar.org/<id>/metadata.jsonreturns LLM-extracteddescription,keywords(MeSH),methodsfor on* datasets.
Related
- Issue OpenNeuro import path doesn't backfill modalities, tasks, subject_count into the D1 catalog #512 (closed) — fixed the D1 metadata-columns gap. The enrichment path is independent and separately broken.
- Epic S3 dataset/ prefix: tool-agnostic cloud-like access to NEMAR datasets #449 (closed) — introduced the metadata.json endpoint that consumes this enrichment data.
backend/src/services/llm-enrich.tsandbackend/src/routes/webhooks.ts(the/webhooks/llm-enrichhandler).
Activity
Fix enrichment 522: point API_BASE_URL at workers.dev for self-fetch (#…
Merge pull request #525 from nemarOrg/dev
Merge pull request #527 from nemarOrg/fix/issue-523-extract-enrich-pi…