Skip to content

fix: harden Vary caching and collapsed forwarding - #65

Draft
sendya wants to merge 2 commits into
mainfrom
fix/vary-fix
Draft

fix: harden Vary caching and collapsed forwarding#65
sendya wants to merge 2 commits into
mainfrom
fix/vary-fix

Conversation

@sendya

@sendya sendya commented Aug 19, 2026

Copy link
Copy Markdown
Member

Summary

  • Introduce deterministic request-header fingerprints and a collision-resistant v2 format for Vary identities.
  • Harden Vary cache lifecycle handling, including wildcard, ignored, changed, removed, legacy, and concurrent-variant cases.
  • Restore effective object-level collapsed forwarding without sharing responses across incompatible representations.
  • Keep method, range, conditional, authentication, cache-control, and upstream-routing inputs isolated where Vary cannot express the distinction.

Motivation

Collapsed forwarding regressed after the flight key began fingerprinting the complete request header map. Request-local metadata such as X-Request-Idx, request IDs, and tracing fields then produced different keys for otherwise equivalent cache misses, causing every concurrent request to reach the origin.

Simply returning to an object-only key would make cold misses unsafe for different methods, ranges, authentication contexts, or response representations. Vary identity serialization also needed stronger field-boundary guarantees and compatibility with existing cache entries.

Implementation

  • Serialize Vary selections using an explicit v2 schema that distinguishes field names, boundaries, absent fields, empty values, and value ordering.
  • Retain fallback lookup support for legacy Vary cache keys.
  • Select representation-specific object IDs before collapsing known Vary misses.
  • Build the initial object-flight key from the object ID, HTTP method, and request controls that affect response semantics outside Vary.
  • Inspect the origin response's actual Vary fields before fan-out.
  • Re-collapse incompatible waiters under representation-specific keys instead of returning the leader's response.
  • Merge concurrent Vary root metadata updates so newly discovered variants are not lost.
  • Add focused regression coverage for metadata-only differences, Vary representation isolation, request-control isolation, wildcard handling, legacy compatibility, and concurrent variant updates.

Impact

Equivalent concurrent full-cache misses once again collapse to a single origin request, including requests carrying unique correlation metadata. Requests that select different representations or carry response-altering controls remain isolated, preserving response correctness and cache safety.

Validation

  • go test -count=1 ./server/middleware/caching ./pkg/x/http ./proxy
  • CGO_ENABLED=1 go test -race -count=1 -run '^TestObjectFlight' ./server/middleware/caching
  • go vet ./server/middleware/caching ./pkg/x/http ./proxy
  • go test -count=1 -v ./tests/all-features/caching -run '^TestCollapsedForwardingObjectFlight$' against a local Tavern instance
  • Static Tavern build
  • git diff --check

sendya added 2 commits August 19, 2026 22:16
…ate Vary data serialization to a robust JSON-based schema
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