Skip to content

Enable Cloudflare after-response tasks with gated waitUntil - #512

Open
prk-Jr wants to merge 1 commit into
feature/476-after-response-tasksfrom
feature/478-cloudflare-after-response
Open

prk-Jr wants to merge 1 commit into
feature/476-after-response-tasksfrom
feature/478-cloudflare-after-response

Conversation

@prk-Jr

@prk-Jr prk-Jr commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Enable RequestContext::after_response(budget, task) on Cloudflare Workers so background work starts after terminal response egress without delaying delivery.
  • Retain tasks with gated waitUntil promises, give each task a fresh outbound callback scope, and cancel pending work at min(budget, 30 seconds) after release.
  • Report after-response-tasks as BoundedCooperative for Cloudflare and document Workers lifetime limits, registration closure, and lack of persistence or retries.

Stacked on #509 (feature/476-after-response-tasks, base c3ba7e56), which supplies the portable task API and response-egress foundation. This PR targets that branch; its changes are the Cloudflare implementation of #478.

Changes

Crate / File Change
edgezero-adapter-cloudflare/src/after_response.rs, src/lib.rs Add the request-local release gate and bounded local task scheduler; reject registration after release.
edgezero-adapter-cloudflare/src/request.rs, src/response.rs Install the scheduler in shared dispatch and keep release ownership through native handoff, stream termination, fallback, cancellation, and abandoned dispatch.
edgezero-adapter-cloudflare/src/cli.rs Advertise BoundedCooperative support and update the capability test.
edgezero-adapter-cloudflare/tests/contract.rs and colocated tests Cover service/prebuilt dispatch, streaming release, budgets, stale handles, request isolation, fresh outbound scopes, timeout cancellation, and terminal error paths.
Cloudflare, capability, and handler guides; CHANGELOG.md Describe effective budgets, platform limits, and outbound request construction inside tasks.
scripts/check_outbound_docs_contract.mjs Keep the documented capability matrix aligned with adapter reporting.
Design and implementation documents Record the contract, architecture, verification scope, and implementation plan.

Closes

Closes #478

Test plan

Local checks used Rust 1.98.1 and Node.js 24.20.0. GitHub CI remains pending.

  • cargo test --workspace --all-targets
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • cargo check --workspace --all-targets --features "fastly cloudflare spin"
  • WASM builds: wasm32-wasip1 (Fastly) / wasm32-wasip2 (Spin) / wasm32-unknown-unknown (Cloudflare) — Cloudflare Worker built and Spin target checked; Fastly target build not rerun for this Cloudflare change.
  • examples/app-demo workspace: cd examples/app-demo && cargo test --workspace --all-targets
  • Docs build: cd docs && npm run lint && npm run format && npm run build
  • Manual testing via edgezero serve --adapter axum — runtime verification used Cloudflare below.
  • Other: Cloudflare native crate tests; strict Cloudflare WASM Clippy with cloudflare and cloudflare,test-utils; Cloudflare WASM unit/contract suites and browser ingress suite; outbound documentation contract check.
  • Negative gate control: deliberately bypassing release in an isolated copy makes the streaming contract test fail because task cancellation occurs while the stream is still active (1, expected 0).
  • Public run_app consumer under local Wrangler 4.83/workerd: response-first return about 3 ms versus an inline-delay control about 306 ms; delayed completion, streaming/full post-egress budget, pending-task drop, fresh outbound transport and old-scope revocation, 204 handoff, 500 fallback, and overlapping request gates all passed.

The local workerd run exercises the actual Worker artifact. Hosted Cloudflare deployment was not exercised. Budgets are cooperative, and Workers independently limits the shared waitUntil lifetime; these checks do not establish durable completion. Panic isolation requires an unwinding build; an aborting WASM panic can terminate the invocation.

Checklist

  • Changes follow CLAUDE.md conventions
  • No Tokio deps added to core or adapter crates
  • Route params use {id} syntax (not :id)
  • Types imported from edgezero_core (not http crate)
  • Store wiring goes through KvRegistry / ConfigRegistry / SecretRegistry (not the legacy single-handle setters) — existing store wiring is unchanged
  • New code has tests
  • No secrets or credentials committed

@prk-Jr prk-Jr self-assigned this Nov 18, 2026
@prk-Jr
prk-Jr marked this pull request as ready for review November 18, 2026 09:28
@prk-Jr prk-Jr linked an issue Nov 18, 2026 that may be closed by this pull request
2 tasks

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.

After-response work on Cloudflare (waitUntil)

1 participant