Skip to content

fix: don't truncate downloads when the cache write fails - #420

Merged
stuartwdouglas merged 2 commits into
mainfrom
fix/cache-write-failure-truncates-download
Nov 2, 2026
Merged

stuartwdouglas merged 2 commits into
mainfrom
fix/cache-write-failure-truncates-download

Conversation

@stuartwdouglas

Copy link
Copy Markdown
Contributor

A cache write failure aborted the copy feeding the client, so clients received 200 OK with a truncated body (e.g. Gradle wrapper zips failing with zip END header not found). The S3 backend hit this whenever upstream response headers exceeded S3's 2 KB user metadata limit (Your metadata headers exceed the maximum allowed metadata size), and since the write always failed, the object was never cached.

  • handler: cache write or Create failures no longer interrupt the client stream; the response is streamed in full and the cache entry is discarded.
  • s3: when headers don't fit in user metadata, only the headers needed to serve the object are stored (content headers, ETag, Last-Modified, X-Cachew-*). Create fails up front if even those don't fit.
  • handler: fetch/serve error logs now include cache_key so failures can be tied to an upstream URL.

A cache write failure aborted the shared copy feeding the client, so
clients got 200 OK with a truncated body. The S3 backend triggered this
whenever upstream response headers exceeded S3's 2 KB user metadata
limit.

- handler: keep streaming to the client when the cache writer fails or
  can't be created, and discard the cache entry.
- s3: when headers don't fit in user metadata, store only the headers
  needed to serve the object (content headers, ETag, Last-Modified,
  X-Cachew-*), and fail Create up front if even those don't fit.
- handler: log the cache key with fetch and serve errors.

Amp-Thread-ID: https://ampcode.com/threads/T-01a19b0c-ec15-75f2-b427-a1f18a35f91c
Co-authored-by: Amp <amp@ampcode.com>
@stuartwdouglas
stuartwdouglas marked this pull request as ready for review November 2, 2026 07:18
@stuartwdouglas
stuartwdouglas requested a review from a team as a code owner November 2, 2026 07:18
@stuartwdouglas
stuartwdouglas requested review from jrobotham-square and removed request for a team November 2, 2026 07:18
@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T07:22:21.350683Z 019e757 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: 019e757601

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/strategy/handler/handler.go Outdated
Comment on lines +249 to +250
// cacheTee forwards writes to a cache writer until it fails, then discards
// them, so a cache failure can't abort the copy that feeds the client.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove documentation from the small cacheTee helper

This private type and its Write method form a small, self-explanatory helper, so the newly added comment violates the repository rule that comments are reserved for non-obvious blocks of at least 20 lines; remove this comment.

AGENTS.md reference: AGENTS.md:L19-L22

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 7558c3e, along with a similar inline comment in s3UserMetadata.

@jrobotham-square jrobotham-square left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only concern from me is that it's not ideal to behave differently when the size is too big... perhaps we should always filter to the 'essential headers'?

That said, the bug feels pretty edgy so this is probably fine. (and switching to 'essential headers' might be more likely to cause other issues)

@stuartwdouglas
stuartwdouglas merged commit 6647230 into main Nov 2, 2026
7 checks passed
@stuartwdouglas
stuartwdouglas deleted the fix/cache-write-failure-truncates-download branch November 2, 2026 09:24
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