Skip to content

Name the Spin adapter in the after-response capability error - #515

Open
prk-Jr wants to merge 8 commits into
feature/478-cloudflare-after-responsefrom
feature/483-spin-after-response-error
Open

prk-Jr wants to merge 8 commits into
feature/478-cloudflare-after-responsefrom
feature/483-spin-after-response-error

Conversation

@prk-Jr

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

Copy link
Copy Markdown
Collaborator

Summary

  • Spin does not run after-response tasks. Before this change, ctx.after_response(budget, task) on Spin fell through to core's generic 501 after-response tasks are not supported by this adapter. That error looks the same as a bare core context or an adapter that forgot to install a scheduler.
  • Every converted Spin request now carries a scheduler that rejects the task. It returns 501 Not Implemented (kind not_implemented) with after-response tasks are not supported by the Spin adapter, exported as edgezero_adapter_spin::AFTER_RESPONSE_UNSUPPORTED. The task is dropped without being polled.
  • One deliberate status change. A zero budget on Spin used to return 501, because core found no handle and refused before checking the budget. It now returns 500, because core rejects a zero budget before calling any installed scheduler. Axum and Fastly already return 500 here (Add bounded after-response tasks on Fastly and Axum #509 treats a zero budget as a programming error). Cloudflare also returns 500 at the current Enable Cloudflare after-response tasks with gated waitUntil #512 base.
  • No change to the capability matrix: Spin stays Unsupported, so required = ["after-response-tasks"] still refuses Spin at build/serve/deploy.

Stacked on #512 (feature/478-cloudflare-after-response at 953f0031), which includes #509 (a5c176e1) and its portable API/capability. #483 is blocked by #476. The Cloudflare implementation of #478 is already in this base; the capability guide and changelog are reconciled with it.

Design: docs/superpowers/specs/2026-11-18-spin-after-response-error-design.md; plan: docs/superpowers/plans/2026-11-18-spin-after-response-error.md.

Integration note: a current git merge-tree comparison with #496 reports conflicts in Axum response conversion, Cloudflare/Spin contracts, and core error/extractor code. These siblings need reconciliation when integrated.

Changes

Crate / File Change
edgezero-adapter-spin/src/after_response.rs (new) Rejecting AfterResponseScheduler: drops the task and returns EdgeError::not_implemented(AFTER_RESPONSE_UNSUPPORTED); host unit tests: poll and drop probes, and zero budget returns 500
edgezero-adapter-spin/src/lib.rs Ungated pub const AFTER_RESPONSE_UNSUPPORTED; module gated like ingress
edgezero-adapter-spin/src/request.rs into_core_request_head inserts the handle. This covers run_app, run_app_with_platform, dispatch_app, AppExt::dispatch, dispatch, dispatch_with_kv_label and into_core_request
edgezero-adapter-spin/tests/contract.rs wasm32 contract test: a real SpinRequest through dispatch_request to a route that registers a task gets the Spin 501; the task is never polled and is dropped once; a control route returns 200
edgezero-core/src/after_response.rs Doc-only: an unsupported adapter may install no handle or a rejecting one
docs/superpowers/specs/2026-11-17-after-response-tasks-design.md One-line pointer to this follow-up
docs/guide/capabilities.md, docs/guide/adapters/spin.md, CHANGELOG.md Spin's error documented; changelog no longer lists Spin as pending
docs/superpowers/{specs,plans}/2026-11-18-spin-after-response-error*.md Design and plan

Not covered, by construction: send_assembly_error (no app, no handlers) and the test-utils dispatch_ingress_* bridges, which build core requests directly. Both keep core's generic 501.

Closes

Closes #483

This PR targets feature/478-cloudflare-after-response, so merging it into that branch does not automatically close the linked issue(s); close them manually or upon default-branch integration.

Test plan

Historical author-reported local verification below (original head unrecorded unless an explicit SHA is given). These results, counts, timings and negative controls were not rerun in this audit, and their underlying local logs were unavailable; checked boxes retain the original report. At the current head da0471b7, all 29 reported hosted checks are passing.

Local, Rust 1.98.1 (pinned) and Node 24.20.0:

  • cargo test --workspace --all-targets (2824 passed)
  • 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-wasip2 (Spin): cargo check -p edgezero-adapter-spin --target wasm32-wasip2 --features spin, plus Spin wasm clippy for spin and spin,test-utils. Fastly and Cloudflare are untouched and were not rebuilt.
  • examples/app-demo workspace: cd examples/app-demo && cargo test --workspace --all-targets (68 passed)
  • Docs build: cd docs && npm run lint && npm run format && npm run build; node scripts/check_outbound_docs_contract.mjs
  • Manual testing via edgezero serve --adapter axum: not applicable (Spin-only change); runtime check below used Spin.
  • Other: Spin wasm32 --test contract --test sdk_resources under Wasmtime 48.0.2 (36 + 25 passed); adapter_capability_matrix_matches_contracts (--features cli).
  • Other, negative control: the contract test fails on the body comparison when the handle is not installed. Spin then returns core's generic message.
  • Other, runtime under spin up 4.1.0. A scratch copy of examples/app-demo got an /after-task route, which propagates the registration error with ? and whose task would print a stderr marker. The same copy was built from this branch and from Add bounded after-response tasks on Fastly and Axum #509:
    • This branch: 501 {"error":{"kind":"not_implemented","message":"after-response tasks are not supported by the Spin adapter","status":501}} on two consecutive requests.
    • Add bounded after-response tasks on Fastly and Axum #509 base: the same route returns 501 ... not supported by this adapter.
    • Task never runs: no task marker in the component stderr 3 s later. A control route that prints inline shows that stderr is captured.
    • Existing routes: / and /echo/spin return 200 on both builds.

Hosted Spin (Akamai Functions) was not exercised. Current reported GitHub checks are passing.

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); store wiring is unchanged
  • New code has tests
  • No secrets or credentials committed

…e tasks

Spin does not run after-response tasks. Every converted Spin request now
carries a scheduler that rejects registration with 501 Not Implemented and
the message exported as edgezero_adapter_spin::AFTER_RESPONSE_UNSUPPORTED,
instead of core's generic "not supported by this adapter" message. The task
is dropped without being polled.

The handle is installed in into_core_request_head, which every native Spin
entry point uses (run_app, run_app_with_platform, dispatch_app,
AppExt::dispatch, dispatch, dispatch_with_kv_label, into_core_request).
The capability matrix already reports Spin Unsupported, so
required = ["after-response-tasks"] still refuses Spin.

Tests: host unit test for the scheduler; wasm32 contract test dispatching a
real SpinRequest. Docs: capabilities, Spin guide, changelog, core
after_response docs, design and plan.
@prk-Jr prk-Jr self-assigned this Nov 18, 2026
@prk-Jr prk-Jr changed the title Return an adapter-named capability error for Spin after-response tasks Name the Spin adapter in the after-response capability error Nov 18, 2026
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.
@prk-Jr
prk-Jr added this pull request to stack #516 November 18, 2026 18:17
@prk-Jr prk-Jr linked an issue Nov 18, 2026 that may be closed by this pull request
2 tasks
@prk-Jr
prk-Jr marked this pull request as ready for review November 18, 2026 19:04
@aram356
aram356 removed this pull request from stack #516 November 19, 2026 05:02
@aram356
aram356 changed the base branch from feature/476-after-response-tasks to feature/478-cloudflare-after-response November 19, 2026 05:03
@aram356
aram356 added this pull request to stack #511 November 19, 2026 05:03
aram356 added a commit that referenced this pull request Nov 19, 2026
#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.
@aram356

aram356 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

For Trusted Server's identity integration chain, this PR now stacks on #512 instead of #509: the two conflicted in CHANGELOG.md and docs/guide/capabilities.md, so one of them had to land second. ec347a2c merges #512's head cdc232c8. The changelog takes #512's capability wording without "(tracked in #483)", which this PR removes, then this PR's Spin 501 and zero-budget 500 bullet; capabilities.md keeps #512's Cloudflare waitUntil bullet and replaces its Spin line with this PR's. The base is now feature/478-cloudflare-after-response, and the PR sits above #512 in stack 511. No behavior or test changes.

Checked locally at ec347a2c: cargo fmt, workspace clippy with all features, both Fastly clippy runs, the wasm feature check, cargo test --workspace --all-targets (3,118 passed), the Spin contract tests under Wasmtime (41), and the per-adapter clippy matrix, all passing.

Takes #512's new head 953f003, which carries #509's new tests for guarded
writes inside after-response tasks. The merge is clean, and this PR's tree
changes only by those tests.
aram356 added a commit that referenced this pull request Nov 20, 2026
#509 (a5c176e) adds test coverage for guarded writes inside after-response
tasks on Axum and Fastly. #512 and #515 each merged the PR below them, so
this merge is clean and the branch tree equals #515's head.
@aram356

aram356 commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), da0471b7 merges #512's new head 953f0031, which carries #509's new after-response tests. The merge is clean, and CI passes 29 of 29. rc/identity took this head as the plain merge b4d5ba87.

Bring in main's Fastly SDK 0.13.3 upgrade (#529) with Viceroy 0.22.0
and the Fastly CLI 17.2.0 upgrade (#531), with PR #275's exact pins at
0.13.3 and url 2.5.9, its Viceroy readiness repair on 0.22.0 and its
typed Image Optimizer unavailability check for SDK 0.13.3.
aram356 added a commit that referenced this pull request Nov 25, 2026
Take PR #515's updated tip, which carries main's Fastly SDK 0.13.3
upgrade (#529) with Viceroy 0.22.0 and the Fastly CLI 17.2.0 upgrade
(#531), PR #275's drain of declared uploads before an early-response
HTTP/1 close, and the macOS test fixes from PRs #407 and #414. It
merges without conflicts.
Bring in PR #275's installation of the wasm32-unknown-unknown target
before the Viceroy 0.22.0 readiness repair builds, which the fastly
wasm tests and Portable record contracts (Fastly) jobs need.
aram356 added a commit that referenced this pull request Nov 25, 2026
Take PR #515's updated tip, which carries PR #275's installation of the
wasm32-unknown-unknown target before the Viceroy 0.22.0 readiness
repair builds. It merges without conflicts.
@aram356

aram356 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed b488957a and 6f912751, two merges of #512's new heads. b488957a takes EdgeZero main's Fastly SDK 0.13.3 upgrade (#529), with Viceroy 0.22.0 and the Fastly CLI 17.2.0 upgrade (#531), with #275's exact pins at 0.13.3 and url 2.5.9, its Viceroy readiness repair on 0.22.0, its typed Image Optimizer unavailability check and its drain of declared uploads after an early response on Axum. 6f912751 takes #275's d8cd85c8, which installs the wasm32-unknown-unknown target before the Viceroy 0.22.0 readiness repair builds, as the fastly wasm tests and Portable record contracts (Fastly) jobs need. Both merges had no conflicts.

Bring in PR #275's atomic conditional KV insert in the Viceroy readiness
repair, and the production hosting tests' held port reservations and
spawn-token respawn from PR #406 up, with each later PR's tests reading
the live host's address.
aram356 added a commit that referenced this pull request Nov 26, 2026
Take PR #515's updated tip, which carries PR #275's atomic conditional
KV insert in the Viceroy readiness repair and the production hosting
port reservation and respawn fixes. It merges without conflicts.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed d178fdc6, a merge of #512's new head that brings #275's 41cdf035, which makes conditional KV inserts atomic in the Viceroy readiness repair, as the Fastly record contract's native race needs, and the production hosting tests' held port reservations and spawn-token respawn from #406 up, with each later PR's tests reading the live host's address. It had no conflicts.

Bring in PR #275's batch cutoff test fix, which advances the test clock
when the request arms its own deadline instead of after dispatch, and
the AWS emulator proofs' readiness markers from PRs #414 and #510, now
published by rename.
aram356 added a commit that referenced this pull request Nov 26, 2026
Take PR #515's updated tip, which carries PR #275's batch cutoff test
fix and the AWS emulator proofs' readiness markers published by rename.
It merges without conflicts.
@aram356

aram356 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

For the identity integration branch (#495), I pushed ea0ee581, a merge of #512's new head that brings #275's 0e2a58ae, which fixes an intermittent failure of the batch cutoff test by advancing its clock when the request arms its deadline timer, and the AWS emulator proofs' readiness markers from #414 and #510, now published by rename. It had no conflicts.

aram356 added a commit that referenced this pull request Nov 27, 2026
PR #524 (outbound mTLS client identities, #523) belongs to no identity
epic, and PR #522 (portable DynamoDB and celld record providers on
Fastly, #474) is still a draft. #524 is stacked on #522, so both leave
together.

This commit reverts their net changes. Its tree is rc/identity as it
was before #522 (654f546) merged with the current tips of #519, #515,
#502, #469 and #536, the branch's remaining lines. #514 and #517 are
already inside them. The rebuild merges without conflicts, and the
change touches only the 113 paths that #522 and #524 changed against
#517.

Three files differed from a plain reverse of the two PRs because of the
conflict resolutions in 7616c85 and b3a45df. Each keeps the other
lines' code and drops only #522's or #524's:

- crates/edgezero-adapter-axum/src/cli.rs keeps the capability matrix
  test's lint expectation and drops #524's client identity test.
- crates/edgezero-adapter-fastly/src/request.rs keeps the after-response
  handle and wrapper and drops #522's deferred portable KV registry.
- crates/edgezero-store-aws/src/dynamodb_records_tests.rs drops imports
  used only by #522's tests.

Merging a later tip of #522 or #524 will not restore this code, because
git treats their earlier commits as already merged. Bringing them back
needs a revert of this commit first.

@dhruv8sh dhruv8sh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no issues, so I'm approving with no comments.

With this change, Spin attaches a rejecting after-response scheduler to every converted request in into_core_request_head. Registering a task returns a 501 whose message names the Spin adapter (AFTER_RESPONSE_UNSUPPORTED), and the task is dropped without ever being polled.

  • Zero budget: AfterResponseHandle::schedule checks budget.is_zero() before it calls the scheduler. A zero budget therefore now returns 500 on Spin, the same as on Axum and Fastly. That is a deliberate behaviour change, and the CHANGELOG and docs record it.
  • Feature gate: the module is gated on any(test, all(feature = "spin", target_arch = "wasm32")), which matches how request.rs is gated. It has no spin_sdk dependency, so its unit tests run on the host.
  • Tests: host unit tests cover the 501 message and that the rejected task is dropped unpolled. A wasm32 contract test sends a real SpinRequest through dispatch and checks the same result, with a control route that still returns 200.
  • Docs: the capabilities guide, the Spin adapter guide, the CHANGELOG and core's doc comments all agree with the new behaviour.

I couldn't run any commands, so I haven't confirmed CI (fmt, clippy, tests) myself.

@dhruv8sh dhruv8sh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review

Summary

This PR installs a rejecting AfterResponseHandle on every converted Spin request. Registering an after-response task now returns a 501 that names the Spin adapter (edgezero_adapter_spin::AFTER_RESPONSE_UNSUPPORTED) instead of core's generic message. The core docs, guides, CHANGELOG and design docs are updated to match. The change is small, correct and well tested. I found nothing blocking.

😃 Praise

  • The handle is inserted in into_core_request_head, which every production path shares (run_app, dispatch_app, the public into_core_request). The wasm32 contract test goes through that same path. The spec also states plainly what is not covered (send_assembly_error and the test-utils dispatch_ingress_* bridges).
  • The behaviour change is called out in the CHANGELOG and both guides. A zero budget now returns 500 instead of 501, because core's AfterResponseHandle::schedule rejects a zero budget before it reaches the scheduler. A host unit test pins that behaviour.
  • The new module needs no spin_sdk and uses the same gate as ingress (any(test, all(feature = "spin", target_arch = "wasm32"))). Its unit tests therefore run under plain host cargo test, and the request module (gated spin + wasm32) always finds after_response when it compiles.
  • The tests check that a rejected task is never polled and is dropped, not just which status comes back. Both the host unit test and the contract test use poll and drop probes, and the contract test has a control route on the same app.

Findings

Blocking

None.

Non-blocking

None.

📌 Out of Scope

  • The spec notes that Cloudflare (#478, PR #512) edits the same capabilities.md bullet and CHANGELOG line. Whichever PR lands second should check that the wording about Spin is still consistent.

_budget: Duration,
task: LocalBoxFuture<'static, ()>,
) -> Result<(), EdgeError> {
drop(task);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😃 Rejected task is dropped right away: The scheduler drops the task explicitly before returning the error, so a rejected task cannot sit around holding captured resources. registration_reports_spin_capability_error_and_drops_task_unpolled and the wasm32 contract test both check this with poll and drop probes.

@ChristianPavilonis ChristianPavilonis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Spin-specific 501, unpolled task disposal, and intentional zero-budget 500 match the intended behavior. Spin stays unsupported in the capability matrix. I found no runtime defects and left two non-blocking documentation comments.

Comment on lines +5 to +7
//! egress boundary, and cancels it when its budget runs out. Adapters without support install
//! either no handle or one that rejects every task, so registration fails with
//! [`EdgeError::NotImplemented`].

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R1 · Clarify when registration returns 501. On Spin, an installed handle rejects a zero budget with 500 before its scheduler runs. The Spin module intro makes the same unqualified claim at crates/edgezero-adapter-spin/src/after_response.rs:3–4.

Suggested change
//! egress boundary, and cancels it when its budget runs out. Adapters without support install
//! either no handle or one that rejects every task, so registration fails with
//! [`EdgeError::NotImplemented`].
//! egress boundary, and cancels it when its budget runs out. Adapters without support install
//! either no handle or one that rejects every task. With a positive budget, registration fails
//! with [`EdgeError::NotImplemented`]. An installed handle checks for a zero budget first
//! and returns an internal error. Without a handle, registration returns the generic
//! [`EdgeError::NotImplemented`] even for a zero budget.

`schedule_with` returned `501` before any budget check. With a handle installed, core's
`AfterResponseHandle::schedule` rejects a zero budget with `500` before the scheduler is called.
That is #509's rule for a programming error, and Axum and Fastly already behave this way.
Cloudflare, which still installs no handle, keeps `501` until #478.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R2 · Distinguish the original design base from the current PR base. #515 now targets #512, which already installs Cloudflare's scheduler on managed requests. Keep #509 as historical context here and in the plan, and update this spec's closing note to say the changelog and capability guide have already been reconciled.

Suggested change
Cloudflare, which still installs no handle, keeps `501` until #478.
Cloudflare had no handle on the original #509 base and returned `501` for a zero budget.
On the current #512 base, managed Cloudflare requests have a handle and return `500`.

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 capability error on Spin

4 participants