Repository navigation
Commit 11a395e
authored
feat(client): accept an AbortSignal per call and close the request on abort (#3200)
* feat(contracts,host-kit): declare the per-call AbortSignal and its requester-side guard
Declare `signal?: AbortSignal` once at the owning contract types — the per-call
overrides, the transport context, and the internal request envelope — so no
per-site guard repeats it (#3178). Add `createRequestGuard` to
@agent-device/host-kit/request beside the daemon-side cancellation machinery it
answers for: an already-aborted call is refused with `dispatched: 'no'`, and an
abort racing an in-flight send wins with the typed canceled-request error so a
custom transport that ignores the signal cannot outlive the caller's promise.
* feat(client): thread the per-call signal through the daemon client and both transports
Wire the declared signal from the client's execute seam down to the transport
context and the request guard, and from the built-in transport into both daemon
wires (#3178):
- `sendToDaemon` refuses an already-aborted call before daemon startup and
guards each client-side phase; an abort during the artifact upload now
combines with the lease beat's own signal so the upload stops for either
owner.
- The socket transport destroys its connection on abort, and the HTTP transport
destroys its request; either way the daemon sees a client disconnect and
marks the request canceled. Every settle path detaches the abort listener,
and the timeout timer is cleared on abort so an abort never triggers the
timeout path's runner sweep or daemon reset.
- Retries and fallback attempts start behind a refusal check, so nothing is
sent after an abort.
* refactor(host-kit): own the transport-facing canceled-request helpers in the guard module
`abortedRequestError` and `refuseAbortedRequest` complete the request-cancel seam
the daemon request transports consume, so every rejection a caller's abort
produces is built by the module that declares the cancellation contract rather
than restated per transport.
* test(client): cover the per-call AbortSignal on the client surface and both transports
#3178 acceptance: an abort before send sends nothing (`dispatched: 'no'`); an
abort mid-request closes that one request so the daemon marks it canceled
(`dispatched: 'unknown'`, proven daemon-side through the request-cancel
registry), and the daemon keeps serving follow-up requests. Client-level cases
pin the guard half: the signal rides the transport context, and a custom
transport that ignores it cannot outlive the caller's promise.
Regression evidence: all eight wiring cases fail on the pre-fix sources
(verified by running these files against fc7df6c's client/daemon-client/
transport) and pass with the fix.
* docs(client): document the per-call signal on every client method
#3178's Done-when: the public client docs list `signal`, including the
already-aborted refusal (`dispatched: 'no'`), the mid-flight cancel
(`reason: 'request_canceled'`), and the promise that an abort never takes the
timeout path's runner cleanup or daemon reset.
* test(daemon-client): carry the wire token in the abort fixtures' daemon requests
* test(daemon-client): prove an abort is never a timeout at the transport seam
Add the paired regression cases for #3178's never-a-timeout promise: with the
timeout seam mocked, an abort with an armed budget leaves the seam never
called, while the same budget without a signal reaches it. Counterfactual
verified: deleting the abort path's `clearTimeout` fails only the abort case.
Clear the ignoring-transport test's late resolve so it keeps no timer alive.
* fix(client): own the per-call guard beside its transport and answer the review
- Move the requester-side AbortSignal guard out of @agent-device/host-kit/request
into daemon-client-transport.ts, the module the CLI eager closure already
loads, so the caller-side half and the transport half share one owner and the
ADR-0019 loading-shape probe stops counting 9 extra modules against cli.ts and
the replay-port facade.
- Generate the request id in execute before guarding, so a canceled call names
itself in request.meta and matches the daemon's diagnostic for the same
request.
- Report dispatched 'no' when a guard is entered already aborted: the refusal
proves send never ran, so 'unknown' would suppress a safe retry.
- Keep a non-Error abort reason as the cause unchanged.
- Return before handleTransportError once a request is settled, so the error an
intentional destroy emits cannot log daemon_request_socket_error.
- Cut the remote-retry health probe on the caller's signal and recheck the signal
before timeout and retry handling, so a canceled call never reads as timed out.
- Forward the caller's abort into the lease beat, which owns its own connection.
- Prove the signal reaches the daemon through the DEFAULT transport: one
loopback test per transport drives createAgentDeviceClient with no injected
transport and asserts the daemon saw the cancel.
- Prove the RPC handler still serves after an HTTP cancellation, not just /health.
- Qualify the signal contract and the docs with the two phases the guarantee
does not cover: a response-artifact download already underway, and a canceled
one-shot replay's existing daemon cleanup.
* refactor(daemon-client): keep the guard's helpers module-local and name the beat's outcomes
The code-quality audit found two exports with no consumer outside the transport
module and two functions whose new branches pushed them over the complexity
threshold. Nothing imported the helpers, so the guard's error factory and its
send-attempt refusal stay module-private beside the two callers that use them.
The lease beat now says what a failed beat means — one path ends the protection,
one reports a transient miss — and the retry path names the budget a
deadline-capped probe proves, instead of inlining both decisions.
* test(provider-scenarios): resolve alert interactors per call from the request's execution metadata
The scenario gateway built its Apple interactor once at bind time with an empty runner
context, so an alert leg asked the runner for a request id it never had. While the client
sent no meta.requestId the unkeyed provider scope still matched, but every call now carries
one: the request-scoped scripted provider is keyed by (deviceId, requestId), the empty
lookup missed it, and the leg fell through to the local XCTest runner — which spawns real
tooling and hangs the in-process harness. Per-call resolution mirrors the production alert
binding, which projects the input's execution metadata into the interactor context.
* refactor(test): one per-call alert-leg resolver for the iOS scenario gateway
* test(daemon-client): destroy tracked sockets when a loopback abort case fails
net.Server.close() waits for accepted connections, and a hanging-handler request keeps
its connection open until the client's abort destroys it. When an assertion before that
fails, the daemon-side handler waits forever and close() hangs the lane, turning the
regression signal the abort tests exist to provide into a test timeout. Track the accepted
sockets and destroy them in teardown at the three socket suites whose handlers never
answer. http.Server already has closeAllConnections(); net.Server has no equivalent.
* chore(gates): ack the caller-signal digest on the HTTP health probe
The compatibleChanges entry must carry the post-change digest; the declaration moved when
the probe began composing the #3178 caller signal with its own timeout budget. The /health
request and accepted payload are untouched, so protocol 2 peers parse it exactly as before.
* docs(agents): name both request-cancellation seams
The caller's per-call abort guard moved beside the transports it serves, while
`@agent-device/host-kit/request` kept the daemon-side cancel registry and
progress. The declaration-site line still credited the whole seam to host-kit,
pointing the next reader at a module that no longer exports the guard.1 parent f2f3afa commit 11a395e
17 files changed
Lines changed: 1212 additions & 88 deletions
File tree
- packages/contracts/src
- src
- __tests__
- test-utils
- daemon-client
- __tests__
- test
- integration/provider-scenarios
- wire-compat
- website/docs/docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| |||
88 | 95 | | |
89 | 96 | | |
90 | 97 | | |
91 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
92 | 114 | | |
93 | 115 | | |
94 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
101 | 106 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
82 | 105 | | |
83 | 106 | | |
84 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
98 | 106 | | |
99 | 107 | | |
100 | 108 | | |
101 | 109 | | |
102 | 110 | | |
103 | 111 | | |
104 | 112 | | |
105 | | - | |
| 113 | + | |
106 | 114 | | |
107 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
108 | 123 | | |
109 | 124 | | |
110 | 125 | | |
| |||
0 commit comments