Skip to content

fix(server): lift the 2,000-doc ceiling on the atlas sitemap read - #126

Merged
sydevs-bot merged 6 commits into
mainfrom
claude/fix-123-atlas-sitemap-scope
Sep 21, 2026
Merged

sydevs-bot merged 6 commits into
mainfrom
claude/fix-123-atlas-sitemap-scope

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The atlas half of /sitemap.xml is now read from GET /api/atlas/sitemap, which is scoped upstream to the URLs this API key's client owns.
  • Growth anywhere in the atlas no longer truncates this site's sitemap: the old ceiling counted documents we never publish.
  • One subrequest instead of up to eight, and three fewer sequential round trips on the route's critical path.

⚠ 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 webUrl in regions (646 docs) and events (453 docs) is on wemeditate-web.contact-c66.workers.dev, so the old origin filter on https://wemeditate.com also 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 — getAtlasSitemapUrls fetches the scoped endpoint; SITEMAP_READ_LIMIT, SITEMAP_MAX_PAGES, SITEMAP_SELECTS and readAllPages are gone. New SITEMAP_URL_CAP. getAtlasSeo now throws with its status attached.
  • server/atlas-types.ts — hand-mirrored AtlasSitemapUrl / 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

Test results

  • Lean gate: ✓ lint + tsc --noEmit + test:run (720 passed)
  • Targeted specs: server/atlas-client.test.ts + server/sitemap-routes.test.ts, 42 passed
  • Build: ✓ pnpm build

Manual verification

Done, against production, not the preview:

curl -H "Authorization: clients API-Key $KEY" https://cloud.sydevelopers.com/api/atlas/sitemap
→ 200  {"generated":"2026-09-21T22:55:31.032Z","urls":[]}

The response shape matches the hand-mirrored type, and the call is not refused — the production key holds the sahaj-atlas-client role. See the ⚠ section above for what the empty list means.

Notes for reviewer

  • The 2,500-event acceptance criterion is covered by fixtures, not by real data. The atlas holds 453 events today; SahajCloud#828 is what creates a larger one.
  • New runtime dependency. This route now depends on SahajCloud's /api/atlas/sitemap (#650) and on that repo's ownership config. Previously it depended only on the regions / events collections.
  • Edge caching checked, not assumed. SahajCloud's Cache Rule is origin-controlled (starts_with(path, "/api/") + Authorization present, per its DEPLOYMENT.md), and the endpoint stamps its own headers via publicReadCacheHeaders.
  • Judgement call: capped at 45,000 rather than building a sitemap index. The ticket offered the index as the fallback. The corpus is ~1,100 today, so the index is speculative; a cap plus a Sentry warning makes the crossing visible instead of silent. Review corrected what the cap is for: it bounds the emitted document against the sitemap spec's 50,000-URL per-file limit, not the Worker request — response.json() has already materialised every row when it applies. Say the word if you want the index built here instead.
  • Dismissed: a reviewer proposed cutting the off-origin Sentry warning as an alert that repeats and actions nothing. Kept — server/AGENTS.md requires a dropped reference to be visible, Sentry groups repeats, and the pre-existing failure capture in this same function repeats identically.
  • Not fixed here, filed instead: the custom-endpoint fetch preamble is now duplicated six times across atlas-client.ts, cms-client.ts and content-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.xml short-circuits on isIndexableHost before 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 on www.wemeditate.com while the client canonicalizes to the apex, every row drops and the Sentry warning misdiagnoses it as a misconfigured key. The sample extra 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: getAtlasSeo threw status-less the same way. Confirmed by reverting the fix, which drops the new spec to expected 'UNKNOWN' to be 'SERVER'.

Fixture pre-mortem. The fixtures assume the response is { generated, urls: [{ loc, lastmod, route }] }, with loc absolute and carrying the client's /map mount, and every row having a lastmod. Verified against src/endpoints/responseTypes.ts (lines 193–237) and src/endpoints/atlas/sitemap/sitemapUrls.ts in the SahajCloud checkout — sitemapUrls() drops any document missing webUrl, webPath or updatedAt, which is why lastmod is 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 + assertClientOriginAllowed gates as /api/atlas/seo, which this Worker already calls successfully in production. A server-to-server call with no Origin header 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

`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
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Deploying wemeditate-design with  Cloudflare Pages  Cloudflare Pages

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

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 21, 2026
@sydevs-bot

sydevs-bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 22:53Z address-review · attempt 1 · session · done
  • 22:53Z address-review · attempt 1 · session
  • 22:44Z adversarial-review · attempt 1 · session · done
  • 22:44Z adversarial-review · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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_CAP bounds nothing the Worker does (:118)
  • should-fix — getAtlasSeo still throws status-less, the defect commit 3 fixes below it (:89)
  • consider — the new AGENTS.md paragraph 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

Comment thread server/atlas-client.ts Resolved
Comment thread server/atlas-client.ts Resolved
Comment thread server/atlas-client.ts Resolved
Comment thread server/AGENTS.md Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 21, 2026
`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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

The blocker is answered, and the answer changes the PR. GET /api/atlas/sitemap was run against production: 200, urls: []. The key holds the role and the envelope matches. The client owns no subtree yet, so this branch lists zero atlas URLs — and so did the old code, every webUrl being on the workers.dev host. No regression, but AC 1 waits on upstream ownership config. Flagged in the body.

Adopted, resolved

Half adopted, left open

  • SITEMAP_URL_CAP bounds nothing → 7b52dc3. The Worker-bounding claim was false in doc and spec alike, and is gone. Kept the cap: it bounds the document against the sitemap spec's 50,000-URL limit.

Gate: lint, types, 720 tests, build.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 21, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 21, 2026 23:04
@sydevs-bot
sydevs-bot requested a review from Ardnived September 21, 2026 23:04
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 21, 2026
Merged via the queue into main with commit 8ba9dc8 Sep 21, 2026
38 of 44 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-123-atlas-sitemap-scope branch September 21, 2026 23:30
@sydevs-bot sydevs-bot moved this from Revising to Done in SYDevelopers Technical Roadmap Sep 21, 2026
sydevs-bot pushed a commit that referenced this pull request Sep 21, 2026
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(server): lift the 2,000-doc ceiling on the atlas sitemap read

3 participants