Repository navigation
fix(server): lift the 2,000-doc ceiling on the atlas sitemap read - #126
Conversation
`getAtlasSitemapUrls` walked both atlas collections at SITEMAP_READ_LIMIT x SITEMAP_MAX_PAGES = 2,000 documents each and only then filtered to this origin. The ceiling therefore counted documents this site never publishes, so growth anywhere in the atlas truncated this site's half of the sitemap, silently and with no marker in the response. SahajCloud's bulk event import by country (sydevs/SahajCloud#828) is expected to clear 2,000 events on its own. Read `GET /api/atlas/sitemap` instead. It answers with the URLs the calling API key's client owns, resolved by the nearest-ancestor ownership walk that already exists upstream, so this Worker stops fetching documents to discard them. Two paginated reads of up to four pages each become one request, and `loc` is the document's own `webUrl` - the same field `/api/atlas/seo` returns as `canonical`, so a sitemap entry and that page's canonical cannot disagree. The origin check stays, demoted from the selection to a guard: it holds the sitemap to the host actually serving the request. A response that carries URLs but loses every one to that guard now reports to Sentry, because in the sitemap it is indistinguishable from a client that owns no subtree. Fixes #123 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HyFWu1gSKszyuZXgUt9dSr
The custom-endpoint section named only `/api/atlas/seo` and the `related-*` readers, so nothing in the guide said where the atlas half of the sitemap comes from now, or that its answer varies per API key. Two contract points a reader cannot get from the code: the endpoint resolves ownership upstream, so reverting to collection reads plus a local filter reintroduces #123; and an empty `urls` list is a client that owns no subtree, never a failure to report. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HyFWu1gSKszyuZXgUt9dSr
Three problems the review surfaced in the endpoint read. A non-OK response threw a plain Error, so `detectErrorType` had only the message to go on and its fallback matches `50[0-9]`. The SDK read this replaced carried `response.status`, which classifies any status at or above 500 as retryable. A Cloudflare-origin 5xx — 520, 522, 524, the shape a Railway restart produces — therefore lost the retry it most needs, and the sitemap shipped without its atlas half for an hour of cache. The status now rides on the error. A 200 whose body lost its `urls` array fell back to an empty list, which is indistinguishable from a client that owns no subtree: no warning, no Sentry event, no test. These types are hand-mirrored, so an upstream rename compiles and passes. It now throws into the existing degrade path. Dropping the page ceiling left nothing bounding the read, and the document breaches the sitemap spec's 50,000-URL limit before the Worker runs out of memory — a rejected document being worse than the truncated tail #123 complained about. Capped at 45,000, leaving the content half its room, and a truncation reports rather than passing unnoticed. Also trims the function's JSDoc to what the code does not already say, corrects the file header's endpoint count, and drops a cross-reference in sitemap-routes.ts that pointed at the deleted ceiling. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HyFWu1gSKszyuZXgUt9dSr
Deploying wemeditate-design with
|
| Latest commit: |
274bafd
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c3159d23.wm-design.pages.dev |
| Branch Preview URL: | https://claude-fix-123-atlas-sitemap.wm-design.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | 274bafd | Commit Preview URL Branch Preview URL |
Sep 21 2026, 11:00 PM |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
Commit 1 is exactly the ticket, and a net deletion: 142 lines of pagination for one scoped read.
Commit 3 is where the diff outgrew the problem. It caps at 45,000 URLs against a ~1,250-document corpus, on a read whose own type doc says bounding is upstream's call.
Nothing has run this code against a real response. Answer that first.
Findings
blocker— never exercised end to end, and the PR's own verification step cannot run (:143)should-fix—SITEMAP_URL_CAPbounds nothing the Worker does (:118)should-fix—getAtlasSeostill throws status-less, the defect commit 3 fixes below it (:89)consider— the newAGENTS.mdparagraph narrates the removed system
What was checked
Read whole: atlas-client.ts, atlas-types.ts, sitemap-routes.ts, sitemap.ts, error-utils.ts, both specs. Consumer side: SahajCloud atlas/sitemap/{index,sitemapUrls}.ts, responseTypes.ts:191-237. Ran curl <preview>/sitemap.xml — empty <urlset>. detectErrorType: 403 skips the retry ladder, 520 retries.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`detectErrorType` reads a status structurally and falls back to matching `50[0-9]` in the message. A Cloudflare-origin 520, 522 or 524 therefore classified UNKNOWN and skipped the retry ladder — confirmed by reverting the fix, which drops the new spec to `expected 'UNKNOWN' to be 'SERVER'`. Same one-line change already applied to `getAtlasSitemapUrls` 65 lines below, in the file this branch was already editing. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QzeM7Sjyd5S2TQ4wa63Yb9
The cap's doc and its spec both claimed it kept one Worker request bounded. It cannot: `response.json()` materialises every row before `.slice()` runs. What it does bound is the emitted document, against the sitemap spec's 50,000-URL per-file limit. The cap itself stays. Without it an atlas past 50,000 owned URLs emits an invalid sitemap silently, which is the failure mode #123 is about. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QzeM7Sjyd5S2TQ4wa63Yb9
The AGENTS.md paragraph is re-read every session, and its middle clause described the system this branch deletes. The rule survives without it, and the #123 breadcrumb stays. The same "no longer" narration on the `getAtlasSitemapUrls` doc is reworded to describe the code as it is. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QzeM7Sjyd5S2TQ4wa63Yb9
|
The blocker is answered, and the answer changes the PR. Adopted, resolved
Half adopted, left open
Gate: lint, types, 720 tests, build. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#126 added a second custom root endpoint, `GET /api/atlas/sitemap`, to the file this branch was converting to the shared read path. - `server/atlas-client.ts` — `getAtlasSeo` keeps this branch's `sahajCloudFetchOptional` read. #126 changed only the shape of the error it throws, and `SahajCloudResponseError` already carries `status`, so the 52x retry both sides wanted survives. `getAtlasSitemapUrls` stays on its own `fetch`, unconverted, as the PR body says. It still calls `getCmsContext()`, so that import comes back — the import block auto-merged to this branch's and dropped it. - `server/atlas-client.test.ts` — both sides grew a capture for the error the retry ladder was handed. Kept `thrownSpy`, and pointed the 522 spec at it. Dropped `find.mockReset()`: `find` mocked the SDK read #126 replaced, and nothing declares it any more. Deduped an import both sides added. - `server/AGENTS.md` — the shared-helper paragraph now names the sitemap endpoint as the one read still assembling its own `fetch`. #126's ownership warning kept verbatim. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CKDSUZUoYyX87AFr7wFDiX
Summary
/sitemap.xmlis now read fromGET /api/atlas/sitemap, which is scoped upstream to the URLs this API key's client owns.⚠ Read this before merging
The endpoint was run against production during review. It answers 200 with
{"generated":"…","urls":[]}— the We Meditate client owns no atlas subtree today, so this PR lists zero atlas URLs.That is not a regression. Every
webUrlinregions(646 docs) andevents(453 docs) is onwemeditate-web.contact-c66.workers.dev, so the old origin filter onhttps://wemeditate.comalso matched zero. Both implementations emit an empty atlas section on the only host where the sitemap is served at all.AC 1 of #123 cannot be demonstrated until SahajCloud declares this client's owned subtrees. Merging is still a strict improvement — the ceiling is gone and the read is one request — but the sitemap will not gain atlas URLs on merge.
Changes
server/atlas-client.ts—getAtlasSitemapUrlsfetches the scoped endpoint;SITEMAP_READ_LIMIT,SITEMAP_MAX_PAGES,SITEMAP_SELECTSandreadAllPagesare gone. NewSITEMAP_URL_CAP.getAtlasSeonow throws with its status attached.server/atlas-types.ts— hand-mirroredAtlasSitemapUrl/AtlasSitemapResponse.server/AGENTS.md— records that the read is client-scoped, and that an empty list is an answer.server/sitemap-routes.ts— comment only: a cross-reference to the deleted ceiling.Preview
/sitemap.xmlthere is an empty<urlset>by design:isIndexableHostrejects*.workers.devbefore either read runs (sitemap-routes.ts:183).Test results
tsc --noEmit+test:run(720 passed)server/atlas-client.test.ts+server/sitemap-routes.test.ts, 42 passedpnpm buildManual verification
Done, against production, not the preview:
The response shape matches the hand-mirrored type, and the call is not refused — the production key holds the
sahaj-atlas-clientrole. See the ⚠ section above for what the empty list means.Notes for reviewer
/api/atlas/sitemap(#650) and on that repo's ownership config. Previously it depended only on theregions/eventscollections.starts_with(path, "/api/")+Authorizationpresent, per itsDEPLOYMENT.md), and the endpoint stamps its own headers viapublicReadCacheHeaders.response.json()has already materialised every row when it applies. Say the word if you want the index built here instead.server/AGENTS.mdrequires a dropped reference to be visible, Sentry groups repeats, and the pre-existing failure capture in this same function repeats identically.atlas-client.ts,cms-client.tsandcontent-index.ts, and one copy has already drifted (no[PayloadCMS]log line). Pre-existing and out of this ticket's scope.Detail
Why the origin filter stayed. It is no longer the selection — upstream resolves ownership — but it still holds the sitemap to the host serving the request, so a key whose client canonicalizes elsewhere cannot publish that site's URLs under ours. A reviewer flagged that it may be dead in practice today, since
/sitemap.xmlshort-circuits onisIndexableHostbefore this read and every currently reachable host is non-indexable. Kept anyway: two lines guarding a silent, high-blast-radius SEO failure.Known limitation of that guard. It is a byte-prefix test against
origin. If the Worker is ever served onwww.wemeditate.comwhile the client canonicalizes to the apex, every row drops and the Sentry warning misdiagnoses it as a misconfigured key. Thesampleextra in the event makes that diagnosable. Not addressed here because the production route config could not be confirmed from the repo.Four defects review caught and this branch fixes. Three were introduced by the rewrite: a status-less thrown error that cost Cloudflare-origin 5xx (520/522/524) their retry; a drifted response body collapsing to an empty list with no telemetry; and the removed page ceiling leaving nothing bounding the document against the sitemap spec's 50,000-URL limit. The fourth is pre-existing and one line in the same file:
getAtlasSeothrew status-less the same way. Confirmed by reverting the fix, which drops the new spec toexpected 'UNKNOWN' to be 'SERVER'.Fixture pre-mortem. The fixtures assume the response is
{ generated, urls: [{ loc, lastmod, route }] }, withlocabsolute and carrying the client's/mapmount, and every row having alastmod. Verified againstsrc/endpoints/responseTypes.ts(lines 193–237) andsrc/endpoints/atlas/sitemap/sitemapUrls.tsin the SahajCloud checkout —sitemapUrls()drops any document missingwebUrl,webPathorupdatedAt, which is whylastmodis typed non-null. The live 200 confirms the envelope keys; the row shape is still fixture-only, since the live list is empty.Auth is unchanged in shape. The endpoint runs the same
requireActiveClient+assertClientOriginAllowedgates as/api/atlas/seo, which this Worker already calls successfully in production. A server-to-server call with noOriginheader is explicitly allowed, and the live 200 above is that call.Closes #123
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01QzeM7Sjyd5S2TQ4wa63Yb9