Skip to content

fix(server): report a failed read once per cause, stop caching what it emptied, list the whole sitemap - #305

Merged
sydevs-bot merged 10 commits into
mainfrom
claude/fix-server-degrade-reporting
Nov 19, 2026
Merged

sydevs-bot merged 10 commits into
mainfrom
claude/fix-server-degrade-reporting

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Visitors. A related-content section emptied by a failed SahajCloud read is no longer cached. Before this change, browsers and the CDN kept the empty section for up to 30 minutes after SahajCloud recovered. An atlas page whose answer is missing its class listing or its breadcrumb trail now renders without that part instead of failing the server render.
  • Search engines. /sitemap.xml reads each content collection a page at a time, so it is no longer cut off silently at 500 documents per collection. The walk stays inside the 5,000 URLs the atlas half leaves free under the 50,000-URL limit for one sitemap file.
  • Developers / Sentry. A read that fails on every attempt sends one event, and each retried attempt is a breadcrumb on that event (it used to send one event per attempt plus one for the final failure). Reads the page can do without (songs, related content, the atlas body, both sitemap halves) go through one helper, degrade in server/error-utils.ts. It logs every failure, reports it once per key and kind of failure per isolate, and returns the fallback. warnOnce keeps a separate memo per source, so a noisy source cannot re-arm another source's warning. A failing atlas route is reported once per kind of failure, not once per crawled URL.

Findings addressed

  • F9d — On main, withRetry sent a warning event for each retried attempt (server/error-utils.ts:175) and an error event for the final failure (:194), and each degrading caller then reported again. Retried attempts are now Sentry.addBreadcrumb entries. The new RetryConfig.reportFailure option (default true) lets a degraded read leave the report to degrade. Reads that propagate their failure still report it at error. Tests: server/error-utils.test.ts › withRetry reporting (3 tests, all fail on main).

  • F15b — Adds degrade and warnOnce beside withRetry. These reads now go through them: getMeditationSongs, getRelatedMeditations and getRelatedLectures (their duplicated filter is now isRenderableCard/readRelatedCards), getAtlasSeo, getAtlasSitemapUrls, and the sitemap's getContentSitemapUrls, which sent nothing to Sentry before. Each wraps withRetry(read, { reportFailure: false }).
    Review follow-ups in this PR:

    • The memo is now one bounded set per source. Before, a single shared 128-key set was emptied when full, which re-armed every other source.
    • degrade keys a report on key + error type + status.
    • degrade takes a separate subject for the log line. getAtlasSeo passes no key, because up to 45,000 routes would otherwise mean up to 45,000 events in a standing 403. The route goes in extra and in every log line.
    • forgetReportedWarnings() lets each test start from a fresh isolate.

    Tests: error-utils.test.ts › warnOnce/degrade, including 'lets one source fill its memo without re-arming another source' and 'reports a keyless failure once per kind…'. atlas-client.test.ts › 'reports a standing fault once per kind, however many routes a crawl asks for'. sahajcloud-client.test.ts › 'reports %s failing once per id per isolate…' (×3). sitemap-routes.test.ts › 'reports a lost content half to Sentry, once per origin per isolate'.

  • F9b — getLecture called captureMessage on every render of a clip whose parent is unresolved. Only the inside of the if (!options.preview && resolved.type === 'clip' && !resolved.hlsUrl) block changed: console.warn still runs on every render, and Sentry is reached through warnOnce keyed on the clip id. Test: sahajcloud-client.test.ts › getLecture › 'reports a clip with no HLS source once per isolate, and logs it every render' (fails on main).

  • F15h — On main, the related routes (server/api-routes.ts:271-317) sent public, max-age=300, stale-while-revalidate=1800 on an empty answer caused by a failure. getRelatedMeditations and getRelatedLectures now return null for a failure that survived the retries and [] for a real empty answer. relatedAnswer() sends no-store for null and when the route's own catch fires. Tests: new server/api-routes.related.test.ts (8 tests: happy path, invalid id, upstream 5xx, real-empty 404, failed config read). The 3 no-store tests fail on main.

  • F15g — On main, the sitemap read limit: 500 per collection with no hasNextPage check (server/sitemap-routes.ts:30). Live counts today: pages 66, meditations 121, lectures 163. page=2 and sort=id are accepted live (lectures: total 163, page 2, hasNextPage: false). readEvery() follows hasNextPage, sorts by id, and stops at 3 pages per collection: 3 × 3 × 500 = 4,500 URLs, inside the 5,000 that SITEMAP_URL_CAP (45,000) leaves free. At the cap it reports through warnOnce. The ceiling is marked as a shortcut: whose upgrade trigger is splitting into a sitemap index. Tests: sitemap-routes.test.ts › 'the content walk': 'lists a collection past one read, a page at a time', 'stops at its ceiling and reports the truncation…', and 'keeps the content half inside the room the atlas cap leaves in one file', which asserts ≤ 50_000 - SITEMAP_URL_CAP and fails with the previous 10-page ceiling.

  • F10e (AtlasContent half) — On main, pages/map/_components/AtlasContent.tsx read content.events.length (:166) and trail.length (:80) without guards. The listing now uses ?? [], as EventContent already does; the trail is guarded with !trail || trail.length < 2, which reads the same and allocates nothing. Tests: AtlasContent.test.tsx › 'renders the region without classes, rather than throwing, when the listing goes missing' and '…without a breadcrumb…'. Both throw on main.

  • Review follow-up, double report — getSiteAnnotation logs only, as it did on main. Its failure is getWebConfig's failure, and getWebConfig's own retry already reports it. Test: 'still lists the home page when the config read fails' now also asserts no warning from the sitemap.

  • Review follow-up, docs — docs/rules/rest-api.md now states the rule as it really applies: a failure throws unless the read can do without the data, and a fallback the caller must tell apart from an empty answer gets a distinct sentinel (null). server/AGENTS.md says a degrade key comes from a small set (an id, an origin) and never from the visitor's URL.

Not in this PR

  • getPageLocaleStatus (server/sahajcloud-client.ts, maxAttempts: 1 plus its own unbounded captureMessage) still reports on top of withRetry. It is the natural next caller of degrade, but it is outside this bundle's list.
  • server/content-index.ts (owned by feat(components): a MeditationLibrary for the meditations index block #293) and server/site-context.ts (the i18n bundle) are untouched. Both can move onto degrade/warnOnce once those land.
  • AtlasContent: only the two reads the finding cites are guarded. If the whole seo.content object went missing, the region, event and root renderers would still throw.
  • The sitemap still sends public, max-age=3600, stale-while-revalidate=86400 when a half fell back. This is pre-existing, and the fix is a follow-up: return a "degraded" flag from both halves and send no-store or a short max-age when either one fell back.
  • No translation keys are needed.

Reconciled with open PRs

Test results

Gate .claude/skills/pr-prep/check.sh at 0f3b767, with origin/main (41079b2) merged in:

  • Lint: 0 errors, 1086 warnings (main's baseline is 1087). None are on lines this PR writes.
  • tsc --noEmit: passed.
  • Vitest: 132 files, 1308 / 1308 tests passed.
  • pnpm build is not required for this bundle and was not rerun for the review follow-ups. It passed at 3c87a53.
  • Intermediate commit b9711f9 also passes tsc and server/ tests (256 / 256).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw

`withRetry` sent a Sentry event for every attempt it retried, at warning,
and another for the outcome. A read that failed three times cost three
events, and a caller that degraded the failure added a fourth. These reads
run per render and nothing caches them, so a standing upstream fault
billed the quota several times per page view.

Each retried attempt is now a breadcrumb. The outcome is still the one
event — the read that recovered, or the final failure — and it carries the
attempt history, so nothing an attempt event said is lost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
Background music, related content, the atlas body and both sitemap halves
each hand-rolled the same block: retry, catch, warn, capture, fall back.
Every copy captured on every failure, and `withRetry` captured the same
failure again underneath it. These reads run per render and nothing caches
them, so a standing upstream fault billed two events per page view per
read, which is the volume server/AGENTS.md says to bound.

`degrade` in error-utils.ts is that block once. It logs every failure and
reports it through `warnOnce`: one event per key per isolate, and again
when the failure changes kind, carrying the status and message the
suppressed `withRetry` event used to. The read inside still retries, and
passes `reportFailure: false` so this is the one report of its failure.

Routed through it: `getMeditationSongs`, `getRelatedMeditations`,
`getRelatedLectures` (whose identical card filter is now one predicate
and one read), `getAtlasSeo`, `getAtlasSitemapUrls`, and the sitemap's
config and content reads. The content half used to degrade with no
Sentry report at all. The other warnings in atlas-client.ts — a root with
no document, an off-origin or capped atlas sitemap — stand until someone
fixes upstream, so they go through `warnOnce` too.

`degrade` reports through `@sentry/react`, as `withRetry` already does,
because error-utils.ts also reaches the browser. Both SDKs re-export one
`@sentry/core`, so the tests share one `captureMessage` spy between them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
`getLecture` sent a Sentry warning on every render of a clip whose parent
lecture came back unpopulated. That gap stands until an editor publishes
or syncs the parent, so the warning billed one event per view of the
clip's page for as long as it stood.

It now goes through `warnOnce`, keyed on the clip: one event per clip per
isolate, with `console.warn` still on every render. Only the inside of the
unresolved-parent branch changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The related-content routes sent `public, max-age=300,
stale-while-revalidate=1800` on every 200, and the readers behind them
answered `[]` for a failure exactly as for an unknown id. So a SahajCloud
blip held an empty related section in browsers and the CDN for up to half
an hour after it recovered, and the route could not tell.

`getRelatedMeditations` and `getRelatedLectures` now degrade to `null`, and
keep `[]` for an answer that really is empty. `relatedAnswer` caches an
answer and sends `no-store` for `null`, as it does for a config read that
failed before the related read was made. The response body is unchanged:
an empty section is still `{ items: [] }`.

The routes had no tests. `api-routes.related.test.ts` covers both: the
cached answer, an invalid id that never reaches SahajCloud, and each
failure answering uncached. It sits beside `api-routes.test.ts` because
these routes read through `fetch` and the config global, where the
proxies there stub the SDK's `request`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The sitemap read 500 documents per collection and never asked whether
there were more, so a collection past 500 lost its newest documents from
`/sitemap.xml` with nothing to say so. Today's counts (66 pages, 121
meditations, 163 lectures) are under it; the cap was silent the day one
was not.

Each collection is now walked a page at a time until `hasNextPage` is
false. Each page is one subrequest, so the walk stops at ten pages per
collection and reports the truncation once per isolate rather than
running unbounded inside a Worker request. The reads sort by id, so a
document created mid-walk lands on the last page instead of shifting
every later page by one; SahajCloud accepts `sort` and `page` on these
reads (checked against the live API).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
`AtlasContent` read `content.events.length` and `breadcrumbs.length`
straight off the `/api/atlas/seo` answer. That shape is hand-mirrored in
`server/atlas-types.ts`, so a field upstream stops sending still compiles,
and either read then threw in SSR — a 500 on a route `+Page.tsx` wraps in
no boundary. The event page already read its own fields defensively; the
region listing and the breadcrumb did not.

A missing listing now renders the region with its "no classes" line, and
a missing trail renders no breadcrumb.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The warnOnce memo was one set shared by every source and emptied at 128
keys, and getAtlasSeo keyed its failures on the visitor's route. During a
standing atlas 403 or 5xx a crawl sent one event per route, and every 128
routes cleared the memo, which re-armed every other source's warning too.

Each source now keeps its own memo, so one source's churn re-arms only
itself. degrade signs a failure by key, error type and status, and takes
a separate `subject` for the log line, so getAtlasSeo passes no key: a
site-wide refusal is one event per kind, the route rides in `extra`, and
every render still logs the route it failed on.

forgetReportedWarnings() lets each test start from a fresh isolate, so
the atlas and sitemap cases go back to their natural routes and origins
instead of dodging keys an earlier test reported.

rest-api.md now says what the related reads do: a failure throws unless
the read can do without it, and a degrade fallback that a caller must
tell from an empty answer is a distinct sentinel (null).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
A sitemap file holds 50,000 URLs, and the atlas half may take 45,000 of
them (SITEMAP_URL_CAP), leaving 5,000 for content. The content walk
allowed 10 pages of 500 per collection, so up to 15,000 content URLs,
and the two halves together could pass the limit with nothing reported:
a crawler refuses an oversized file whole. Three pages per collection is
4,500 in all, and the truncation report still fires at the ceiling. A
test pins the content half under 50,000 - SITEMAP_URL_CAP.

getSiteAnnotation goes back to logging only. Its failure is getWebConfig's
failure, and getWebConfig's own retry already reports that, so a second
warning here spent two events on one cause.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 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 0f3b767 Commit Preview URL

Branch Preview URL
Nov 19 2026, 10:45 PM

Comment thread pages/map/_components/AtlasContent.tsx Resolved
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@sydevs-bot

sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 22:41Z address-review · attempt 1 · session · done
  • 22:41Z address-review · attempt 1 · session

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

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 19, 2026
`(trail ?? []).length` built a throwaway array on every render just to
read a length. `!trail || trail.length < 2` reads the same and allocates
nothing.

`trail && trail.length < 2` would invert the missing-trail case: the
guard goes false, `trail.map` runs, and the render throws. The
'trail goes missing' test in AtlasContent.test.tsx fails that way.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWySWAHJp4dWwhm9Ku
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Adopted — the breadcrumb guard, at 0f3b767, as !trail || trail.length < 2. The literal trail && trail.length < 2 inverts the missing case and throws; the failing test is quoted in the thread.

Base merged — origin/main (41079b2) merged in cleanly at 839a6de. #285, #290 and #292 are now behind this branch.

Gate at 0f3b767 — lint 0 errors, 1086 warnings (main's baseline 1087); tsc --noEmit clean; vitest 132 files, 1308 / 1308.

Security review skipped: this push's own change is under pages/map/, outside securityReview.triggerPattern.

Body refreshed: the F10e bullet, the reconciliation list, and the test results.

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


Generated by Claude Code

@cloudflare-workers-and-pages

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-design 0f3b767 Commit Preview URL

Branch Preview URL
Nov 19 2026, 10:45 PM

@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 19, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 19, 2026
Merged via the queue into main with commit 3588ccb Nov 19, 2026
30 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-server-degrade-reporting branch November 19, 2026 23:54
@sydevs-bot sydevs-bot moved this from Pending to Done in SYDevelopers Technical Roadmap Nov 19, 2026
sydevs-bot pushed a commit that referenced this pull request Nov 21, 2026
`server/AGENTS.md` names `warnOnce` as the volume bound for a new warning
on a read. It reached main with #305, after this branch's base, so the
memo here was a second implementation of it.

The dedup key, the per-render `console.warn` and the Sentry level are
unchanged. The cap moves from 64 gaps to `warnOnce`'s 128 per source.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYS6tjaST5e7ETsP68
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.

3 participants