Skip to content

fix: fall back to the default when PECANS_CACHE_MAX_AGE is not a number#71

Merged
dopry merged 2 commits into
nextfrom
claude/fix-cache-max-age-parse
Jul 22, 2026
Merged

fix: fall back to the default when PECANS_CACHE_MAX_AGE is not a number#71
dopry merged 2 commits into
nextfrom
claude/fix-cache-max-age-parse

Conversation

@dopry

@dopry dopry commented Jul 22, 2026

Copy link
Copy Markdown
Owner

parseInt of a non-numeric PECANS_CACHE_MAX_AGE produced NaN, which flowed into the backend's cache-age comparison where every check comes out false — the release cache was fetched once at startup and never refreshed again. configure() now parses the env var through a new exported parseCacheMaxAge() helper (mirroring parseTrustProxy), which falls back to the 2-hour default for missing or non-numeric values.

Includes unit tests for numeric, missing, empty, and garbage values.

From the 2.0 release review pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AtqCsX7ptP36t5rdyaJJhM


Generated by Claude Code

parseInt of a non-numeric value produced NaN, which flowed into the
backend's cache-age comparison where every check is false - the release
cache was fetched once and never refreshed again. Parse the env var
through parseCacheMaxAge, which falls back to the 2 hour default for
missing or non-numeric values.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AtqCsX7ptP36t5rdyaJJhM

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a caching edge case in configure() where an invalid PECANS_CACHE_MAX_AGE (e.g. non-numeric) could produce NaN, preventing the backend cache from ever refreshing after the initial fetch. It introduces a dedicated parseCacheMaxAge() helper (similar in spirit to parseTrustProxy) and adds unit tests for the parsing behavior.

Changes:

  • Add parseCacheMaxAge() with a 2-hour fallback default and use it from configure().
  • Ensure invalid/missing cache max age values don’t propagate NaN into backend cache refresh logic.
  • Add unit tests covering numeric, missing/empty, and garbage inputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/index.ts Adds parseCacheMaxAge() and routes PECANS_CACHE_MAX_AGE parsing through it to avoid NaN disabling cache refresh.
test/unit/index.spec.ts Adds unit tests for parseCacheMaxAge() behavior.

Comment thread src/index.ts
Comment thread test/unit/index.spec.ts
Comment thread src/index.ts Outdated
Copilot review follow-up: parseInt-permissive values like '3600ms' or
'-1' now fall back to the default instead of silently changing caching
behavior (a negative age refreshes on every request), and the 2 hour
default is shared from the backend module instead of duplicated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AtqCsX7ptP36t5rdyaJJhM

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@dopry
dopry merged commit 9b2063d into next Jul 22, 2026
3 checks passed
@dopry
dopry deleted the claude/fix-cache-max-age-parse branch July 22, 2026 03:07
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