You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The driver future owns the handler via `Rc<H>` and only needs `H` to
outlive the future. Parameterize `ServerHandle` and `serve` over a
lifetime so callers with non-`'static` handlers are supported.
For `'static` handlers (the expected common case), nothing changes
at the call site — inference picks `'static`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/runner-task-ipc/server-design.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ The IPC server runs per spawn execution **only when fspy is enabled**, letting t
9
9
1.**Server doesn't take a cancellation token.** The caller signals "stop accepting" via `StopAccepting::signal()`. The server has no awareness of external cancellation.
10
10
2.**Handler is moved in, returned out.** The caller doesn't keep a reference. The driver owns the handler; on drain completion it returns it by value. No self-reference, no `&H` lifetime.
11
11
3.**`Rc<H>` + `CancellationToken` internally** — both hidden from the public API.
12
-
4.**Driver is `!Send`, `'static`** — matches the existing execute pipeline shape (`LocalBoxFuture<'static, ...>` throughout).
12
+
4.**Driver is `!Send`**, lifetime bounded by `H`'s lifetime — if `H: 'static`, the driver is `'static`; if `H` borrows, the driver respects that.
@@ -115,11 +115,11 @@ if !fast_fail_token.is_cancelled() && !interrupt_token.is_cancelled() {
115
115
116
116
## Design-decision log
117
117
118
-
### Why `H: 'static`?
118
+
### Why no `'static` bound on `H`?
119
119
120
-
Storing the driver in `FspyState` without a lifetime parameter requires `LocalBoxFuture<'static, H>`, which requires `H: 'static`. The concrete `IpcRecorder` is naturally `'static` — it owns all its fields (RefCells, cloned env config).
120
+
The driver future _owns_the handler (via `Rc<H>` internally). It doesn't need to outlive `H` — it just needs `H` to outlive the future. So the signature is `serve<'h, H: Handler + 'h>` and the returned `ServerHandle<'h, H>` carries the lifetime. If the caller's `H` is `'static`, the driver is `'static`; if `H` borrows, the driver respects that.
121
121
122
-
An earlier direction ("don't require `'static` on Handler") was specifically to avoid `spawn_local`, which requires `'static` tasks. Requiring `'static`on the trait type is acceptable when the concrete handler naturally has no borrow.
122
+
If the caller wants to store `ServerHandle` in a struct without a lifetime parameter, they can use a `'static`handler (naturally satisfied by handlers that own all their state via `RefCell<...>` + cloned data).
0 commit comments