Skip to content

fix(cache): attach s3://bucket/key context to body-phase stream errors - #1618

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/s3-body-phase-error-context
Aug 5, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/s3-body-phase-error-context

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

What

S3 GET failures during the body/stream phase lost the s3://bucket/key prefix that header-phase errors carry. The body error surfaces from ReaderStream after the GetObject future has already returned, so log_target could not be attached with a single .context(...) call — it has to be threaded through a per-chunk map adapter. This was deferred out of #271 and untracked since.

Change

  • crates/cache/src/origin/s3.rs: new prefix_body_stream_error(log_target, io::Error) helper, wired onto the final OriginByteStream in fetch via stream.map(...). It fires only on the error arm; the happy path is untouched.
  • The wrapper is deliberately narrow so it does not disturb retry::classify_io_error, which the engine runs over every body-phase error:
    • typed markers (BlobTooLargeMarker / OriginError, e.g. DecompressionFailed) pass through untouched so their downcast still fires and stays Permanent — re-wrapping them in a String would hide the marker and silently reclassify a deterministic permanent error as a transient Other;
    • the original io::ErrorKind is preserved on the prefixed error, so transient/permanent routing of network faults (UnexpectedEof, ConnectionReset, …) is unchanged.
  • Replaced the stale "deferred" comment block with a short pointer to the new adapter.

Tests

Three unit tests over the helper (the meat of the change):

  • body_stream_error_gains_s3_prefix — plain network fault gains the prefix and keeps its kind.
  • body_stream_error_preserves_retry_classification — a prefixed UnexpectedEof still classifies Transient.
  • body_stream_error_passes_typed_marker_through — a typed OriginError marker passes through unwrapped and still classifies Permanent.

cargo nextest run -p decdn-cache: 327 passed, 0 failed.

Closes #1617

🤖 Generated with Claude Code

S3 GET body-phase stream errors surfaced from `ReaderStream` after the
`GetObject` future returned, so they lost the `s3://bucket/key` prefix
that header-phase errors carry from `classify_get_object_error`
(deferred out of #271). Thread `log_target` through a per-chunk
`map` adapter that prepends the prefix on the error arm only.

The wrapper is deliberately narrow so it does not disturb
`retry::classify_io_error`: it passes typed markers
(`BlobTooLargeMarker` / `OriginError`) through untouched so their
downcast still fires, and preserves the original `io::ErrorKind` so
transient/permanent routing of network faults is unchanged.

Closes #1617

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 5, 2026 14:58
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@alpergundogdu, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 26 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: c1a3f00a-1ae3-434c-8adc-45a8d6a7817c

📥 Commits

Reviewing files that changed from the base of the PR and between 0f1be9c and 5ce2312.

📒 Files selected for processing (1)
  • crates/cache/src/origin/s3.rs

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 80.33% (was 80.30%, ▲ +0.02%) — 57158/71158 lines

File Coverage Lines Δ
crates/cache/src/origin/s3.rs 89.36% 546/611 ▲ +0.69%
History
Commit Total Δ vs base
0294e2b 80.31% ▲ +0.01%
5ce2312 (HEAD) 80.33% ▲ +0.02%

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 improves S3-origin observability in decdn-cache by ensuring body/stream-phase S3 GET failures retain the same s3://bucket/key context that header-phase errors already include, without changing retry classification behavior.

Changes:

  • Added a prefix_body_stream_error(log_target, io::Error) helper to attach s3://bucket/key context to mid-stream io::Errors while preserving io::ErrorKind and typed markers.
  • Wired the helper into the S3 fetch body stream via a per-item StreamExt::map(...) adapter.
  • Added focused unit tests validating prefixing behavior and preserving classify_io_error routing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cache/src/origin/s3.rs Resolved
Comment thread crates/cache/src/origin/s3.rs Resolved
Address PR #1618 review:

- `prefix_body_stream_error` now wraps the original `io::Error` in a
  private `PrefixedBodyError` struct whose `Display` prepends the
  `s3://bucket/key` prefix and whose `source()` returns the original
  error, instead of flattening it into a formatted `String`. The
  `io::ErrorKind` is still preserved and typed markers
  (`BlobTooLargeMarker` / `OriginError`) still pass through untouched.
  Added a test assertion that the original error is reachable via
  `std::error::Error::source`.

- Reword the `map`-adapter comment: the per-chunk closure runs for
  every item; it is a cheap passthrough on `Ok` (no allocation) and
  only builds the prefixed error on `Err`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit 2bd4878 into main Aug 5, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/s3-body-phase-error-context branch August 5, 2026 15:55
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.

S3 body-phase error context: propagate s3://bucket/key prefix

2 participants