Skip to content

fix(cache): include exchange delay in response age - #82

Merged
fannnzhang merged 2 commits into
mainfrom
bugfix/cache-response-age
Nov 25, 2026
Merged

fannnzhang merged 2 commits into
mainfrom
bugfix/cache-response-age

Conversation

@fannnzhang

Copy link
Copy Markdown
Contributor

Cached responses could be reported and reused as younger than RFC 9111 permits because the Age calculation omitted request-to-response delay and restarted residence at storage. The fixed regression now produces 205 seconds instead of 203; buffering the body also retains the time already elapsed since response headers.

The transport attaches per-attempt ResponseTiming to HTTP/1 and HTTP/2 responses. The cache uses that metadata for corrected initial age, freshness and generated Age, including 304 validation with its own timestamps and missing-Date normalization. Valid oversized Age values saturate instead of becoming zero. Synthetic responses without trustworthy timing are returned without automatic storage; existing connector and constructor signatures remain unchanged.

Added 15 focused tests covering literal RFC vectors, fractional and buffering time, validation, malformed/oversized Age, incomplete wire bodies, missing timing, H1 headers before a gated body, negotiated H2 and final-hop redirect timing. The requirement matrix and evidence describe the verified scope.

Validation on macOS arm64, Rust 1.99.1:

  • RUST_TEST_THREADS=1 cargo test --workspace --all-targets: 579 passed, 16 ignored.
  • RUST_TEST_THREADS=1 cargo test --workspace --all-targets --all-features: 620 passed, 16 ignored.
  • cargo test --workspace --all-features --doc: 2 passed.
  • cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --all --check: passed.
  • The 203/205 and legal Age-overflow regressions were observed failing before the calculation/parser fixes.

The initial parallel default run encountered the existing tracing capture race (spans = []), reproduced on unmodified origin/main; complete suites were therefore also verified serially. The separate existing 304 strong-ETag eligibility gap is explicitly recorded as a conformance/release blocker in the evidence document; this PR verifies Age/Date reconstruction, not complete cache conformance.

The macOS default Test and Build job lost the "response body failed"
trace event. tracing-core 0.1.36 keeps a process-wide callsite interest,
and with one registered dispatcher the first thread to execute the event
caches Interest::never(). A parallel body-failure test can do that before
the capturing subscriber runs. Bring main's fresh-process capture harness
onto this branch so the existing assertions run without shared callsite
state. Cache Age behavior is unchanged.
Co-authored-by: peter rich <fannnzhang@users.noreply.github.com>
@fannnzhang
fannnzhang merged commit 97ccc5f into main Nov 25, 2026
10 checks passed
@fannnzhang
fannnzhang deleted the bugfix/cache-response-age branch November 25, 2026 08:08
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.

2 participants