Repository navigation
Fix #523: point API_BASE_URL at workers.dev to allow self-fetch - #524
Merged
Merged
Conversation
…523) Cloudflare Workers reject fetch() calls to the Worker's own custom-domain hostname (the API_BASE_URL self-fetch in runEnrichmentForDataset surfaced as instant HTTP 522 in 0.3s, not a true edge timeout). Switching API_BASE_URL on the SCCN prod config from https://api.nemar.org to the workers.dev fallback https://nemar-api.sccn-org.workers.dev fixes the self-fetch path without code changes. Both URLs hit the same Worker code. Root-caused while running 'nemar admin reindex --all' post-v0.8.18 deploy: 51/51 on* datasets reported enrich:failed with the same HTTP 522 0.3s pattern. Service-binding refactor is the proper long-term fix — tracked separately in #523.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR524Version: 🤖 Updated on each push. |
4 of 8 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #523.
Root cause
runEnrichmentForDatasetinbackend/src/services/dataset-reindex.tsdoes a Worker self-fetch:```ts
const res = await fetch(`${env.API_BASE_URL.replace(/\/$/, "")}/webhooks/llm-enrich`, { method: "POST", ... });
```
On the SCCN prod config, `API_BASE_URL = "https://api.nemar.org"\` — the Worker's own custom-domain hostname. Cloudflare Workers reject fetch() calls to the Worker's own custom domain (returns instant 522, NOT a true edge timeout). The `*.workers.dev` URL for the same Worker is allowed.
Diagnostic evidence (curl against prod admin reindex with skip_sync=true):
```
{"dataset_id":"on005262","enrichment":{"status":"failed","ref":"main","error":"HTTP 522: error code: 522"},"sync":{"status":"skipped"}}
HTTP=200 time=0.295683s
```
The 0.3s response time is the smoking gun — a real Cloudflare 522 (origin connection timeout) takes the full 15s connect_timeout.
Fix
One-line config change: `API_BASE_URL` in `backend/wrangler-sccn.toml` from `https://api.nemar.org\` to `https://nemar-api.sccn-org.workers.dev\`. Both URLs route to the same Worker; only the workers.dev path is whitelisted for self-fetch.
The legacy `backend/wrangler.toml` is unchanged (it deploys to api.osc.earth/nemar in maintenance mode and doesn't need self-fetch).
Verification plan
After deploy:
Follow-up
The proper long-term fix is a service binding ( `[[services]] binding = SELF` + `env.SELF.fetch()` instead of HTTP round-trip). Tracked in #523 — service binding eliminates the HTTP round-trip entirely (lower latency + lower subrequest cost). This PR is the tactical unblock.