Repository navigation
feat: exception queue for any agent (closed kinds, raise_exception MCP tool, detectors, local registry, Desktop cards) - #2494
Conversation
…P tool, detectors, local registry, Desktop cards)
Only #2492 bumps Desktop to 0.31.0, so the stop queue's exception cards, their tests and their changelog line now land there. This pull request touches no packages/desktop file.
Under load the card's 3-second deadline passed before the answer command started, so the roster check never ran. The card now waits 600 seconds; the test checks the stranger's answer is refused with nothing written, then a rostered person answers abort to end the run.
raise_exception only works when the agent calls it. openadapt-flow exceptions watch attaches to the agent's Chromium over CDP (the endpoint the guard uses), reads the page with geometry every half second, runs the detectors and opens the card itself. While a card is open it blocks every save the page sends, using the guard's own classify() and the guard.yaml not_saves, so a person can still submit a code form listed there. A verified continue or done_by_person lifts the hold; any other outcome blocks every later save and the watch exits 3. Chromium hands a paused request to each DevTools session in turn, so the watch and the guard compose in either attach order. Covered: second_factor, unexpected_dialog, session_expired (after a save) and, with --stall-s, timeout_or_stall. Not covered: possible_duplicate, ambiguous_record, cannot_complete, non-browser agents, WebSocket saves, and a run with no watch. The registry gains poll(), one non-blocking look that wait() now loops on. The exception package's files are formatted to the CI ruff config.
Moved here from #2494 so only one pull request bumps Desktop to 0.31.0. The stop queue reads Flow's exception registry under OPENADAPT_HOME and answers each card on its own, signed with the stop queue's approver key. The card fixture the tests read is committed here too, byte for byte the file #2494's Flow test writes.
Chromium hands a paused request to the DevTools session that attached last first, so the watch must attach after the guard to decide a save before the guard sees it. The earlier commit said the two compose in either order; in the other order a blocked save is still never sent, but the guard has already let it go and ends the run unconfirmed. Only the guard-first order is tested. Also lists two gaps: other tabs, and a save sent before the watch's next look at the page.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. This PR adds an exception queue any agent can use: seven closed kinds, five answers, a Local checks on this head: run 3 merged this head into integration tree |
Independent adversarial review: REQUEST CHANGESFrom: Gemini This PR introduces the exception queue, allowing agents to stop and ask a person for help. It includes an MCP tool for cooperative agents and a browser watch that runs detectors and blocks saves independently. The design is robust, with secure local file handling, proper cryptographic verification of answers, and a fail-closed philosophy for unreadable or invalid answers. However, there is a crash bug in the browser watch's request handling that causes it to exit on normal network aborts, failing open for the remainder of the run.
Earlier findings at this head:
Verdict: REQUEST CHANGES |
…ly when lost A CDP error from Fetch.continueRequest or Fetch.fulfillRequest (the page aborted a paused save, say) ended the watch loop, and nothing was blocked for the rest of the run. Each decision is now caught and logged as request_decision_failed, and the loop goes on. When the watch's own DevTools session stops answering while the tab is still open, it prints WATCH LOST on stderr, logs watch_lost, reports lost in its output and exits 4 if it was holding saves (a card open or a stop), else 5. The docs say a dead watch blocks nothing, so the guard is the backstop. Tested in headless Chromium: a save the page aborts while paused, then a save that is still blocked; and a dropped session with a card open.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since 2fb05fa this head fixes the blocker in the Gemini review: a CDP error on one paused request no longer ends the watch, and a lost watch session exits non-zero with a WATCH LOST message and a logged event. Docs say a dead watch blocks nothing, so the guard is the backstop. Fresh origin/main is merged. Local checks on this head: registry, detectors, watch units, MCP, the watch and new fault e2e files (headless Chromium), flow cli_tasks, capabilities map and import layers, 2359 passed; ruff, ruff format and mypy clean. |
Independent adversarial review: REQUEST CHANGESFrom: Claude (independent reviewer) I read the whole diff against main: the card and answer types, the registry, the MCP tool, the detectors, the watch and its CLI, the tests, EXCEPTION_QUEUE.md and the CAPABILITIES row. The earlier blocker is fixed: Blockers
Nits
|
…on cards - The screen read counts only controls the page renders: a hidden, aria-hidden, inert, zero-size or invisible control is not "on screen at the save", and a field matched only by hidden controls is not read. - When the field diff overrides a verify-run receipt that says verified, effect-receipt.override.json beside it records the guard's verdict and the receipt digest, and guard.json says outcome overridden. - The ledger row's approval_decided_at comes only from an answer the guard accepted. - Desktop reads exception card and answer files only when no other user can read them (no group or other bits), as its docstring says, and the scan stops at MAX_CARDS across runs, not per run. - StopCard.kind includes exception, with exception_kind. - The Desktop changelog and exception_queue.py say the cards require Flow with the exception registry (#2494); #2494 merges first. - GUARD_AN_AGENT.md says a read-back provider declares its own tier.
If a detector, opening a card (a full disk, an unwritable registry) or reading an answer raised, the loop ended, the cleanup let the paused saves through, and the CLI ended on a traceback with exit 1. Now any such error marks the watch failed: every paused and later write is refused with a 409 until the process exits, watch_lost is logged with reason watch_failed, and the watch exits 4. cmd_watch turns any other failure into the same documented code. Also: a request the watch can't classify is refused, not let through; ending with a card still unanswered (--max-s, a signal) exits 6, not 0; EXCEPTION_QUEUE.md says a stop answer blocks later saves for as long as the watch runs.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since 8503558 this head fixes the blocker in the independent review: any error in detection, card opening or polling keeps every paused and later write refused (409, never continued) until the watch exits, logs watch_lost and exits 4. A request that can't be classified is refused, and a watch that ends with a card unanswered exits 6. Local checks on this head: registry, detectors, watch, MCP, the watch and faults e2e files (headless Chromium), cli_tasks, capabilities map and import layers, 2363 passed; ruff, ruff format and mypy clean. |
Independent adversarial review: REQUEST CHANGESFrom: Claude (independent reviewer) I read the P6 diff against main: the card and answer types, the registry, the MCP tool, the detectors, the watch and its CLI, the tests, EXCEPTION_QUEUE.md and the CAPABILITIES row. The other changes since 8503558 come from the main merge. The registry's answer checks still hold up: the signature covers the card id, kind and open time, and the registry also checks the offered choice, the time window, the roster and single use. The Gemini blocker is still fixed. Part of the earlier independent blocker is fixed: a paused save is no longer continued after an error, and the exit code is 4. But after its own error the watch still stops holding. I confirmed both blockers below with a small script against this head, using fake page and CDP objects. Blockers
Nits
|
…un ends After the watch's own error, run_loop returned at once, so the agent's next save met no watch. The loop now stays in the failed state, refusing every write, until the tab closes, the session is lost, a signal arrives or max_s passes. Cleanup before detaching decides every paused request and skips one the browser refuses, instead of stopping at it and letting the rest through on detach. Also: the WATCH LOST line names a card or a stop only when there was one, and an interrupt with a card open exits 6.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since 695a44b this head fixes the two blockers in the independent review: after a failure the watch stays in a failed state and refuses every write until the tab closes, the session is lost, a signal arrives or max_s passes; and cleanup decides every paused request, skipping any single refusal. An interrupt with a card open exits 6. Local checks on this head: registry, detectors, watch, MCP, the watch and faults e2e files (headless Chromium), cli_tasks, capabilities map and import layers, 2366 passed; ruff, ruff format and mypy clean. |
Independent adversarial review: APPROVEFrom: Claude (independent reviewer) I checked the two blockers from the last review (695a44b) against this head and read the whole P6 diff against main again: the card types, the registry, the MCP tool, the detectors, the watch and its CLI, the tests, EXCEPTION_QUEUE.md and the CAPABILITIES row. Both blockers are fixed, and the watch, registry and detector unit tests pass (84 passed). Earlier blockers
Blockers Nits
|
…ess, a doc link) - The registry opened its card and answer files with a plain os.open, so on Windows os.read and os.write used text mode (the Windows guards job, test_binary_file_descriptors). It now uses private_file.open_binary. - The watch attached over CDP without the rendering check every other attach makes (test_browser_readiness). It now calls require_rendering_ready on the tab it selected, and is in the inventory of CDP attaches. - The exceptions command note linked EXCEPTION_QUEUE.md with a path that only works from the repo root, which the link check reads relative to the note's folder. It now names the path as code.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. The only change since c5309ef is 95f8d19, which fixes three CI failures this branch caused: the exceptions command note names the docs path as code instead of a broken relative link; watch_browser runs the require_rendering_ready check on the tab it attaches to, as every CDP attach must; and the registry reads and writes through private_file.open_binary, so Windows does not open its files in text mode. Local checks on this head: the three failing contract tests plus registry, detectors, watch, MCP, the watch and faults e2e files, cli_tasks, capabilities map and import layers, 2424 passed; ruff and mypy clean. Windows was not run locally; the descriptor contract test that failed there passes. |
Independent adversarial review: APPROVEFrom: Claude (independent reviewer) Delta check since c5309ef: one fix commit that turns a doc link into a code path, switches the registry's |
What this adds
An exception queue any agent can use to stop and ask a person, one closed question at a time (box 5 of the flight recorder and control plane).
packages/types/openadapt_types/exception_card.py, imported by submodule path, not exported from__init__.py):openadapt.exception-card/v1andopenadapt.exception-answer/v1.second_factor,unexpected_dialog,session_expired,timeout_or_stall,possible_duplicate,ambiguous_record,cannot_complete.continue,skip,decline,done_by_person,abort.openadapt_flow/exceptions/registry.py): a file protocol under$OPENADAPT_HOME/exceptions/<run_ref>/. It writescard-,answer-andconsumed-files atomically with mode 0600, following the item-approval pattern (item_approval.pyis unchanged).wait()blocks with a heartbeat. On expiry it writesanswer=decline,decided_at=null,reason=expired. Only a verifiedcontinueordone_by_personlets the run go on.openadapt-flow exceptions serve | list | answer CARD_ID CHOICE.serveis a stdio MCP server with one tool,raise_exception(kind, summary, screenshot_path?). It blocks until the card is answered or expires.answersigns with the approver key and checks the signature against the approver roster.__main__.py, with a doc and a regenerated command map.exceptions/detectors.py): a pure library over screen text, the accessibility or DOM snapshot, and timing. It has general signals only and never names an app: a one-time-code field, a password field after the first save-eligible screen, a topmost modal over the target, a stall, and aduplicate_keymatch. When a detector is uncertain, it raises a card.stop_queue.card_for_exception()maps each kind to its choices and their consequences.dispatch._stop_cardsalso scans the registry, so cards from CLI, wrap, flight and hooks runs appear in the queue too.stops.jsrenders the new cards for a paired phone.MAX_BATCHis unchanged.exception_queue.py. Desktop's version goes from 0.30.6 to 0.31.0.done_by_person). OpenAdapt never relays the code in this PR.packages/flow/docs/EXCEPTION_QUEUE.mdsays the "~10% need a person" figure is unmeasured. This PR also adds one row at the end of the Approvals table in CAPABILITIES.md and regeneratesllms-full.txt.Tests (synthetic, headless, through the cpu-slot runner)
tests/test_exception_card.py: 20 passed.test_cli_tasks.pyandtest_capabilities_map.py: 128 passed. This run needs theagentextra formcp; without it, the e2e test skips.test_stop_queue_exceptions.pyandtest_stop_queue.py: 56 passed and 1 skipped. The skipped test needs the in-tree types; with them,test_stop_queue_exceptions.pyhas 29 passed.The end-to-end test uses a scripted agent and a synthetic two-step app on 127.0.0.1: a one-time-code page, then a form. The agent talks to
exceptions serveover real MCP stdio, and a second subprocess answers the card withexceptions answer. The test asserts:done_by_person;abort,skip, an expiry (recorded asdecline), or a key that is not on the roster, read from the app's own state;Integration follow-ups (not in this PR)
second_factoranswer path that seals the code and types it throughsecond_factor.py, so the agent never sees it.raise_exceptionto the MCP surface ofwrap -- COMMAND.opened_atanddecided_atfrom the answer files as intervention intervals, and map such runs to ESCALATED, not FAILED.duplicate_record.pyinto a validated data pack, to close a generality gap.