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. |
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, base54e7a4b8), 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.Test plan
Current local verification covers signed commit
136ed0d8with Rust 1.98.1, Node.js 24.20.0, and lock-matched wasm-bindgen 0.2.128. Hosted CI for this revision is pending; earlier green runs do not verify this commit.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