Skip to content

fix(admin): probe summary.json directly from S3 (not via self-Worker) - #630

Merged
neuromechanist merged 2 commits into
devfrom
fix/coverage-direct-s3
May 27, 2026
Merged

neuromechanist merged 2 commits into
devfrom
fix/coverage-direct-s3

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Symptom (observed live on prod)

First post-deploy smoke of GET /admin/summary/coverage returned 130 versions, all kind: error, status: 522 (Cloudflare "origin connection timed out"). Direct curl to the same data.nemar.org/<id>/<v>/summary.json URL from outside returned 200 in ~730 ms. The 522 only fires when the call originates inside the Worker.

Root cause

probeSummary used globalThis.fetch against data.nemar.org/<id>/<v>/summary.json. That URL is served by the same Worker that hosts /admin/summary/coverage. Fanning out 8 concurrent × 130 ids triggers Cloudflare Worker-to-Worker subrequest behavior that 522s under load.

The cross-component code-reviewer flagged this back on PR #623 as "option c" (the cleaner alternative to the cache-bust fix we shipped at the time). The bill came due on first prod run.

Fix

Refactor probeSummary to read S3 directly via loadSummary() — same code path Phase 3's page-bundle service uses for its summary fan-in. Bypasses CF + the self-call entirely, so no subrequest limit and no 24 h s-maxage to cache-bust around.

Wiring:

  • New SummaryFetcher type + defaultSummaryFetcher(env) builder.
  • Dependency-inject the fetcher into probeSummary and buildCoverageReport.
  • Tests stub the fetcher directly instead of swapping globalThis.fetch.

Test plan

  • 11 unit tests pass (bun test test/manifest-coverage.unit.test.ts)
    • schema ok / stale / forward-compat 1.2 / forward-compat 2.0
    • missing (fetcher returns null)
    • error (fetcher throws, JSON parse fail, empty schema_version, missing key, non-string schema)
    • fetcher-args wire contract pin
  • Backend typecheck clean
  • Post-deploy: re-run /admin/summary/coverage; expect 0 errors, ~130 stale (every existing summary is still schema 1.0 until backfill runs)
  • Then run the staged backfill (--match on* first, then --match nm*)

Why ship as a follow-up not a fixup amend

#628 already merged + tagged + npm-published as v0.8.35. Amending isn't possible; this is genuinely a follow-up release.

Discovered on first post-deploy smoke of /admin/summary/coverage: all 130
published versions classified as kind: error, status: 522 (Cloudflare
'origin connection timed out'). Direct curl to the same
data.nemar.org/<id>/<v>/summary.json URL from outside returned 200 in
~730ms. The 522 only happens when the call originates inside the Worker.

Root cause: probeSummary used globalThis.fetch against
data.nemar.org/<id>/<v>/summary.json, but that URL is served by the SAME
Worker that hosts /admin/summary/coverage. Fanning out 8 concurrent ×
130 ids triggers Worker-to-Worker subrequest behavior that 522s under
load. Cross-component code-reviewer flagged this as 'option c' on PR
#623 (the cleaner alternative to the cache-bust fix we shipped at the
time); the bill came due on first prod run.

Fix: refactor probeSummary to read S3 directly via loadSummary() — the
same code path Phase 3's page-bundle service uses for its summary fan-in.
Bypasses CF + the self-call entirely, so no subrequest limit and no
24h s-maxage to cache-bust around.

Wiring: introduce SummaryFetcher type + defaultSummaryFetcher(env)
builder, and dependency-inject the fetcher into probeSummary /
buildCoverageReport. Tests stub the fetcher directly instead of swapping
globalThis.fetch.

Tests: 11 unit tests cover the schema classifier (ok / stale /
forward-compat 1.2 / forward-compat 2.0 / missing / error / malformed
JSON / empty schema_version / missing key / non-string schema /
fetcher-args wire contract). Backend typecheck clean.
@github-actions

github-actions Bot commented May 27, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR630

Version: 0.8.36-PR630.df796d5
Commit: df796d5


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

3-agent review complete.

Fixed inline:

  • silent-failure HIGH — hang protection: `probeSummary` now wraps the fetcher in `Promise.race(setTimeout(8000))`. A slow-loris S3 edge can no longer occupy a worker slot for the full ~30s platform cap. The orphaned fetch still runs to completion in the background (loadSummary takes no AbortSignal today); follow-up Refactor: extract shared s3OptionsFromEnv helper #633 tracks pushing the signal through to actually cancel the fetch.
  • code-reviewer 82% — default-arg evaluation moved into the function body (`fetcher = fetchSummary ?? defaultSummaryFetcher(env)`) so test paths don't allocate a production fetcher.
  • code-reviewer — comment note on v-prefix normalisation moving to loadSummary, added to the existing fetcher-args test docstring.
  • pr-test-analyzer severity 7 — `probeAll` order-preservation test: 4 fetchers with reverse delays; assert `out[i].dataset_id === rows[i].dataset_id`. Catches the load-bearing index-assignment-not-push contract.
  • pr-test-analyzer severity 6 — `buildCoverageReport` totals tally test: scripted mix of ok/stale/missing/error across 5 rows; assert `totals` object. Catches typo-class bugs (`ok++` vs `stale++`).
  • New unit test for the timeout race itself: hanging fetcher → state.kind=error with `message.includes("timeout")`, elapsed between 7–8.5s.

Deferred follow-ups (real but not hotfix-blocking; documented for next iteration):

Tests: 14/14 pass (was 11 → +3). Backend typecheck clean. CI pending on push.

@neuromechanist
neuromechanist merged commit c7bdc91 into dev May 27, 2026
10 checks passed
@neuromechanist
neuromechanist deleted the fix/coverage-direct-s3 branch May 27, 2026 01:39

This branch was previously deployed

1 inactive deployment
npm — df796d57 Deployed May 27, 2026 by neuromechanist via publish #1172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant