# Emergency stopping

The candidate implements [exclusive control](spec.md#exclusive-control) in the existing independent helper. The scoped native/WSL host, held-input, handback and interruption results complete #31; broader presentation and capability acceptance stays with its separate owners; see the [candidate results](validation.md#exclusive-control-candidate).

Use `/computer-stop` to stop the current computer-use operation without waiting for a tool response. Pi cancellation also stops the operation. Queued actions are cancelled, active work is signaled, and subsequent calls in that operation are rejected with `COMPUTER_USE_STOPPED`. A model turn, retry or custom continuation does not reset stopping; a genuine new user run does.

Operation settlement (`operation_end`) remains tracked but is exempt from stop-triggered cancellation. It must finish input cleanup, disarm protection and release ownership even when queued behind the cancelled action; cancelling settlement itself can strand the cleanup acknowledgment. The actual-worker regression queues settlement before stopping a preparation-blocked action and verifies ownership release without dispatching input.

## Current Windows listener

A small separate Windows process installs a low-level keyboard hook. It is armed by the internal `prepare_input` request and guarded native mutation paths, including background element scrolling; quiet reads and browser work do not arm it. Background element scrolling retains the cleanup lease while a synchronous provider call is outstanding, but never announces physical input to the presentation. Esc signals an operation-specific manual-reset Windows event directly, then notifies the worker. The listener never calls UI Automation and can signal while a native provider is blocked. During exclusive control, keyboard/mouse hooks consume ordinary physical input before application delivery. Physical Esc and the configured shortcut signal stop and are consumed; pressed keys/buttons whose down events were swallowed have their later releases drained. The helper tracks physical modifiers itself because suppressed key-down events do not update ordinary Windows key state. Status exposes aggregate blocked-event and held-input counts, without key/text logs. It also supports the personal extra shortcut and ignores injected keyboard events, so agent Escape actions do not stop themselves. See [indicator lifetime and preview](indicators.md).

If the listener process exits, the transport notifies the worker immediately, including during model thinking; the operation is blocked before later input preparation. Explicit native protection-loss/stop results also stop the operation. Hook handles do not prove that Windows retained hooks after a silent timeout. The user accepted this [first-release platform limitation](spec.md#exclusive-control); suppression and physical stop keys are not guaranteed after silent removal. Actual-host and scoped cleanup acceptance is recorded in the [#31 evidence](validation.md#control-interruption-acceptance).

The explicit stop control bypasses the worker request queue. The worker blocks the operation before cleanup, signals its listener/event if armed, cancels active and queued requests and retires the read-only desktop bridge. Retirement waits for confirmed child exit; failure to confirm exit retains the child handle and sticky failure, blocks replacement work and is not permission to release ownership. Worker stdin closure also retains ownership if prior stop cleanup was unconfirmed. If a worker exits after reporting active input without a cleanup acknowledgement, its client rejects replacement work instead of starting a new worker; this fail-closed state requires external investigation. Final settlement waits for this stop cleanup before releasing desktop ownership. Cancellation is not an instruction to replay any action.

## Current physical-input protocol

Pointer and keyboard actions use the cancellation event and report `inputReady: true` with an explicit `readyActions` list. See [pointer guards](pointer.md) and [text/clipboard cleanup](text.md) for pending physical acceptance. Each enabled action must:

1. Arm the independent listener, confirm exclusive-control acquisition and the required border before physical dispatch, and check the operation's cancellation event.
2. Check cancellation between input steps and releases every held key/button in `finally`.
3. Confirm input cleanup and physical-control release before retiring a native input bridge or releasing desktop ownership; an unconfirmed release retains ownership.
4. Handle listener failure and timeout without silently replaying input or claiming success.

Before physical dispatch, the worker now sends a private request-scoped preparation token and waits for the controlling client to acknowledge it. The client records the active-input lease before acknowledging; a missing or mismatched acknowledgement cannot start input. Stop or stdin closure while still waiting cancels preparation without dispatch. The worker clears the lease before dispatch only if preparation was cancelled; after dispatch, only the native cleanup acknowledgement clears it. This private worker/client protocol is not a public tool parameter. A raw older worker-protocol client that does not acknowledge `input_prepare` will stall before physical dispatch until it cancels or closes stdin; bundled clients use the updated acknowledgement. The real-worker protocol has deterministic coverage against disposable fake native processes; actual Windows input and crash behavior remain separate acceptance checks.

A blocked read-only UIA/capture process can be killed after a bounded grace period. Four [known-held cancellation/target-error cases](validation.md#known-held-input-release) now passed; this does not establish release after abrupt death of an input owner. Uncertain input retains its ownership and prevents replacement work.

## Validation

- `npm test` covers a busy disposable protocol peer, queued cancellation, same-operation rejection, custom-continuation rejection, Pi abort, new-user recovery and confirmed retirement of an unresponsive peer.
- After `npm run build`, `npm run test:stop` verifies real Windows hook registration, an initially unsignaled kernel event, signaling through the normal stop control, a distinct unsignaled event for the next operation, and worker rejection/recovery and a deliberately invalid pointer target refusal. It sends no keys or pointer input.
- The existing paired accessibility provider subset (`test:accessibility:report -- /path/to/reference --providers`) independently confirms the identified reader is alive after provider entry and absent after cancellation, before releasing its owned provider, followed by fresh-read recovery. This is native read-process cleanup, not held-input cleanup; see [provider evidence](validation.md#accessibility-comparison-evidence).
- A dedicated physical Esc run stopped busy typing in the Pi worker fixture and independently observed released keys; actual native Pi-host Esc subsequently passed; remaining WSL-host and held-input/control cases stay with #31. DSH host stopping is removed. Hook registration and explicit signaling are not reported as a physical-key test.

The [passive operation baseline](validation.md#passive-operation-evidence) records current results and reference source comparison. User-reported earlier Esc/command checks do not replace a recorded busy-input/held-key acceptance run. A rejected promise, hook registration or `cleanupConfirmed` alone cannot establish actual key/button release.

## Held-key acceptance boundary

Neither Pi nor DSH exposes a public key-down/hold/key-up operation; each `keypress` dispatches a complete chord. Observing a modifier up after cancellation does not establish that it was held when cancellation arrived. The legacy Pi-only long-typing fixture overwrote the original clipboard without restoring it and could retire an unsettled input owner; its runner now refuses execution before starting a backend. A Pi long-typing cancellation case needs an independently observed input-settlement boundary before retiring its worker or fixture: Pi abort rejection can precede worker cleanup. Reference-client limits are historical, not a current test dependency. If cleanup cannot be confirmed, retain the owned processes/files and report uncertainty instead of killing a possible input owner or replaying input. Native Pi-host Esc and the [actual WSL Pi configured shortcut](validation.md#wsl-pi-physical-shortcut) are accepted; reuse these results. See [dedicated session evidence](validation.md#dedicated-physical-comparison-evidence).

### Known-held input cancellation and target failure

`npm run test:stop:held -- --plan` lists four cases without built modules, files or Windows access. After building, run the same command without `--plan` through Windows Node with `PI_CU_DEDICATED_INPUT_DESKTOP=1` on the authorized idle desktop, under the shared live-test lock. The existing disposable editor fixture adds a passive observer for tagged agent events: a later Alt-down observes Ctrl already held, or a later pointer move observes the left button already held. It then synchronously signals the normal cancellation event or invalidates its owned target. It never suppresses input, adds production delays or exposes a hold tool.

Each case requires the held-at-trigger receipt, expected cancellation/target error, native cleanup acknowledgment, independent Windows input release, operation settlement, released control/held counters and worker exit. Uncertain input/control cleanup requests normal stop and retains the owner. These four cases passed in the [scoped evidence](validation.md#known-held-input-release); they do not prove cleanup after abrupt input-owner death.

### Clipboard-free manual worker fixture

After `npm run build`, run `npm run test:stop:busy -- esc` on a dedicated, unlocked Windows desktop with `PI_CU_DEDICATED_INPUT_DESKTOP=1`. The runner waits up to two minutes at a start gate: once the user is ready, send `start` followed by Enter to the runner's stdin. After it reports typing has started, physically press Esc once within 40 seconds. Use `shortcut` instead of `esc` in a separate fresh run to test the fixture's isolated `Ctrl+Alt+F9` setting. Optional indicators are disabled in fixture settings; the required local border still appears during control. Add `--interference` for the grouped check: after typing starts, physically type `abc`, move the mouse and click inside the disposable editor, then press the requested stop key. The fixture requires aggregate blocked keyboard/mouse/button observations and no unexpected characters. Do not interact outside the disposable window. The fixture never reads or changes the clipboard.

When stdout is buffered, set `PI_CU_STOP_STATUS_FILE` to a new, nonexistent file in a private Windows-readable directory before starting the runner. Its JSON `phase` changes from `setup` to `ready`, then `started`; monitor it independently and relay the key prompt when it reports `started`. The caller sends the stdin start command only after the user is ready. The runner refuses to overwrite an existing status file.

The runner observes the disposable editor, the worker stop event, rejection of the stopped operation, acknowledged operation settlement, stable partial text, absence of unexpected characters, and released mouse buttons, modifiers, Esc and F9. It checks both independent Windows key state and the listener's physical-held counts; OS state alone cannot prove release of swallowed key-down events. After settlement it polls key state for up to five seconds to allow the user to release the physical shortcut; keys still held after that period fail the check. A pass also requires the input result itself to report `COMPUTER_USE_STOPPED` with confirmed cleanup; a generic worker cancellation or other input error is inconclusive. A one-millisecond wait checks stopped-operation rejection and fresh-operation recovery without enumerating or binding unrelated windows. If input settlement cannot be confirmed, it retains the fixture, worker and temporary files rather than terminating a possible input owner; manual investigation is required. A timeout sends the normal stop control once and remains a failed physical-key test. These results cover the Pi worker and listener, not a real Pi session, DSH host, or cancellation while a modifier is known held. `npm run test:stop:busy:check` checks the outcome evaluator without desktop input.

### Passive registered-command fixture

After building, `npm run test:stop:pi-host -- command` selects the native-Windows no-input case; `--command-host wsl` selects a WSL2 Pi host with the same real Windows worker. Add `--plan` to either selector for a side-effect-free summary. The case uses installed Pi 1.4.0 and an isolated scripted provider. It uses the existing runner, real RPC host, production registered `/computer-stop` command and Windows worker; only health and wait tools are permitted. Hold the shared live-test lock for the entire run. No editor, window discovery, UIA, screenshot, clipboard or physical key is used. This mode does not substitute for the physical fixture's prerequisites below.

The finite sequence requests one 30-second wait, establishes an actual received/pending request plus independently observed ownership, submits `/computer-stop` through RPC, requires the actual matching worker wait response to report `COMPUTER_USE_STOPPED` before its original 30-second budget (same-process monotonic timestamps), gates later turns on its successful ownership-release acknowledgment, checks aborted settlement and same-operation custom-continuation refusal, then permits one fresh ordinary-user short wait under a distinct operation. A passive metadata-only Node preload observes existing worker protocol frames without introducing a worker/proxy owner or starting stdin flow early. It never rewrites or substitutes responses. Malformed/missing observer proof, deadlines or uncertain cleanup retain the actual host and keeper, deny further tools and authorize no kill, next reset or deletion. Reports stay in the printed owned temporary directory; successful cleanup removes only the isolated settings/agent directory.

Portable forwarding/callback, observer-fault and owner/tool guard controls run in `npm run check`; the existing keeper's fake-process retention checks remain binding. One independently reviewed native-Windows run on `73d4162` passed actual worker cancellation and release before continuation; [scoped evidence](validation.md#passive-operation-evidence) preserves that exact source. A separately reviewed WSL2 run on `e09b12c` also passed, with its own Linux-host/Windows-worker identities and [paired command evidence](validation.md#passive-operation-evidence). The native result remains pinned to its earlier source; it was not rerun or relabeled as the WSL candidate. Host identity and cleanup stay separate: Linux `/proc` start/executable identities never enter Windows PID queries, which start only from the Windows worker’s real returned PID. WSL-only relative settings, shared mapped cwd and child-only `WSLENV` forwarding keep settings/logs owned; worker metadata must confirm the actual cwd/override. This case cannot prove physical Esc/custom shortcuts, held-key/button release, DSH-host or real-model behavior.

### Scripted native Pi host fixture

`npm run test:stop:pi-host -- preflight` runs on native Windows with no physical-input opt-in. It uses the same RPC launcher and default extension as the guarded physical fixture. Its scoped provider permits only health, one fixed invalid HWND/PID click and a pending wait; the click must fail before dispatch. A worker-only preload records protocol/child-lifetime metadata without arguments, environment values or typed text. The runner independently identifies the Pi host, Windows worker, stop listener, native bridge and ownership helper by executable, parentage, birth and native assembly role. It submits the real `/computer-stop`, requires the matching worker wait cancellation and operation-release acknowledgment, then closes Pi stdin and verifies normal exit and absence of all recorded participants. Failure requests cooperative stop before retaining uncertain resources. This proves orderly cleanup of recorded participants, not crash containment or held-input release. Keep the shared live-test lock throughout; no settings or agent directory is removed until successful exit checks.

`preflight host-exit` uses the same no-input sequence and participant checks, then terminates only the retained Pi host after the invalid pointer request has confirmed cleanup. It observes the worker/helpers exiting without forcibly ending them. Its receipt distinguishes this failure-path cleanup from orderly Pi shutdown; it cannot prove cleanup while native input is held or authorize forced retirement of a native helper.

`npm run test:stop:pi-host -- esc` requires native Windows, `PI_CU_DEDICATED_INPUT_DESKTOP=1` and both fresh same-launcher preflights in the same invocation. Their source fingerprint covers source, native assets, built modules, tests and the installed Pi CLI; changes before dispatch invalidate the gate. The current physical run must independently identify its own participants, confirm its invalid-target setup refusal/cleanup, active protection and border, then authorize one finite typing request through a single-use private gate. Its provider denies other mutations, changed targets and retries. This replaces the earlier unconditional refusal with tested prerequisites; it does not require a kill-on-close job or claim universal descendant containment. `npm run test:stop:pi-host:check` validates the evidence evaluator and prerequisite refusal controls without desktop input.

The passive job supervisor is not itself a safe physical-input supervisor: it kills job members if the supervisor dies. The no-input [crash boundary fixture](text.md#isolated-clipboard-diagnostics) separately demonstrates that the killed synthetic worker's managed `finally` does not execute, although the normal control's does. Pi's input paths release held inputs in `finally`; the synthetic result is a reason to retain the physical gate, not an observation of an actual held key or button.

The separate `npm run test:stop:pi-host:job` prerequisite requires Windows Node, a built package and `PI_CU_PI_CLI` pointing to the installed Pi CLI. A test-only supervisor starts suspended, enters a Windows job and launches the native Pi CLI with an isolated scripted provider. It sends no physical input, exercises health, list-windows and a wait, observes the distinct Pi host, worker and a process named `windows` in the job, then requires the job to be empty. The process name alone does not establish its executable path or parentage. Its temporary stdout may contain a window title and is removed on completion. Its synthetic provider and passive launcher do not establish containment of the physical stop launcher or independently exclude escaped/external descendants. `npm run test:stop:pi-host:job:check` checks the evidence evaluator without Windows.

The same fixture now supports a WSL2 Pi host when launched from WSL, with Windows Node compiling the owned editor and the editor reporting its actual Windows PID. Linux host/interop identities stay in `/proc`; Windows inspection starts from the traced Windows worker. Observer/settings overrides are mapped and forwarded only to the child. Actual WSL Ctrl+Alt+F9 [passed](validation.md#wsl-pi-physical-shortcut); native Esc is reused.

The physical fixture uses the installed project Pi SDK through the shared launcher, isolated settings and the stdin/status-file coordination above. `shortcut` selects its configured physical key. It requires a matching worker stop event and canonical input cleanup response, operation-specific release acknowledgment, stable partial text with no unexpected characters, independent OS key/button release and a fresh health observation showing suppression and physical-held counts released. A stop key reaching the editor fails the check. SDK abort alone cannot pass or authorize retirement. Only after those receipts does it close Pi stdin, verify normal host exit and absence of all recorded participants, close the owned fixture and remove its temporary resources. Timeout/failure requests normal abort; uncertain cleanup retains actual owners and files. Native Esc and WSL physical-shortcut results retain their named scripted-provider scopes; known-held release is covered separately above; DSH and additional model-comparison runs are removed.

The existing `test:stop:pi-host -- handback` case writes one `x`, proves normal settlement/control release, then waits at a human gate for `abc`. Explicit continuation is another ordinary-user turn; a successful fresh snapshot must precede Ctrl+End/one appended `x`, producing exactly `xabcx`. Cleanup and exact operation-release acknowledgments are required before human invitation and retirement. This [WSL Pi case passed](validation.md#wsl-pi-human-handback-and-continuation). The [control interruption acceptance](validation.md#control-interruption-acceptance) completes #31 using the narrowed safety scope. Reuse locked-input refusals and this handback result; do not require target survival or seamless unlock recovery. No further human lock step is queued without a proven evidence gap.

`npm run test:stop -- --desktop-loss` runs with Windows Node under the shared live-test lock. It claims the production desktop mutex and compiles a disposable helper copy with only an availability-failure guard added to `InteractiveDesktop`; real OS checks and the native timer/stop/release paths remain intact. It injects no input and does not lock Windows. The available-state control, automatic stop/cancel/control release, same-operation refusal, disarm and helper exit passed. This complements the real locked-refusal, worker and held-input receipts; it does not claim an actual OS-lock-during-held-input run.
