Skip to content

fix(worker): a request of one reader never meets the HTML cache or the last good renders - #74

Merged
wojciechszyjka merged 2 commits into
mainfrom
fix/wp10-cache-private-requests
Nov 30, 2026
Merged

wojciechszyjka merged 2 commits into
mainfrom
fix/wp10-cache-private-requests

Conversation

@wojciechszyjka

@wojciechszyjka wojciechszyjka commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes a regression of WP10 (#69) that WP11's harness found. In the HTML cache of src/worker/editorial-cache.ts, a request carrying EmDash's edit-mode cookie was answered before src/outer-middleware.ts ran. A cached /crm then went to that request with public, max-age=0, must-revalidate and without Set-Cookie: emdash-edit-mode=deleted, while a cold page answers private, no-store and clears the cookie (WP01's rule, decision D6a).

Change

privateRequest() names the requests that belong to one reader. editorialApp() passes such a request straight to the site: no read of the generations, no cache hit, nothing stored, no kept render removed. The request then gets exactly the cold path. The set:

  • the edit-mode cookie emdash-edit-mode (WP01; dropped and cleared outside /_emdash by the outer middleware);
  • every query src/route-policy.ts refuses: _preview, _edit, /_image, the OAuth metadata (their 404);
  • WP09's Access assertion header Cf-Access-Jwt-Assertion and the CF_Authorization cookie;
  • Astro's session cookie astro-session (a signed-in editor);
  • an Authorization header (already excluded before).

The same order problem also hit two other paths. Both are fixed by the same check:

  • Last good fallback. In an outage, an edit-mode request got the kept public page with no-store but without the cleared cookie. It now gets the cold 503, which clears the cookie.
  • Refused queries. A refused /crm?_edit=1 answered 404, and that 404 removed the kept render of /crm, so anyone could empty the outage fallback of any page.

The og card route (/og/<slug>.png) goes through the same editorialApp(), so the same check covers it. Its og crop runs inside the cold path.

Verification

  • test/worker/publish/cache-private.test.ts: 14 cases (the review added an og card row, an overwrite-proof check of the kept and cached objects, and a check that the Worker config keeps Astro's session cookie name). On 322a252 with a stub privateRequest, 13 fail on assertions, for example expected 'hit' to be null and, in the outage case, expected [ 200, null ] to deeply equal [ 503, ... ]. The 14th, the config check, passes there too, as it should. On this head all 14 pass.
  • yarn check: passes. npx vitest run test/worker: 379 passed.
  • Built Worker on a fresh local D1 filled by yarn om emdash-import:
    • The repro: GET /crm answers miss, then hit. Then GET /crm with Cookie: emdash-edit-mode=true answers 200, private, no-store, Set-Cookie: emdash-edit-mode=deleted, with no X-OM-Cache, the same as a cold page.
    • /crm?_edit=1 answers 404.
    • test/worker/publish/admin-d1.ts: 35 checks, then the outage phase, all pass. The run used the same local, uncommitted Access key source as for feat(worker): the publish guard, the D1 invariants and the cache (WP10) #69.
    • WP11's test/worker/smoke.ts (from feat/wp11-worker-harness): 37 checks, all pass.
    • The test/worker/smoke.ts on main still expects the WP04 shell: placeholder home, admin 302, older route list. It fails 5 checks that are unrelated to this change; WP11 updates it.

@wojciechszyjka wojciechszyjka left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Code review: om-auto-review-pr (head a92fc9a)

Verdict: approve-ready. Posted as a comment, because GitHub does not let the author approve their own PR.

An independent review pass found 0 blockers, 0 majors, 2 minors and 3 nits. All five are fixed in a92fc9a.

Minors

  • The "stores or removes nothing" check compared keys only, so it missed an overwrite under the same key. On 322a252 the Authorization row passed for that reason. The check now compares the stored objects, and that row fails on 322a252.
  • astro-session is Astro's default session cookie name. A test now fails if astro.worker.config.ts sets session.cookie.

Nits

  • Removed dead read code: every non-read request already returns early.
  • The fake cold path now matches cookie names exactly.
  • Added an og card row, /og/crm.png?_preview=.... It fails on 322a252 because the refused query removed the kept card.

Validation

  • yarn check: pass.
  • npx vitest run test/worker: 379 passed.
  • Built Worker on a fresh local D1, run on e34e74c. The review fixes after it change only the dead read code and the tests.
    • admin-d1.ts: 35 checks and the outage phase pass.
    • WP11's smoke check: 37 of 37 pass.
    • The repro answers as a cold page.

CI is pending at this head. This comment does not wait for it.

@wojciechszyjka
wojciechszyjka merged commit a023276 into main Nov 30, 2026
5 checks passed
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