Skip to content

fix(cache): always treat zero-lifetime entries as stale - #5980

Merged
mcollina merged 3 commits into
mainfrom
fix/cache-max-age-0-same-ms
Oct 8, 2026
Merged

mcollina merged 3 commits into
mainfrom
fix/cache-max-age-0-same-ms

Conversation

@mcollina

@mcollina mcollina commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Fixes a flaky failure of stores response with max-age=0 and etag, revalidates it on reuse (e.g. https://github.com/nodejs/undici/actions/runs/37791061280/job/113358249444?pr=5979), which is a real bug rather than a test issue.

Responses stored with a zero freshness lifetime (e.g. max-age=0 with an etag) get staleAt === cachedAt. isStale() used now > result.staleAt, so a reuse within the same millisecond as the store (when the Date header contributes no apparent age), or after the clock stepped back, served the entry as fresh without revalidation.

isStale() now also treats staleAt <= cachedAt as stale. This only affects zero-lifetime entries; the existing millisecond boundary for other entries (covered by cache-revalidate-stale.js) is unchanged.

Added a deterministic regression test that freezes Date so both requests observe now === staleAt; it fails without the fix and passes with it.

mcollina and others added 2 commits October 8, 2026 16:03
Milo was vendored as lib/milo/{simd,no-simd}.js in #5954, but #5935
was written against the previous lib/milo/src/*/index.js layout, so the
'ordinary esbuild bundles retain experimental Milo' test fails on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xf8iHe9HroHgZuP6UXGZnx
Signed-off-by: Matteo Collina <hello@matteocollina.com>
The vendored Milo layout from #5954 has no binary/ or src/ directories.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xf8iHe9HroHgZuP6UXGZnx
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina requested review from metcoder95 and ronag October 8, 2026 14:34
Responses stored with a zero freshness lifetime (e.g. max-age=0 with an
etag) get staleAt === cachedAt. isStale() used `now > staleAt`, so a
reuse in the same millisecond as the store (or after the clock stepped
back) served the entry as fresh without revalidation. This made
'stores response with max-age=0 and etag, revalidates it on reuse'
flaky on CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xf8iHe9HroHgZuP6UXGZnx
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina force-pushed the fix/cache-max-age-0-same-ms branch from 340a0f1 to d76f50e Compare October 8, 2026 14:34
@mcollina
mcollina changed the base branch from main to fix/bundle-parser-milo-paths October 8, 2026 14:35
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.54%. Comparing base (e23f210) to head (d76f50e).

Additional details and impacted files
@@                       Coverage Diff                        @@
##           fix/bundle-parser-milo-paths    #5980      +/-   ##
================================================================
+ Coverage                         91.52%   91.54%   +0.01%     
================================================================
  Files                               113      113              
  Lines                             43594    43597       +3     
================================================================
+ Hits                              39901    39911      +10     
+ Misses                             3693     3686       -7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Base automatically changed from fix/bundle-parser-milo-paths to main October 8, 2026 16:02
@mcollina
mcollina merged commit e960331 into main Oct 8, 2026
73 checks passed
@mcollina
mcollina deleted the fix/cache-max-age-0-same-ms branch October 8, 2026 16:30
@github-actions github-actions Bot mentioned this pull request Oct 14, 2026
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.

3 participants