Skip to content

fix: honor client validators during forced revalidation - #298

Open
perfloop[bot] wants to merge 5 commits into
mainfrom
perfloop-pr-open-qq6pcvmfgx
Open

perfloop[bot] wants to merge 5 commits into
mainfrom
perfloop-pr-open-qq6pcvmfgx

Conversation

@perfloop

@perfloop perfloop Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Forced-revalidation GETs now return a bodyless conditional response when the client's validators match the selected representation. TAG checks the client's conditions separately from its synthetic cache-freshness request.

ns/op 888.5 µs → 331.9 µs (−61.2%); medians of 9 paired runs.

The test fails without this change and passes with it.

The test fails without this change and passes with it.

Per-metric results
Workload Measure Metric Before median After median Paired change Outcome / requirement
512 KiB forced-revalidation GET with matching client ETag time ns/op 888.5 µs 331.9 µs −61.2% improvement passed

Each workload ran 9 paired runs.

Changes

  • Combine repeated If-None-Match fields, respecting quoted commas and precedence over modification dates.
  • Evaluate conditions against origin-confirmed metadata before committing a body; forward the original request if an updated ETag cannot label cached bytes.
  • Preserve changed-body draining, cache population and range rewarming when the client needs no body. Stale fallback evaluates the stale representation without recording successful origin validation.

The origin validation round trip remains necessary. HEAD keeps its separate revalidation flow, and cache metadata storage and coordination are unchanged.

Testing

TestRevalidationClientConditionsMatchOrigin compares direct-origin and gateway status, validators, range metadata, bytes and cache reads; it reproduces the discrepancy without the repair.

TestCachedObjectMeta_MatchesETagHeader checks quoted commas with strong and weak comparison.

TestNormalCacheHitRepeatedIfNoneMatchFields checks repeated fields on an ordinary cache hit.

TestRevalidationStaleFallbackUsesClientConditionsWithoutSuccessValidation checks conditional stale service and failure accounting.

TestRevalidationBodyMissForwardsOriginalClientConditions preserves pre-commit fallback with the original headers; this check also passes without the repair.

TestRevalidationCommittedCacheReadFailureDoesNotForwardAgain preserves an incomplete transfer without a second origin response; this check also passes without the repair.

TestRevalidationChangedBodyDrainFailureStillCompletesMatching304 checks a complete conditional response without publishing truncated cache content.

TestRevalidationChangedRangeDrainFailureStillCompletesMatching304 checks that a failed range drain retains the complete conditional response and full-object rewarm.

Benchmark

proxy/revalidation_benchmark_test.go adds BenchmarkRevalidationClientMatch. Reproduce with go test ./proxy -run '^$' -bench '^BenchmarkRevalidationClientMatch$'. It measures a serial, matching-validator GET for a warmed 512 KiB object through the real transparent forwarder with valid SigV4, loopback HTTP origin and gateway, and an in-memory cache. Setup is outside timing; the origin round trip and complete response read are included. The metric is local elapsed time, not CPU time. Changed-origin drain and populate work remain and are not this benchmark's workload.

Production frequency, object-size distribution, remote-cache cost and end-to-end savings remain unmeasured. The SDK compatibility job remains target-CI owned.

5 recorded checks pass with this change.

  • Proxy tests
  • Cache tests
  • Conditional GET race tests
  • Conditional cache integration tests
  • Formatting and module checks

Generated by Perfloop.


Note

Medium Risk
Changes core GET conditional and revalidation response selection (304 vs body, stale fallback, ETag parsing), which can alter client-visible HTTP semantics for cached reads.

Overview
Forced-revalidation GETs now treat the client’s If-None-Match / If-Modified-Since separately from TAG’s synthetic upstream freshness check. After origin confirms the representation, matching validators can return a bodyless 304 without reading the cached body—addressing the ~61% latency win on matching ETag revalidations in the benchmark.

ETag list parsing in MatchesETagHeader splits on commas only outside quotes, so tags like "a,b" and repeated If-None-Match fields (merged via new clientIfNoneMatch / clientNotModified helpers) behave per RFC 7232 on cache hits and revalidation paths.

Revalidation flow (revalidateAndServe): origin 304 merges response validators locally, returns client 304 when appropriate, serves cached bytes when not, or forwards the original request if the 304 updates ETag without a safe cached body. Origin 200/206 can still 304 to the client while draining the upstream body into cache update/rewarm. Stale fallback applies client conditionals without counting as successful origin validation.

Docs and README describe the new conditional semantics and X-Cache meanings; broad integration tests and BenchmarkRevalidationClientMatch cover the behavior.

Reviewed by Cursor Bugbot for commit 96a52b1. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Forced-revalidation GETs now check the client's validators separately from TAG's cache-freshness request.

  • Forced-revalidation GETs return 304 when client validators match the origin.
  • ETag lists keep commas inside quoted tags.

Reviews (1) · Last reviewed commit: "fix: honor client validators during forc..." · Reviewed by Greptile

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