Repository navigation
Conversation
Add RequestContext::after_response(budget, task) and the adapter-facing AfterResponseScheduler/AfterResponseHandle in edgezero-core, plus the after-response-tasks manifest capability (Axum Native, Fastly BoundedCooperative, Cloudflare and Spin Unsupported). Axum spawns each task on the server's LocalSet, releases it when Hyper drops the response body, bounds it with a Tokio timeout inside its own outbound callback scope, and drains registered tasks on SIGTERM within the existing shutdown grace after connections settle. Fastly queues tasks per request lifecycle and drives them after the response is sent, inside the same callback scope, each raced against its budget. Adapters without a scheduler return 501 at registration. Closes #476.
Address self-review findings on the after-response task work: - Cover the Fastly registry lifecycle used by run_app and serve_app through send_request_with_registries_and_hooks_for_test, and assert that a prepare hook cannot replace the adapter scheduler. - Stamp each Fastly lifecycle with a generation so a retained handle is rejected instead of queuing into a later request. - Let an idle tracker win over an elapsed deadline in the Axum task wait, and log abandoned tasks on every shutdown exit path. - Classify Axum as BoundedCooperative, matching its await-point cancellation, and document AxumDevServer::run draining. - Add tests for the shared grace, a second signal during the task wait, Fastly outbound requests from a task, and native replacement. - Keep the handler example from failing pages on unsupported adapters and sync the design and plan documents with the code.
Move the abandoned-task warning from drain_tasks into run_owned through AfterResponseTracker::warn_abandoned, so the prebound serve() path and the unusable-deadline return also report cancelled tasks, exactly once. Exercise the prepare-hook override through the registry funnel test too.
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 now stacks on #517, the top of the line
One behavior change, from the port: the base records an Checked locally at |
Exercise the consumer path Trusted Server relies on for follow-up writes: - Axum: a conditional Add record write inside a task is acknowledged and readable by a later request, without delaying the response. - Axum: SIGTERM arrives while a request is in flight, the handler then registers a KV write; the request and the write both complete within the grace, the process exits 0, and the value survives a restart. - Fastly: a guarded record write inside a task lands after delivery. Ignored in CI because the bare Viceroy runner has no KV stores; run it from the adapter crate, whose runner loads the demo fastly.toml.
Summary
ctx.after_response(budget, task): the task starts once the response attempt ends at the adapter's terminal egress boundary, and is cancelled when its budget elapses. Axum drains registered tasks on SIGTERM within the existing shutdown grace. Adapters without support (Cloudflare, Spin for now) return501 Not Implementedat registration instead of dropping work silently.after-response-tasksmanifest capability so apps can declare itrequiredand havebuild/serve/deployrefuse adapters that cannot run it.Stacked on #406 (
issue-392-396-production-hosting-specate37e0df2), which carries #275, #499 and #460; this work needs #406's SIGTERM drain and #275's Fastly callback scope. Design:docs/superpowers/specs/2026-11-17-after-response-tasks-design.md; plan:docs/superpowers/plans/2026-11-17-after-response-tasks.md.Changes
edgezero-core/src/after_response.rs(new)AfterResponseScheduleradapter trait,AfterResponseHandleextension handle, 501 when absent, zero budget rejectededgezero-core/src/context.rsRequestContext::after_response(budget, task)edgezero-core/src/manifest.rsCapability::AfterResponseTasks(after-response-tasks)edgezero-adapter-axum/src/after_response.rs(new)spawn_localon the serverLocalSet, gated on a release signal,timeout(budget)inside a fresh outbound callback scope;watch-based task tracker; registration closes once releasededgezero-adapter-axum/src/{service,response}.rsAxumEgressBodyand fires when Hyper drops the body (final frame handed over, or early disconnect/cancellation)edgezero-adapter-axum/src/dev_server.rsdrain_taskswaits for the tracker after connections settle, under the same grace deadline (an idle tracker wins over an elapsed deadline); pending tasks at the grace are cancelled → existinggrace exhaustedfailure; abandoned tasks are logged on every exit path. Applies to production entrypoints,run_appandAxumDevServer::runedgezero-adapter-fastly/src/after_response.rs(new),request.rsfinish_request, tasks are drained inside the samewith_callbackscope (outbound and timers work), each raced against its budget; handle inserted only while armed, afterprepareextensions; each lifecycle has a generation so a retained handle is rejected;send_request_with_registries_and_hooks_for_testexposes therun_app/serve_appfunnel to contract testsedgezero-adapter-*/src/cli.rsBoundedCooperative(budget cancels at await/yield points), Cloudflare/SpinUnsupportedtests/after_response.rs), subprocess SIGTERM tests; Fastly host tests and Viceroy contract testscapabilities.md(new checked matrix),handlers.md,adapters/axum.md,adapters/fastly.md,CHANGELOG.md;scripts/check_outbound_docs_contract.mjschecks the new matrixCloses
Closes #476
Test plan
Local, Rust 1.98.1 / Node 24.20.0 (pinned versions):
cargo test --workspace --all-targetscargo clippy --workspace --all-targets --all-features -- -D warnings, plus the per-adapter wasm/native clippy matrix fromformat.ymland Fastly--features cli/--no-default-featurescargo fmt --all -- --checkcargo check --workspace --all-targets --features "fastly cloudflare spin"wasm32-wasip1(Fastly) /wasm32-wasip2(Spin) /wasm32-unknown-unknown(Cloudflare, core)examples/app-demoworkspace:cargo test --workspace --all-targets, fmt, clippynpm run lint && npm run format && npm run build;node scripts/check_outbound_docs_contract.mjs--test contract42/42,--lib357/357run_appregistry funnel fails its contract testprepareextensions fails the hook-override testsexamples/app-demowith a/after-taskroute (registers a task with a 1.5 s timer):run_app: the response arrives in ~1 ms and the task completes ~1.5 s later. SIGTERM right after the response waits ~1.5 s and exits 0. With a 1 s grace the task is cancelled, the process exits 1 withgrace exhausted, and the abandoned-task warning is logged.viceroy serve(0.21.0): the response arrives in ~1–2 ms and the task completes ~1.5 s later on two consecutive requests.spin upand Cloudflarewrangler dev --local:/after-taskreturns501withafter-response tasks are not supported by this adapter, while existing routes are unaffected.Not verified: deployed Fastly Compute and a production Axum container/ECS stop; Trusted Server consumer integration; hosted CI (pending on this push).
Notes and limitations
ResponseEgressOutcome::HostHandoff), not proof of client receipt. Tasks run whatever the outcome (completed, error response, disconnect).BoundedCooperativefor both. On Fastly a blocked hostcall cannot be preempted.serve_appinstance, and — when delivery did not commit — a caller-sent native replacement response, by at most the longest registered budget (documented trade-off; skipping would drop work silently).waitUntil) #478 (CloudflarewaitUntil) and After-response capability error on Spin #483 (Spin capability error naming the adapter).Checklist
{id}syntax (not:id)edgezero_core(nothttpcrate)KvRegistry/ConfigRegistry/SecretRegistry(not the legacy single-handle setters) — not touched