Repository navigation
Name the Spin adapter in the after-response capability error #515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prk-Jr
wants to merge
8
commits into
feature/478-cloudflare-after-response
from
feature/483-spin-after-response-error
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f48355c
feat: return an adapter-named capability error for Spin after-respons…
prk-Jr dd05d12
docs: state Spin's zero-budget 500 and widen the #512 overlap note
prk-Jr ec347a2
Merge PR #512 into PR #515 for outbound compatibility stack
aram356 da0471b
Merge PR #512 into PR #515 for outbound compatibility stack
aram356 b488957
Merge PR #512 into PR #515 for outbound compatibility stack
aram356 6f91275
Merge PR #512 into PR #515 for outbound compatibility stack
aram356 d178fdc
Merge PR #512 into PR #515 for outbound compatibility stack
aram356 ea0ee58
Merge PR #512 into PR #515 for outbound compatibility stack
aram356 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| //! Spin's after-response capability error. | ||
| //! | ||
| //! Spin does not run after-response tasks. Every converted request carries a scheduler that | ||
| //! rejects them with a `501` naming the Spin adapter, instead of core's generic error. | ||
|
|
||
| use std::time::Duration; | ||
|
|
||
| use edgezero_core::after_response::{AfterResponseHandle, AfterResponseScheduler}; | ||
| use edgezero_core::error::EdgeError; | ||
| use futures_util::future::LocalBoxFuture; | ||
|
|
||
| struct SpinAfterResponseUnsupported; | ||
|
|
||
| impl AfterResponseScheduler for SpinAfterResponseUnsupported { | ||
| #[inline] | ||
| fn schedule( | ||
| &self, | ||
| _budget: Duration, | ||
| task: LocalBoxFuture<'static, ()>, | ||
| ) -> Result<(), EdgeError> { | ||
| drop(task); | ||
| Err(EdgeError::not_implemented( | ||
| crate::AFTER_RESPONSE_UNSUPPORTED, | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| /// Handle inserted into every Spin request so registration fails with the Spin capability error. | ||
| pub(crate) fn unsupported_handle() -> AfterResponseHandle { | ||
| AfterResponseHandle::new(SpinAfterResponseUnsupported) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::unsupported_handle; | ||
| use crate::AFTER_RESPONSE_UNSUPPORTED; | ||
| use edgezero_core::http::StatusCode; | ||
| use std::cell::Cell; | ||
| use std::rc::Rc; | ||
| use std::time::Duration; | ||
|
|
||
| struct DropProbe(Rc<Cell<bool>>); | ||
|
|
||
| #[expect( | ||
| clippy::missing_trait_methods, | ||
| reason = "`Drop::pin_drop` is unstable (`pin_ergonomics`) and conflicts with `drop`" | ||
| )] | ||
| impl Drop for DropProbe { | ||
| fn drop(&mut self) { | ||
| self.0.set(true); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn registration_reports_spin_capability_error_and_drops_task_unpolled() { | ||
| let polled = Rc::new(Cell::new(false)); | ||
| let dropped = Rc::new(Cell::new(false)); | ||
| let probe = DropProbe(Rc::clone(&dropped)); | ||
| let observed = Rc::clone(&polled); | ||
|
|
||
| let error = unsupported_handle() | ||
| .schedule(Duration::from_secs(1), async move { | ||
| let _probe = probe; | ||
| observed.set(true); | ||
| }) | ||
| .unwrap_err(); | ||
|
|
||
| assert_eq!(error.status(), StatusCode::NOT_IMPLEMENTED); | ||
| assert_eq!(error.message(), AFTER_RESPONSE_UNSUPPORTED); | ||
| assert!(!polled.get(), "a rejected task is never polled"); | ||
| assert!(dropped.get(), "a rejected task is dropped at registration"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn zero_budget_is_a_programming_error_before_the_capability_error() { | ||
| let error = unsupported_handle() | ||
| .schedule(Duration::ZERO, async {}) | ||
| .unwrap_err(); | ||
|
|
||
| assert_eq!(error.status(), StatusCode::INTERNAL_SERVER_ERROR); | ||
| } | ||
| } | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,9 @@ | |||||||||||||||||
| //! | ||||||||||||||||||
| //! A handler registers a task through [`RequestContext::after_response`](crate::context::RequestContext::after_response). | ||||||||||||||||||
| //! The adapter starts it once the request's response attempt has ended at the adapter's terminal | ||||||||||||||||||
| //! egress boundary, and cancels it when its budget runs out. Adapters without support install no | ||||||||||||||||||
| //! handle, 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, so registration fails with | ||||||||||||||||||
| //! [`EdgeError::NotImplemented`]. | ||||||||||||||||||
|
Comment on lines
+5
to
+7
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| use std::fmt; | ||||||||||||||||||
| use std::sync::Arc; | ||||||||||||||||||
|
|
@@ -13,7 +14,8 @@ use futures_util::future::LocalBoxFuture; | |||||||||||||||||
|
|
||||||||||||||||||
| use crate::error::EdgeError; | ||||||||||||||||||
|
|
||||||||||||||||||
| /// Message returned when the adapter installed no after-response scheduler for the request. | ||||||||||||||||||
| /// Message returned when no after-response scheduler is installed for the request. Adapters that | ||||||||||||||||||
| /// install a rejecting scheduler may use their own message. | ||||||||||||||||||
| pub const AFTER_RESPONSE_UNSUPPORTED: &str = | ||||||||||||||||||
| "after-response tasks are not supported by this adapter"; | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
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
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
38 changes: 38 additions & 0 deletions
38
docs/superpowers/plans/2026-11-18-spin-after-response-error.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Spin after-response capability error — plan | ||
|
|
||
| Design: [`2026-11-18-spin-after-response-error-design.md`](../specs/2026-11-18-spin-after-response-error-design.md). | ||
| Issue: #483. Base branch: `feature/476-after-response-tasks` (PR #509). | ||
|
|
||
| ## Tasks | ||
|
|
||
| 1. **Failing tests first.** | ||
| - `crates/edgezero-adapter-spin/src/after_response.rs` host unit tests: the handle returns | ||
| `501` with `AFTER_RESPONSE_UNSUPPORTED`; the task is never polled and is dropped at | ||
| registration (drop probe uses core's `missing_trait_methods` expect pattern); a zero budget | ||
| through the Spin handle returns `500`. | ||
| - `crates/edgezero-adapter-spin/tests/contract.rs` (`ingress_contract`) wasm32 test: a real | ||
| `SpinRequest` dispatched through `test_support::dispatch_request` to a route that registers a | ||
| task gets a `501` registration error with the Spin message (the handler echoes status and | ||
| message in a `200` body); the task is never polled and is dropped once; a control route on | ||
| the same app returns `200`. | ||
| 2. **Implement.** Define `AFTER_RESPONSE_UNSUPPORTED` ungated in `lib.rs` (no `pub use`, which | ||
| the `restriction` lint group denies). Add the module (gated like `ingress`: `any(test, | ||
| all(feature = "spin", target_arch = "wasm32"))`), insert the handle in | ||
| `into_core_request_head`. | ||
| 3. **Docs.** `capabilities.md` bullet, `adapters/spin.md` section, `CHANGELOG.md` line, and core's | ||
| `after_response` module and constant docs (an unsupported adapter may install a rejecting handle). | ||
| 4. **Negative control.** Run the contract test with the constant present but without the module, import and | ||
| insertion; the wasm32 contract test must fail with the | ||
| generic core message. Restore. | ||
| 5. **Verification.** | ||
| - `cargo fmt --all -- --check` | ||
| - `cargo clippy --workspace --all-targets --all-features -- -D warnings` | ||
| - `cargo test --workspace --all-targets` | ||
| - `cargo check --workspace --all-targets --features "fastly cloudflare spin"` | ||
| - `cargo check -p edgezero-adapter-spin --target wasm32-wasip2 --features spin` | ||
| - Spin wasm clippy (`spin`, `spin,test-utils`) as in `format.yml` | ||
| - Spin wasm32 `--test contract --test sdk_resources` under Wasmtime 48.0.2 (the CI sdk-tests phase) | ||
| - `node scripts/check_outbound_docs_contract.mjs`; docs `npm run lint && npm run format` | ||
| - Runtime: `spin up` (4.1.0) on a scratch copy of `examples/app-demo` outside the repo, with a | ||
| route whose task would log `AFTER_TASK_RAN`; expect `501` with the Spin message, no marker | ||
| in the logs after 2 s, and an existing route `200`. |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
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_unpolledand the wasm32 contract test both check this with poll and drop probes.