Repository navigation
Conversation
Installing a rejecting Spin scheduler changes a zero budget from 501 to 500: core now finds a handle and rejects the budget before the scheduler, as it already does on Axum and Fastly. The guides, changelog and spec claimed every Spin registration returns 501 and that the zero budget case was unchanged. Correct them and pin the 500 with a Spin unit test. Also note that core pre-dispatch hooks can replace or remove the handle (removal falls back to core's 501), that PR #512 overlaps on the CHANGELOG line as well as the capabilities bullet, and point the #509 design at the follow-up.
#509 (2620377) adds bounded work after the response on Fastly and Axum, drained on Axum SIGTERM (EZI-1, #476). #512 (cdc232c) runs it on Cloudflare through waitUntil (#478), and #515 (ec347a2) reports Spin's capability error (#483). The line now stacks on #517 and each PR merged the one below it, so this merge is clean.
|
For Trusted Server's identity integration chain, this PR's base #509 now stacks on #517. Checked locally at |
|
For the identity integration branch (#495), I pushed |
|
For the identity integration branch (#495), I pushed |
|
For the identity integration branch (#495), I pushed |
dhruv8sh
left a comment
There was a problem hiding this comment.
This PR adds Cloudflare after-response tasks. Each task is registered with Workers waitUntil right away, but it waits on a request-local oneshot gate before it starts. A single ReleaseGuard owns that gate. The guard moves from CloudflareEgressRuntime to WorkersCommitter and then into the spawned response pump. It is dropped when the response writer finishes, on bodyless handoff, on sync errors or failed fallback, and when dispatch is abandoned. Dropping it closes registration and releases all waiting tasks.
Each task's budget is min(budget, 30s) and starts only after release. Tasks run in a fresh outbound callback scope, and a panicking task is caught so it can't stop the others. The capability matrix, the docs and the docs-contract script are updated to match.
I didn't find any blocking issues. Things I checked:
- The gate uses a poison-tolerant mutex and sends signals only after the lock is released.
- Registering after release returns an error, and the task you passed in is never polled.
spawnusestake(), so the guard moves into the writer exactly once.- Gates for different requests are independent.
Tests cover streaming, bodyless responses, fallback, source errors, abort, abandoned dispatch, fresh-scope outbound and timeout cancellation.
Minor, non-blocking notes:
docs/superpowers/plans/...still has two unchecked items (signing/push and self-review), so the plan doc doesn't match a merged state.- Panic isolation only works where panics unwind. As the spec itself says, an ordinary aborting WASM panic on Workers can still end the invocation, so the "panicked" log path is mostly for host builds.
I couldn't run CI gates (fmt, clippy, tests) here because I only had read access.
dhruv8sh
left a comment
There was a problem hiding this comment.
PR Review
Summary
This PR turns on RequestContext::after_response for Cloudflare. Each task is queued with Workers waitUntil as soon as it is registered, but it is not polled until a request-local gate opens. A single ReleaseGuard closes registration and opens that gate. The guard starts in CloudflareEgressRuntime, moves to WorkersCommitter, and goes into the spawned response writer. Because the guard releases when it is dropped, every terminal path opens the gate: stream completion, a cancelled or failed writer, a bodyless handoff, fallback (whether it succeeds or fails), and an abandoned dispatch. I found no blocking problems. The design is sound and the contract tests cover the important edges.
😃 Praise
- Ownership-based release is a clean design. Tying the gate to
Dropof a guard that follows the response pump means no terminal path can forget to release. Theafter_response_releases_when_dispatch_is_abandonedandafter_response_releases_after_failed_fallbacktests confirm this. - The task's deadline and outbound callback scope are created only after release, so slow streaming does not use up the task's budget.
after_response_waits_for_stream_and_budget_starts_at_releaseand the fresh-scope/stale-scope fetch test check both behaviours directly. - The
Gatemutex is never held while the SDK is called or while waiters are signalled. BothregisterandDroprelease the lock beforewait_untilorsend.
Findings
Blocking
None.
Non-blocking
- ⛏ Unused
Defaultderive onGate: the derived default setswaiters = None, which is a gate that is already closed, and nothing uses it (see inline comment). - 🤔 Timer error is discarded: the timer-failure branch logs without the underlying error (see inline comment).
- 🤔 Timing-sensitive contract test:
after_response_waits_for_stream_and_budget_starts_at_releasedepends on wall-clock margins of 20, 25, 60 and 100 ms. On a busy CI runner the 60 ms budget could expire during the 25 msDelayplus scheduling overhead, which would makecompleted == 1fail. Consider wider margins, for example a 500 ms budget against a 25 ms delay. - 📝 Plan has unchecked items: in
docs/superpowers/plans/2026-11-18-cloudflare-after-response.md, the Task 5 items for publishing and self-review are still[ ]. That is fine if it is intentional, but tick them or remove them before merge so the plan matches what landed.
📌 Out of Scope
- Panic isolation in
run_boundedonly works in unwinding builds. Normalwasm32Workers builds abort on panic, and the docs say so. If panic isolation becomes a goal, track whether a Workers-side unwind configuration is possible as a separate issue.
ChristianPavilonis
left a comment
There was a problem hiding this comment.
I reviewed #512 against its live #509 base, feature/476-after-response-tasks at 54e7a4b8. Please address R1–R3 before advertising the Cloudflare capability. R4–R9 are optional.
The three behavioral findings reproduced with the compiled adapter and normal Rust fetch entrypoint in local workerd. Focused Cloudflare WASM and native tests, WASM Clippy, formatting, and the docs contract check passed. Hosted Cloudflare was not exercised.
|
Follow-up in 136ed0d8:
GitHub currently reports zero check runs and zero workflow runs for this head. Hosted CI remains unverified, so the inline conversations remain open. Hosted Cloudflare deployment was not exercised. The PR description now reflects this current revision and evidence instead of the older green head. |
ChristianPavilonis
left a comment
There was a problem hiding this comment.
Re-review of e4c6647a9..136ed0d8 (one commit), reviewing only #512's changes on top of #509.
All nine items from my last review are addressed. For R1, the regression is a guest scheduler test rather than the #[event(fetch)] 204 test I asked for. That's narrower but covers the yield-before-run fix.
Approving so I'm not blocking, on the understanding that you'll handle the inline comments before merging.
Bring in PR #509's after-response review fixes (the task and budget limits, the deadline checked before every poll) and the review fixes below it, from PR #517 down to PR #275, including Cloudflare geo and JA4 read only with direct ingress, the portable ClientInfo plumbing, RunMode hosting and main's lockfile versions. crates/edgezero-adapter-cloudflare/src/request.rs: PR #517 passes stores.direct_ingress to request_geo and into_core_request_head. This PR wrapped the dispatch in the after-response release scope and inserted the handle into the head request. The resolution keeps this PR's scoped dispatch and uses PR #517's direct-ingress arguments inside it. docs/guide/capabilities.md: the sentence keeps this PR's "All three supporting adapters" and PR #509's corrected reason, that the budget cannot interrupt a running poll. CHANGELOG.md: this PR renamed the after-response section to "After-Response Tasks (#476, #478)". The merge left PR #509's old heading in place with no entries under it. The resolution keeps one section under this PR's heading. That section holds this PR's Cloudflare entry, PR #509's updated registration and limit entry, and this PR's capability line, which reports Cloudflare as BoundedCooperative.
Bring in PR #517's merge of PR #514 (Spin KV Geo misconfiguration as a redacted 500 and Spin Geo timers that re-arm after an early wake) and PR #275's Fastly contract test fix through PR #509. CHANGELOG.md: PR #509's update inserted PR #514's "Spin KV Geo and Cloudflare platform Geo" section ahead of the "After-Response Tasks (#476)" heading, which this PR renamed to "(#476, #478)" with its Cloudflare entry. The resolution keeps the base's Spin section first, then one after-response section under this PR's heading.
|
Round 12 identity realignment:
Each merge message says what it carries and how any conflict was resolved. |
|
Round 15 identity realignment:
Each merge message says what it carries and how any conflict was resolved. |
Core rejects budgets above 30 seconds with a 500 before the Cloudflare scheduler runs, so the guides no longer promise a clamp.
Review follow-up: fixes committed to this branchA full review of this PR turned up the problems below; each would otherwise have needed a follow-up ticket, so it is fixed on this branch instead. Every item names its commit.
Fixes made on the PRs below this one in the stack were merged into this branch with merge commits. |
Summary
RequestContext::after_response(budget, task)on Cloudflare Workers so background work starts after terminal response egress without delaying delivery.waitUntilpromises, defer the first user poll past host handoff, and give each task a fresh outbound callback scope.min(budget, 30 seconds)from one shared release instant and reject retained handles used by another active dispatch before calling Workers.after-response-tasksasBoundedCooperativefor Cloudflare and document Workers lifetime limits, registration closure, and lack of persistence or retries.Stacked on #509 (
feature/476-after-response-tasks), which supplies the portable task API and response-egress foundation. This PR targets that branch; its changes are the Cloudflare implementation of #478.Integration note (historical comparison): a
git merge-treecomparison with #496 reported conflicts in Axum response conversion, Cloudflare/Spin contracts, and core error/extractor code. These siblings need reconciliation when integrated.Changes
edgezero-adapter-cloudflare/src/after_response.rs,src/lib.rs,src/outbound.rsedgezero-adapter-cloudflare/src/request.rs,src/response.rsedgezero-adapter-cloudflare/src/cli.rsBoundedCooperativesupport and update the capability test.edgezero-adapter-cloudflare/tests/contract.rs,src/test_runtime.rs, and colocated testsCHANGELOG.mdscripts/check_outbound_docs_contract.mjsCloses
Closes #478
This PR targets
feature/476-after-response-tasks, so merging it into that branch does not automatically close the linked issue(s); close them manually or upon default-branch integration.Current CI follow-up
Current revision:
7713311862773b3efb91ccbdc9a6010aa556bbd8, using Rust 1.98.1, Node 24.20.0 and lock-matched wasm-bindgen 0.2.128.pin-project-lite0.2.17 was yanked, so freshly generated offline consumers could no longer resolve it from the primed cache. The six active lockfiles now select non-yanked 0.2.19; every other package node is unchanged. Generated consumers still resolve their own dependencies without network access or seeded fixture locks.The fake-Cargo cancellation tests also spent their readiness window capturing real source/compiler identities. Their dedicated test helper now supplies a scoped fixture identity and fake compiler, with nested-unwind restoration coverage. Production identity hashing and the five-second readiness window and all cancellation, listener and reaping assertions remain unchanged. The separate macOS zombie-group signal race is not repaired by this test change.
cloudflare,test-utils(44 passed) and actual Node Wasm library/contracts withcloudflare,test-utils(151 / 41 passed) and standalonecloudflare(148 / 24 passed); strict Wasm Clippy for both variants.All 30 hosted checks now pass on
77133118, including the native and Wasm suites. The processed Rust CodeQL analysis is clean at the current merge (27 rules, zero findings, no errors or warnings); the other configured language analyses are also clean. These local Node guest checks do not establish new workerd or hosted Workers qualification. Earlier source/runtime evidence is preserved below as historical; the broader prescribed-suite and repaired Fastly runtime qualifications remain separate.Historical review follow-up
fc85a354 makes
Gatethe single scheduler clock owner, gives ownership/closed-window registration a combined operator diagnostic, names the per-poll request identityDispatchIdentity, and shares environment/manual-clock test setup. Registration status, release ownership and outbound callback policy are preserved.Historical local verification on
fc85a354: all five Cargo gates; isolated harness (680 passed, 4 ignored); native Cloudflare library (43 passed); actual guest library/contracts withcloudflare,test-utils(151/41 passed) andcloudflare(148/24 passed); strict WASM Clippy for both feature configurations. The diagnostic regression rejects the old message in a separate source copy and passes when restored. Rust 1.98.1, Node 24.20.0 and wasm-bindgen 0.2.128 were used.No Actions runs were observed for
fc85a354. The workerd comparison below is historical; no new hosted deployment, browser ingress run or complete Fastly runtime qualification was performed for this follow-up.Test plan
Historical implementation verification below covers
136ed0d8, using Rust 1.98.1, Node.js 24.20.0 and lock-matched wasm-bindgen 0.2.128. It is retained as historical evidence; it does not verify the latest review-follow-up revision.cargo test --workspace --all-targets— final source passed; the initial sandbox-denied socket run was superseded by a successful run with local socket access.cargo clippy --workspace --all-targets --all-features -- -D warningscargo fmt --all -- --checkcargo check --workspace --all-targets --features "fastly cloudflare spin"cargo check -p edgezero-adapter-spin --target wasm32-wasip2 --features spincloudflareandcloudflare,test-utils; both configurations passed.cloudflare,test-utils: 148 and 40 passed. Standalonecloudflarelibrary/contract suites also passed.#[event(fetch)]consumer using publicCloudflareServicedispatch in local workerd 2026-04-15: original 204 background-work responses took 95–203 ms; corrected responses took 2.4–4.2 ms against a 62–163 ms inline-work control. Expired siblings stay unpolled, unexpired siblings run, cross-request registration is rejected, and the original streaming body can still register its own work. The corrected runtime log has no cross-context warnings.The final runtime comparison uses the repository's resolved worker/worker-macros/worker-sys 0.8.5 and wasm-bindgen 0.2.128. Earlier exploratory runs with newer transitive SDK components were superseded. Hosted Cloudflare deployment was not exercised. Budgets remain cooperative and consume host-turn/executor delay; Workers can independently terminate waitUntil work. Panic recovery requires unwinding and is not guaranteed on an aborting WASM build.
App-demo, Fastly target/runtime qualification, and browser ingress were not separately rerun locally for these Cloudflare fixes; the applicable hosted jobs remain separate verification obligations.
Checklist
{id}syntax (not:id)edgezero_core(nothttpcrate)KvRegistry/ConfigRegistry/SecretRegistry(not the legacy single-handle setters) — existing store wiring is unchanged