Skip to content

Preserve outbound cache tags and borrowed readiness - #460

Open
ChristianPavilonis wants to merge 15 commits into
review/pr275-cutover-followup-20261112from
issue-459-outbound-compat
Open

ChristianPavilonis wants to merge 15 commits into
review/pr275-cutover-followup-20261112from
issue-459-outbound-compat

Conversation

@ChristianPavilonis

@ChristianPavilonis ChristianPavilonis commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve existing Fastly surrogate-key metadata when callers use managed outbound HTTP. Tags are mutually exclusive with bypass and do not set TTL/stale overrides or a wire header.
  • Expose the provider's existing paired time and Pending's existing borrowed readiness path, without another transport, completion state, detached task or deadline policy.

Depends on #275. Production changes are separate commits 251974d4 and dc296073; publication head also enables ordinary CI for stacked bases and updates its exact trigger regression.

Review follow-up in 90a1d4ed

  • Reject the whole malformed surrogate-key list in dispatch preflight. At least one key is required, keys use printable ASCII (0x21..=0x7e), and only ASCII spaces separate keys. Fastly passes valid lists unchanged to SDK 0.13.3.
  • Reject tagged Cloudflare requests before body polling or Fetch. Untagged default and bypass behavior are unchanged. Axum and Spin still accept valid tags as a no-op.
  • Keep the existing cache-policy API. Setter-time validation, deduplication, and hosted cache fill and purge qualification remain out of scope.

Changes

Crate / File Change
Core outbound Tagged default policy, borrowed getter, paired-time getter and non-consuming poll_ready. collect reuses its existing drive path; is_ready is unchanged.
Fastly outbound Map the typed selection to the existing SDK set_surrogate_key operation.
Core/adapters tests Real wakeup/borrow-drop/cache/owner tests; SDK metadata for Send/Begin/Batch; optimizer preflight, redirect/signing and portable no-op checks.
Outbound spec and guide Document tags, loss of Copy and snapshot/ownership boundaries.
Ordinary CI Cover non-main PR bases while retaining main-only push and existing deployment triggers.

Closes

Closes #459

Test plan

Production-source checks at exact dc296073, with clean before/after fingerprints:

  • cargo test --workspace --all-targets, default parallel: 2711 passed, one existing generated-workspace test ignored.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings.
  • cargo fmt --all -- --check.
  • cargo check --workspace --all-targets --features "fastly cloudflare spin".
  • Target-matched Fastly WASM execution: 325 library +37 contract +1 API cases, using the repository-audited repaired Viceroy0.21, not stock-hosted qualification. Target Clippy passes.
  • Cloudflare unknown-unknown and Spin wasip2 all-target compilation; native adjacent serial suite705 passes.
  • Publication-only changes: 35 CI tooling tests and actionlint with ShellCheck pass.
  • Outbound docs/legacy contracts and changed-content privacy audit pass.
  • Full demo workspace/docs build and hosted cache fill/purge acceptance are not claimed by these local results.

A separate adjacent all-feature parallel Axum sample failed the unchanged pending_chunked_forward timing bound at 205.459963 ms against 200 ms +5 ms. The default primary pass does not clear or establish the cause of that miss. No threshold or assertion changed.

Workers SDK cache-mode test code compiled for its real target but was not browser-executed. Fastly SDK object checks prove metadata mapping, not hosted purge, private-response caching or Image Optimizer acceptance. Tagged optimizer requests reject before I/O because that SDK path replaces custom cache metadata.

The application owns its timer-first cutoff: borrow readiness before expiry, stop driving when the timer wins, then use the existing non-driving snapshot/collection rules. This PR does not change that policy.

Checklist

  • No Tokio/runtime/SDK/dependency/capability pin changes.
  • No second transport or compatibility carrier.
  • New behavior has scoped/public API and cross-target tests.
  • No credentials, licensed data or customer material added.
  • Existing origin freshness, signing, response-body ownership and cancellation remain authoritative.

Draft while fresh hosted checks and combined application acceptance run. No deployment or merge into main is part of this PR publication.

@aram356

aram356 commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

CREATOR: From the server-side identity plan (IABTechLab/trusted-server#1559, c7dc9de77): Validate tags (printable ASCII, non-empty) and make Cloudflare reject tags instead of silently using the default. Fix the red Cloudflare wasm clippy; the fix exists only in RC commit ebf622c2. It removes Copy from an #275 public type, so it lands before R1.

Part of #488

@ChristianPavilonis
ChristianPavilonis marked this pull request as ready for review November 13, 2026 17:02
@ChristianPavilonis
ChristianPavilonis changed the base branch from docs/outbound-http-spec to review/pr275-cutover-followup-20261112 November 13, 2026 17:32
aram356 added a commit that referenced this pull request Nov 14, 2026
Brings #275 at e9ffaa8 and the refreshed heads of #499, #460, #406,
#407, #409, #414, #422 and #439. Each PR merged the one below it, so
this merge has no conflicts.

Two edits fit #469 to #275, as #469's open review asks:

- #469's ingress JA4 test calls into_core_request with one argument.
  #275 now passes the Axum outbound executor through that function, so
  the test gets an executor handle the way the other ingress tests do.
- The Axum guide names EdgeZeroAxumService, which #275 removes and
  check_outbound_legacy_api.sh rejects. The guide now names only
  AxumDevServer::with_trusted_ja4_header.
aram356 added a commit that referenced this pull request Nov 16, 2026
Brings #275 at b65e714 and the refreshed heads of #499, #460, #406,
#407, #409, #414, #422 and #439. Each PR merged the one below it, so
this merge has no conflicts. #409 resolved the one conflict on the way
up, in edgezero-core's app.rs imports, by keeping both.
aram356 added a commit that referenced this pull request Nov 17, 2026
Brings #275 at ea2549f and the refreshed heads of #499, #460, #406,
#407, #409, #414, #422 and #439, including #422's stock-celld store
service and its merge into #439. Each PR merged the one below it, with
no conflicts on the way up, so this merge has no conflicts.
@ChristianPavilonis
ChristianPavilonis removed this pull request from stack #501 November 17, 2026 17:14
Bring in main's Fastly SDK 0.13.3 upgrade (#529) with Viceroy 0.22.0
and the Fastly CLI 17.2.0 upgrade (#531), with PR #275's exact pins at
0.13.3 and url 2.5.9, its Viceroy readiness repair on 0.22.0 and its
typed Image Optimizer unavailability check for SDK 0.13.3.
The surrogate-key filter comment and the proxying guide's surrogate key
and Image Optimizer notes name the SDK release they describe. SDK 0.13.3
leaves the surrogate key setter and the cache override handling
unchanged from 0.13.1, and a service with Image Optimizer enabled still
reaches the same optimizer send call, so the notes hold for the pinned
0.13.3.
Bring in PR #275's installation of the wasm32-unknown-unknown target
before the Viceroy 0.22.0 readiness repair builds, which the fastly
wasm tests and Portable record contracts (Fastly) jobs need.
@aram356

aram356 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed 5ca954cf, e8e1d9cb and e93f7e52.

Bring in PR #275's atomic conditional KV insert in the Viceroy readiness
repair, which the Fastly record contract's native race needs.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed d914d222, a merge of #499's new head that brings #275's 41cdf035, which makes conditional KV inserts atomic in the Viceroy readiness repair, as the Fastly record contract's native race needs. It had no conflicts.

Bring in PR #275's batch cutoff test fix, which advances the test clock
when the request arms its own deadline instead of after dispatch.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed cdd7c568, a merge of #499's new head that brings #275's 0e2a58ae, which fixes an intermittent failure of the batch cutoff test by advancing its clock when the request arms its deadline timer. It had no conflicts.

@prk-Jr prk-Jr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at cdd7c568 against base 27901990.

The borrowed readiness path (poll_ready, collect reusing it, HttpClient::time) looks correct. The Fastly SDK mapping matches fastly 0.13.3: set_surrogate_key switches the override from Pass to Override, and the guest-cache candidate converts the whole value with HeaderValue::to_str, so per-key filtering is what preserves valid neighbouring keys. Redirect replay and the Image Optimizer preflight both keep the tag correctly.

Blocking: a tag that can't be honoured is silently dropped rather than rejected.

The comment opening this PR (13 Nov) asked to validate tags (printable ASCII, non-empty) and to make Cloudflare reject tags instead of silently using the default. The later fix commit c191a9c5 does the opposite, and the PR does not say why:

  • Fastly (build_fastly_request / filter_surrogate_keys): keys outside 0x21..=0x7e are discarded with no error and no log. A value whose keys are all invalid becomes an Override with an empty key list. The request still dispatches and the response can still be cached, but it carries none of the caller's purge keys.
  • Cloudflare (build_worker_request, and tagged_default_is_an_accepted_cache_noop): the tag is accepted and ignored. Workers Fetch keeps its default caching, so the response can be cached without the purge identity the caller asked for.

Consequence: a later purge by that key misses these objects, and stale content is served until normal expiry. The guide asks callers whose purge contract requires a tag to fail closed if HeaderValue conversion fails. Callers can't do that here, because conversion succeeds and the loss happens inside the adapter with no signal. Axum and Spin have no intermediary cache, so a no-op there is semantically fine. Cloudflare and partially-invalid Fastly values are different.

Minimal correction, matching the existing preflight pattern that already rejects tagged and Image Optimizer requests before I/O:

  1. Validate PlatformDefaultWithSurrogateKey in validate_for_dispatch. Return bad_request when the value contains a byte outside space or 0x21..=0x7e, or has no non-empty key. The Fastly filter then becomes unnecessary, or a debug assertion.
  2. Make Cloudflare's validate_supported_options reject the tagged variant, as it already does for Image Optimizer.

If the maintainers deliberately chose filter-and-ignore over that request, please record the decision in the PR and the guide instead. Then this becomes non-blocking.

Verification

  • cargo +1.98.1 test -p edgezero-core --all-targets passes locally.
  • Two broken-code checks on core both failed as expected: replacing the replayed policy with PlatformDefault in redirect replay, and loosening the optimizer guard to reject only Bypass. With the code restored, the tests pass again.
  • Hosted CI at this head is green except cache-restore-seed, which is a compiler-cache publication failure unrelated to this change. The Fastly and Cloudflare evidence artifacts show the new tests passing on the repaired Viceroy and the Workers runner: tagged_cache_metadata_*, surrogate_key_filter_*, captured_begun_* and tagged_default_*.
  • I could not run the Fastly wasm tests locally, because the local Viceroy is too old. Hosted cache fill and purge remain out of scope, as the description says.

@ChristianPavilonis

Copy link
Copy Markdown
Collaborator Author

The review fixes are in 90a1d4ed: reject malformed tag lists before dispatch, reject tagged Cloudflare requests before Fetch, and align the spec with Fastly SDK 0.13.3.

The earlier Cloudflare WASM Clippy failure was already fixed by borrowing the cache policy in c191a9c5. Target Clippy still passes with this patch. Local verification also passed for core, the Workers WASM clock suite, the Fastly SDK metadata test on Viceroy 0.22.0, and the Axum and Spin compatibility tests.

Setter-time validation and ordered deduplication in EZ-11 remain outside this patch so the cache-policy API stays unchanged. Hosted cache fill and purge were not tested.

@prk-Jr prk-Jr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PR Review (follow-up)

Summary

Re-reviewed at 90a1d4ed against base 27901990. 90a1d4ed fixes both blocking items from my previous review. Malformed tag lists are now rejected in shared dispatch preflight, and Cloudflare rejects tagged requests before Fetch. The borrowed-readiness and paired-time parts are unchanged since my last pass and still look correct. Approving. The comments below are optional.

😃 Praise

  • 😃 Putting the check in validate_for_dispatch means every path gets it. send, begin, batch slots and every follow hop all go through dispatch::prepare, which calls it. The new core test covers all four modes. It also checks that no upload is polled and nothing is dispatched.
  • 😃 The Cloudflare wasm test uses a mixed batch and asserts exactly one Fetch, from the untagged slot. That shows the tagged slot really stops before I/O while its neighbour still runs.
  • 😃 The Fastly SDK test now passes " ! ~ duplicate duplicate " straight through. That covers both ends of the printable range, repeated spaces and duplicates, so the "no filtering, no dedup" rule is tested, not just documented.

Prior findings status

Prior finding Status Evidence
🔧 Fastly silently dropped invalid keys; an all-invalid list dispatched with no purge keys ✅ resolved crates/edgezero-core/src/outbound.rs:1947-1960 rejects with BadRequest any byte outside space/0x21..=0x7e and any list with no key. filter_surrogate_keys is gone. Fastly passes the value unchanged (crates/edgezero-adapter-fastly/src/outbound.rs:1162).
🔧 Cloudflare accepted the tag and kept default Fetch caching ✅ resolved crates/edgezero-adapter-cloudflare/src/outbound.rs:3897-3904 rejects the tagged variant in validate_supported_options, which prepare runs before validate_for_dispatch.
⛏ Spec named SDK 0.13.1 ✅ resolved The spec paragraph now names 0.13.3, matching the guide and lockfile.

Findings

Blocking

None.

Non-blocking

  • 🌱 Fastly length limits are still a silent-loss path (inline on outbound.rs).
  • 📝 Public enum change: OutboundCachePolicy gains a variant and drops Copy. Downstream exhaustive matches and by-value copies will stop compiling. The guide documents the loss of Copy. This is fine before 1.0, but please mention it in the CHANGELOG when the stack lands.

Verification

  • Broken-code checks, both failed as expected and passed again once the code was restored: (1) removing the "at least one key" clause in validate_for_dispatch fails malformed_surrogate_keys_fail_before_upload_or_dispatch; (2) disabling the Cloudflare tagged rejection fails tagged_default_is_unsupported_in_batch_preflight.
  • Local: cargo fmt --all -- --check passes. cargo test -p edgezero-core --all-targets and cargo test -p edgezero-adapter-{fastly,cloudflare,spin} --all-targets --features test-utils pass. cargo +1.98.1 clippy on core and all four adapters with --all-targets --all-features -D warnings is clean.

CI Status

  • Hosted CI at 90a1d4ed: all checks pass (Run Tests, Run Format, Deploy actions, CodeQL), including the fastly, cloudflare and spin wasm test jobs.
  • The Cloudflare and Fastly lifecycle evidence artifacts for this run show these tests passing: tagged_default_is_rejected_before_body_poll_or_fetch, tagged_default_is_unsupported_in_batch_preflight, untagged_cache_policies_keep_worker_default_and_no_store_modes and tagged_cache_metadata_reaches_sdk_from_send_begin_and_batch_without_ttl.
  • Not covered: Fastly wasm tests were not run locally. Hosted cache fill and purge stay out of scope, as the description says.

Comment on lines +1947 to +1960
if let OutboundCachePolicy::PlatformDefaultWithSurrogateKey(value) =
request.cache_policy_setting()
{
let keys = value.as_bytes();
if !keys
.iter()
.all(|byte| *byte == b' ' || byte.is_ascii_graphic())
|| !keys.iter().any(u8::is_ascii_graphic)
{
return Err(EdgeError::bad_request(
"surrogate keys must be a non-empty space-separated list of printable ASCII keys",
));
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🌱 Length limits can still lose tags silently on Fastly. This check closes the byte-class and empty-list cases. Fastly's surrogate-key guide also sets length limits: individual tokens may not exceed 1KB, and a Surrogate-Key value may not exceed 16KB. When either limit is hit while parsing, "the token currently being parsed and all tokens following it within the same header will be ignored". So a list with a 1025-byte key, or more than 16KB in total, passes this preflight. The response is then cached without that key and every key after it, which is the same purge-miss outcome as the original finding. The description puts size limits out of scope, so this doesn't block. A cheap follow-up would be to reject a key over 1024 bytes or a value over 16384 bytes here, or at least to name these limits in the guide paragraph that says EdgeZero adds no size limit.

Comment on lines +3897 to +3904
if matches!(
request.cache_policy_setting(),
OutboundCachePolicy::PlatformDefaultWithSurrogateKey(_)
) {
return Err(EdgeError::bad_request(
"outbound cache surrogate keys are not supported by cloudflare",
));
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

😃 This follows the existing Image Optimizer rejection, and prepare runs it before validate_for_dispatch, so a tagged request fails with the clearer Cloudflare-specific message even when its list is also malformed. I checked this by disabling the condition: tagged_default_is_unsupported_in_batch_preflight then fails, so the test really depends on this check.

}

#[test]
fn malformed_surrogate_keys_fail_before_upload_or_dispatch() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

😃 Good coverage: empty, spaces only, invalid UTF-8, valid UTF-8 outside ASCII, and tab, each across Send, Begin, Follow (first hop) and Batch. The test also asserts no body polls and no recorded provider requests. Removing the at-least-one-key clause makes this test fail, as it should.

This branch has not been deployed

No deployments
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.

Preserve managed outbound cache and collection contracts

3 participants