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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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