Demonstrates cooperative cancellation. The client submits a long-running
job, observes a few events, and sends job.cancel { reason }. The
runtime aborts the agent's ctx.signal; the agent observes the signal
between ticks, throws CancelledError, and the runtime emits a
terminal job.error with final_status: "cancelled".
Cancellation is cooperative in v1.0 — the runtime cannot force-kill
the agent function. Instead it gives the agent a 30 s grace period
(§7.4) to observe the signal and bail. If the grace expires, the
runtime emits the cancelled error anyway. The agent here checks
ctx.signal.aborted between ticks so cancellation is observed within
one tick (~100 ms).
In one terminal:
pnpm tsx examples/cancel/server.tsIn a second terminal:
pnpm tsx examples/cancel/client.ts- §7.4
job.cancel→ cooperative abort viactx.signal. - Terminal
job.error { final_status: "cancelled", code: "CANCELLED" }. handle.donerejects with the error (the client awaits it inside atryblock).- The 30 s grace timer is configurable on
ARCPServerviacancelGraceMs.
| Env var | Default | Used by |
|---|---|---|
ARCP_DEMO_PORT |
7883 |
server |
ARCP_DEMO_URL |
ws://127.0.0.1:7883/arcp |
client |
ARCP_DEMO_TOKEN |
demo-token |
both |