Skip to content

fix(s3): stop reads extending explicit TTLs - #439

Merged
alecthomas merged 1 commit into
mainfrom
s3-ttl-read-refresh
Nov 9, 2026
Merged

alecthomas merged 1 commit into
mainfrom
s3-ttl-read-refresh

Conversation

@alecthomas

Copy link
Copy Markdown
Collaborator

Reading an S3 cache entry refreshed its expiry to now + MaxTTL once less than half of MaxTTL remained. This applied to every entry, whatever TTL its creator requested. #173 added the refresh so frequently read git snapshots would not expire 72h after creation. Its side effect is that entries created with a short, explicit TTL are kept alive for as long as they are read.

Git bundles show the harm. They are cached for BundleCacheTTL (2h by default) under a key made from the upstream URL and base commit, but they contain everything up to the current HEAD. The TTL is what limits how stale a bundle can get. A bundle is only written on a miss, so a popular one was never rebuilt and kept serving an older and older HEAD until the bucket lifecycle rule deleted it, at least a day later.

The approach keeps both behaviours:

  • Create marks objects stored with TTL 0 (the default) with a Sliding-Expiry key in the data object's user metadata. That metadata never changes after upload, so the stale-companion fallback path still sees the mark.
  • Open extends the expiry only for marked objects, using the same rule as before. S3 has no size-based eviction, so this is still how frequently read snapshots stay cached.
  • Any explicit TTL, including one capped at MaxTTL, is a hard expiry that reads never extend.
  • Objects written before this change have no mark, so they are not extended. Treating them as extendable would keep existing popular bundles alive indefinitely. The cost is that an existing snapshot is not extended until it is next rewritten, so the worst case is one cold miss per snapshot.

The refresh decision is now a small pure function with a table-driven test. A second test against MinIO checks that Create marks only TTL 0 entries.

One related issue is not addressed here. Tiered backfill writes into tier 0 with TTL 0 (internal/cache/tiered.go), so a 2h bundle copied from S3 to the local disk tier gets disk's maximum TTL.

🤖 Generated with Claude Code

Reads refreshed every S3 entry's expiry to now + MaxTTL, regardless of the
TTL its creator requested. Git bundles are keyed by base commit but contain
history up to HEAD, so their short TTL is what bounds staleness; popular
bundles were extended indefinitely and served an ever-older HEAD until the
bucket lifecycle rule removed them.

Entries created with the default TTL (e.g. git snapshots) are now marked
in their data object metadata and keep the read-time refresh from #173,
since S3 has no size-based eviction. Explicit TTLs are hard expiries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alecthomas
alecthomas marked this pull request as ready for review November 9, 2026 01:47
@alecthomas
alecthomas requested a review from a team as a code owner November 9, 2026 01:47
@alecthomas
alecthomas requested review from luispadron and removed request for a team November 9, 2026 01:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T01:48:49.587100Z 374836f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 374836f873

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cache/s3.go Resolved
@alecthomas
alecthomas merged commit 0277712 into main Nov 9, 2026
7 checks passed
@alecthomas
alecthomas deleted the s3-ttl-read-refresh branch November 9, 2026 01:51
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