Skip to content

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

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

prk-Jr wants to merge 46 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 rejecting scheduler. Core checks budget and task limits first; registrations that pass those checks receive 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.
  • Installed-handle validation takes precedence. Without a handle, Spin used to return generic 501 for any budget. With a handle installed, zero or over-30-second budgets return 500 before the scheduler runs; the 64-task check also precedes scheduling. Managed Cloudflare requests on the current Enable Cloudflare after-response tasks with gated waitUntil #512 base have the same validation precedence.
  • 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), which includes #509 and its portable API/capability. #509 was the original design base. The Cloudflare implementation of #478 is already in the current 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 (historical comparison): a git merge-tree comparison with #496 reported 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, src/context.rs Distinguish no-handle capability errors from installed-handle validation precedence
docs/superpowers/specs/2026-11-17-after-response-tasks-design.md One-line pointer to this follow-up
Capability, handler and Spin guides; CHANGELOG.md Document Spin's error after core registration checks; retain unsupported capability
docs/superpowers/{specs,plans}/2026-11-18-spin-after-response-error*.md Design and plan

The test-utils dispatch_ingress_* bridges build core requests without a handle and retain core's generic 501. send_assembly_error has no app or handlers and does not register tasks.

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.

Review follow-up

bbcb62f1 corrects validation precedence across the public docs and module introductions: no handle returns generic 501 for any budget; an installed handle checks zero/over-limit budget and task capacity before calling a rejecting scheduler. The spec/plan distinguish original #509 history from the current #512 base and record completed changelog/capability reconciliation. Executable Rust and tests are unchanged.

Local evidence for the documentation commit bbcb62f (Rust 1.98.1, Node 24.20.0): all five required Cargo gates; isolated harness (680 passed, 4 ignored); nine core and two Spin focused tests; docs lint/Prettier/build and outbound-doc contract; strict native public rustdoc. Independent source review confirmed comment-only Rust changes and preserved unpolled disposal/slot rollback.

Additional strict private-rustdoc runs expose existing links in unchanged Spin files (config_store, key_value_store, kv_pagination, request); those broader private-doc configurations remain unqualified. No warnings were suppressed. Hosted Actions for bbcb62f later failed as described below. No new hosted deployment or full runtime qualification was performed for this documentation follow-up.

CI follow-up

CI follow-up cb37b00e refreshes only pin-project-lite version/checksum to 0.2.19 in the six active lockfiles after 0.2.17 was yanked. Fresh offline logging and generated AWS/Dynamo/celld proofs pass. A separate test-only correction supplies scoped fixture identity and a fake compiler so cancellation tests reach fake Cargo before their unchanged startup deadline; production fingerprinting is unchanged. All five required Cargo gates, three WASM target checks and the full harness (681 passed, 4 ignored; two test threads) pass. The earlier macOS shutdown race is not claimed fixed. All 30 hosted checks now pass on cb37b00, including the workspace and genuine generated-consumer CLI jobs. The processed Rust CodeQL analysis is clean (27 rules, no errors, warnings or findings), as are the other configured languages.

The bbcb62f hosted workspace/CLI failures reproduced with a pristine cache containing only the locked, now-yanked 0.2.17. Locked fetch with 0.2.19 restores eligible dependencies for genuine fresh offline consumers; no fixture lockfile was injected and no network access was added to Rust tests. The generated runtime proofs retain their build and startup assertions.

The separate native AWS advisory failed while pulling its pinned Moto image, before contract tests ran. The immutable pin is unchanged; public-registry availability does not qualify Docker execution. Earlier default-concurrency macOS harness failures are retained as a limitation; the final full pass uses two test threads. The existing private-rustdoc limitations above remain.

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. The earlier da0471b7 revision had 29 reported passing hosted checks; that result is historical and does not verify the current review-follow-up commit.

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. These historical results do not qualify the current revision; see the review follow-up above for current local evidence and hosted status.

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.

Fixtures that poll a non-blocking std TcpListener read the accepted
stream with set_read_timeout. macOS accept(2) copies O_NONBLOCK to the
accepted socket (Linux does not), so those reads failed with WouldBlock
at once and tests failed at random on macOS under parallel load.

Add a small accept_blocking helper per crate (store-aws, adapter-axum
tests, cli tests) that restores blocking mode, route all nine accept
sites through it, and cover it with a test that fails on macOS when the
accepted stream does not wait for its read timeout.
Four production_hosting tests drive the native proxy fixture, which binds
its upstream socket to 127.0.0.2 or 127.0.0.3 so the server sees distinct
peers. Linux routes all of 127.0.0.0/8 to lo; macOS lo0 has only
127.0.0.1, so the bind fails with EADDRNOTAVAIL, the relay drops the
connection, and the tests see an empty response or TLS UnexpectedEof.

Ignore them off Linux with a reason that gives the lo0 alias commands
needed to run them with --ignored.
The SDK's 100 ms attempt deadline runs from the start of the attempt.
Under parallel load the child can be descheduled between the TCP connect
and the request write, so the SDK correctly abandons the connection
before sending anything. The fixture treated that as fatal ("SDK closed
before request headers"), which failed the test about once in 20 full
store-aws runs on macOS.

The test now uses a fixture that accepts every attempt and never
answers, recording whether the client closed each connection itself. The
operation budget is 10 s, so only the attempt deadline can close a held
connection within the 5 s bound. The test asserts that every attempt was
closed that way, that the SDK made 1 to 3 attempts, and that any full
request named the fixture ARN. Removing the attempt timeout from the
provider makes the test fail.
macOS marks a new socket close-on-exec only after socket() returns. When
a parallel test spawned a fixture process in that gap, the child
inherited another test's port reservation and kept it bound after the
test released it. That test's fixture server then failed to bind
(AddrInUse); lsof showed another fixture process holding the port as a
CLOSED socket. Separately, a released reservation could be served by
another test's server during a "nothing answers" check. Together these
failed 6 of 20 macOS runs.

Reservations and fixture spawns now hold one lock, so they never
overlap. Tests that assert nothing answers keep their reservation bound,
but not listening, until the check is done.
production_hosting: client streams from Server::socket and raw_request
also take the reservation/spawn lock, so a concurrently spawned fixture
cannot inherit one and keep the connection open after the test drops it.
Because a held reservation always refuses connections, "nothing answers"
checks now also assert that the server never reached its listener bind.

Secrets Manager: the holding fixture drains every queued connection
after the child exits before counting attempts, so a starved fixture
thread cannot undercount them.
aram356 added a commit that referenced this pull request Dec 1, 2026
Take PR #515's head with the round 12 review fixes of the whole identity chain and, through its second base PR #519, the macOS fixture fixes and loopback trusted-proxy tests.
Bring in PR #275's Viceroy repair, which fails an if-generation-match
insert when the key has no live entry, so a stale generation cannot
recreate a deleted key. The merge is clean.
Bring in PR #275's Viceroy repair, which fails an if-generation-match
insert when the key has no live entry, so a stale generation cannot
recreate a deleted key. The merge is clean.
Bring in PR #275's Viceroy repair, which fails an if-generation-match
insert when the key has no live entry, so a stale generation cannot
recreate a deleted key. The merge is clean.
aram356 added a commit that referenced this pull request Dec 2, 2026
Take PR #515's new head, which carries PR #275's Viceroy repair that fails an if-generation-match insert when the key has no live entry.
@aram356

aram356 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Round 12 identity realignment: rc/identity (#495) is now at 38cb74fe. This branch fast-forwarded from ea0ee581 to 4cc226a5:

This PR also merges #519. rc/identity already held #519's old head, so only a chain that carries #519's new test fixtures merges into it without a resolution. #519's changes show in this PR's diff until #519 lands.

Each merge message says what it carries and how any conflict was resolved.

prk-Jr and others added 7 commits December 2, 2026 23:13
Bring in PR #275's lockfile update, which moves the yanked
pin-project-lite, chacha20 and yoke-derive versions to their
replacements. Its pin-project-lite change is the same text as this PR's
own update, so the merge is clean.
Bring in PR #512's new head, which clarifies Cloudflare after-response
registration ownership and carries PR #509's and PR #517's updates. The
merge is clean.
Bring in PR #519's new head, which shares native test fixtures and
strengthens timeout evidence. The merge is clean.
aram356 added a commit that referenced this pull request Dec 3, 2026
Take PR #515's new head, which brings the yanked-crate lockfile updates
from PR #275 and PR #454, the owner updates on PR #509, #512, #515 and
#519, and PR #514's Spin geo hardening through PR #517.
@aram356

aram356 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Round 15 identity realignment: rc/identity is now at ef5cbf308. This branch fast-forwarded from cb37b00e6 to 7d6a8cde0:

Each merge message says what it carries and how any conflict was resolved.

@aram356

aram356 commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Review follow-up: fixes committed to this branch

A full review of this PR turned up the problems below; each would otherwise have needed a follow-up ticket, so it is fixed on this branch instead. Every item names its commit.

  • The docs listed an exhausted task limit as a Spin 500 cause, which cannot happen. A refused registration gives its slot back (fetch_sub in AfterResponseHandle::schedule) and Spin's scheduler refuses every task, so a Spin app's 65th registration returns the same 501 as the first; error handling written to the documented contract would take the wrong branch. 1ee3a46 drops the task-limit cause from the capability matrix and the Spin guide and states that only a zero or over-30-second budget returns 500. Docs only; core's a_refused_task_does_not_use_a_slot and Spin's registration_reports_spin_capability_error_and_drops_task_unpolled cover the behaviour. This corrects the description given in the R1 thread on core after_response.rs.

Fixes made on the PRs below this one in the stack were merged into this branch with merge commits, including #519's (the production-hosting bad-address case expects client 192.0.2.1 after #519 moved the proxy source, and the store-aws child-process helper carries #[expect(clippy::too_many_lines)]).

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