Skip to content

refactor(errors): give caller aborts a typed reason at the adapters - #10633

Merged
morluto merged 6 commits into
mainfrom
refactor/caller-abort-reason
Nov 15, 2026
Merged

morluto merged 6 commits into
mainfrom
refactor/caller-abort-reason

Conversation

@morluto

@morluto morluto commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

The CLI, direct-analysis, MCP and HTTP adapters aborted their controllers with no reason, so a caller cancellation's cause was an anonymous platform AbortError (or, for MCP, the client's bare string). This adds a typed CallerAbort that each adapter creates when its caller ends work, gives REA's own aborts at those boundaries an OwnerCancellation, folds the startup-owner symbol into OwnerCancellation, makes waitForAbortable return the reason it observed, and adds a counted-baseline guard against new bare .abort() calls.

Stacked on #10566 (base branch refactor/cancellation-owner). Refs #8223

Problem and expected behavior

  • withCommandCancellation (CLI), withProcessCancellation (direct analysis), the MCP request/completion bookkeeping and the node HTTP bridge called controller.abort(). The resulting cause could not say whether SIGINT, SIGTERM, an MCP notifications/cancelled, a client disconnect or REA itself ended the work.
  • STARTUP_OWNER_CLOSED was a bare Symbol, which also became the cause of a Ghidra NativeAOT and doctor cancellation.
  • waitForAbortable returned an ABORTED sentinel, so every consumer read signal?.reason again (and IDA/Kuna wrapped it in carriedReason).
  • Expected: an adapter's caller abort carries a typed reason naming the adapter and any client-stated reason; REA-initiated aborts carry OwnerCancellation; the abortable wait hands its reason straight to cancelledBy.

Change and scope

  • src/domain/analysisErrorCore.ts: CallerAbort extends DOMException with name === "AbortError", kind (interrupt, terminate, request-cancelled, client-disconnected) and optional clientReason; CallerAbort.forProcessSignal(signal). It keeps the platform abort shape on purpose. Existing classifiers that match name === "AbortError", and Node's fs/fetch wrapping of signal.reason, see the same shape as before (checked: fs wraps it as cause; fetch rejects with it directly). The doc comment states it is opaque like any caller reason: its kind never establishes failure origin or cleanup authority.
  • OwnerCancellation.startupOwnerClosed (new kind startup-owner-closed) replaces STARTUP_OWNER_CLOSED. It is kept distinct from OwnerCancellation.ownerClosed on purpose. Hopper and Ghidra compare a startup signal's reason by identity to report "session closed during startup". If it were merged with the general ownerClosed, an outer owner's close reaching the caller's signal would be misreported as a startup closure.
  • Adapters:
    • CLI commandCancellation.ts: SIGINT and SIGTERM abort with CallerAbort.forProcessSignal.
    • DirectAnalysis.withProcessCancellation: the same, split into two listeners.
    • MCP EvidenceMcpServerCore/McpToolRequest: notifications/cancelled aborts with CallerAbort("request-cancelled", params.reason). Transport onclose aborts with client-disconnected. REA's close() and the post-reply release use OwnerCancellation.ownerClosed. McpToolRequest.cancel and forgetPendingMcpRequest now require the reason.
    • HTTP nodeHttpBridge: client leaving aborts with client-disconnected; serveStreamableHttp body-forwarding release and shutdown use ownerClosed.
    • eagerRuntime shutdown aborts startup with ownerClosed.
  • src/process/AbortablePromise.ts: ABORTED is replaced by AbortedWait, a CarriedCancellationReason holding the reason observed when the abort won. All 14 consumers were migrated. gdb, IDA and the two Kuna sites now call cancelledBy(operation, waited); desktop rethrows waited.carried; SharedStartupAttempt returns and forwards it.
  • Guard: scripts/verify/architecture-guards.mjs adds abort-without-reason (pattern .abort() with no argument, non-test src/), using the existing counted baseline. Baseline: 32 sites in 25 files (43 before this PR). gdb's new AnalysisCancelledError( baseline drops 13 → 12.
  • Not included:
    • the remaining 32 bare .abort() sites. Several are internal controllers whose consumers rely on the platform AbortError (for example ZipArtifactReader), so each needs checking in its own slice;
    • Finalized<T>/runOwned (W4b);
    • deleting the per-provider signal-reading helpers (hopperCancelledBySignal, #startupWaitCancellation, rizinCancellation), which still read the signal for the post-completion check.
  • Contribution scope: not applicable (internal refactor within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: CallerAbort/OwnerCancellation in src/domain/analysisErrorCore.ts. The CLI, MCP and HTTP adapters create them, and cancelledBy consumes them.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none. A cancellation's cause is not projected; exit codes 130/143 are unchanged.
  • Provider, bridge, target-format, or platform compatibility: none. Hopper/Ghidra startup-closure classification is unchanged because the startup reason stays distinct.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: none.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

None checked: this changes abort reasons only.

The MCP request boundary now passes the owned cancellation signal to both schema-bearing and schema-free handlers. Owner shutdown records close intent before transport closure, preserving the owner reason when onclose fires synchronously.

Evidence and regression coverage

  • Tests added or updated:
    • src/server/EvidenceMcpServer.test.ts:
      • new: a client callTool aborted with "user stopped" gives the running tool's request signal a CallerAbort of kind request-cancelled with that clientReason;
      • bookkeeping: the completion signal's reason is the passed reason.
    • src/server/http/nodeHttpBridge.test.ts: a client leaving aborts the web Request with CallerAbort client-disconnected.
    • tests/boundary/cli/androidCliCancellation.test.ts: SIGINT/SIGTERM give interrupt/terminate reasons with name: "AbortError".
    • src/domain/analysisErrorCore.cancellation.test.ts: the CallerAbort shape; startupOwnerClosed is distinct from ownerClosed.
    • src/process/AbortablePromise.test.ts (new): the wait carries the reason into cancelledBy, including a signal aborted before the wait.
    • SharedStartupAttempt, Kuna doctor and Ghidra profile-ownership tests now assert OwnerCancellation.startupOwnerClosed.
  • Base reproduction: with EvidenceMcpServerCore.ts and nodeHttpBridge.ts reverted to the base branch, the three MCP/HTTP tests fail (reasons are the client string or a plain DOMException); they pass with this change.
  • Guard: lowering any baseline entry or adding a bare .abort() fails node scripts/verify/architecture-guards.mjs (same mechanism as refactor(errors): require a reason for every analysis cancellation #10566).
  • Remaining proof gaps: no real-client MCP cancellation run; Windows not exercised.

Additional validation: MCP server and cancellation lifecycle tests passed (20 tests), including real in-memory transport shutdown and joined handler cleanup. npm run check:fast passed.

Validation performed

  • 2026-11-15, after merging current origin/main (conflict in scripts/verify/architecture-guards.mjs: kept both the abort-without-reason and the new gdb-mi-record-regex checks): npm run check:fast — passed; node scripts/verify/architecture-guards.mjs — passed; npx oxfmt --check scripts/verify/architecture-guards.mjs — passed.
  • npm run check:fast: passed (typecheck, lint).
  • node scripts/verify/architecture-guards.mjs: passed across 2783 source files.
  • npm run docs:check: passed.
  • npx oxfmt --check on changed files: passed.
  • npm run test:local -- src/server/EvidenceMcpServer.test.ts src/server/http/nodeHttpBridge.test.ts src/process/SharedStartupAttempt.test.ts src/doctorRuntime.test.ts: 61 passed, 1 skipped.
  • npm run test:local -- src/application/desktop/DesktopBuildTurns.test.ts src/application/desktop/DesktopRemoteTaskReaders.test.ts: 13 passed.
  • npm run test:local -- src/ida/IdaSessionClient.test.ts src/ghidra/GhidraProvider.behavior.test.ts src/process/OwnedCommand.test.ts: 396 passed.
  • npm run test:local -- src/domain/analysisErrorCore.cancellation.test.ts src/process/AbortablePromise.test.ts: 8 passed.
  • npm run test:focused -- tests/boundary/cli/androidCliCancellation.test.ts tests/boundary/providers/hopper/hopperClient.startupWaiters.test.ts tests/boundary/providers/hopper/hopperClient.restart.test.ts tests/boundary/providers/ghidra/ghidraClient.test.ts tests/boundary/providers/kuna/kunaDoctor.test.ts tests/boundary/filesystem/ghidraProfileArtifactOwnership.test.ts tests/boundary/providers/GdbCommandQueue.test.ts tests/boundary/providers/RizinDebugSessionAdmission.test.ts tests/boundary/providers/kuna/kunaCommandCancellation.test.ts tests/boundary/providers/ida/retainedConnectionRetry.test.ts tests/process-global/commandFinalizationCancellation.test.ts: 11 files, 191 passed.
  • Base reproduction above: 3 failed with the two adapters reverted.
  • After rebasing on main (2026-11-15): CI showed darwinProcessRunTokenReader.test.ts still expecting the default DOMException for a reader close, which this PR's owner-abort change now reports as OwnerCancellation.ownerClosed; the expectation was updated. npm run test:focused -- tests/boundary/process/darwinProcessRunTokenReader.test.ts: 37 passed. Related abort-reason tests (nativeCommandResolver, cdpConnection, EvidenceMcpServer, HopperDownload, KunaCopy, analysisErrorCore.cancellation, ExecFileOutput, androidTargetSnapshot): 137 passed. Architecture guards and pre-push check:fast passed.
  • After rebasing onto main (conflict in scripts/verify/architecture-guards.mjs with main's new tshark guard; both guards kept): node scripts/verify/architecture-guards.mjs passed; npm run check:fast passed.
  • HTTP owner-close follow-up (review thread): npm run test:focused -- src/server/http/serveStreamableHttp.test.ts: 77 passed; with the onclose change reverted the new replacement and shutdown cases fail. npm run test:focused -- src/server/EvidenceMcpServer.test.ts tests/boundary/cli/cliStartupImports.test.ts: 16 passed. npm run check:fast passed.

Compatibility, safety, and release

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T09:17:52.008022Z aa34308 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; no new actionable issues were found.

Summary

Adds typed caller and owner abort reasons across the adapters and internal work owners. AbortedWait now carries the reason observed by an interrupted wait.

  • Caller cancellations say which adapter saw the request end.
  • REA-owned stops carry a reason for why the work ended.
  • Aborted waits carry the reason they observed into their callers.
  • The architecture check now flags new bare abort calls.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Caller["Caller cancels or disconnects"] --> Adapter["CLI, MCP or HTTP adapter"]
  Adapter --> CallerReason["CallerAbort"]
  Owner["REA stops owned work"] --> OwnerReason["OwnerCancellation"]
  CallerReason --> Signal["AbortSignal.reason"]
  OwnerReason --> Signal
  Signal --> Wait["waitForAbortable"]
  Wait --> Carried["AbortedWait carries the observed reason"]
  Carried --> Cancelled["cancelledBy preserves the cause"]
Loading

Reviews (10) · Last reviewed commit: "Merge origin/main into refactor/caller-a..." · Reviewed by Greptile

Comment thread src/server/EvidenceMcpServerCore.ts Resolved
Comment thread src/server/EvidenceMcpServerCore.ts Resolved
Comment thread src/server/EvidenceMcpServer.test.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 62ce5d008d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/EvidenceMcpServerCore.ts Resolved
Comment thread src/server/EvidenceMcpServer.test.ts Resolved
Squashes 9088135, 87858de (fix(mcp): preserve cancellation reasons in handlers) and fa151dc (test(server): race handler-entry gates against the triggering tool call) onto main without #10566's pre-squash commits.
…the browser adapters (#10692)

* refactor(errors): give owner-initiated aborts a typed reason outside the browser adapters

* refactor(verify): keep the abort-reason scan receiver-independent

Playwright's route.abort takes a network error code; the one call site now names its default code instead of the guard exempting a variable name.

* refactor(browser): give owner-initiated CDP aborts typed reasons (#10706)

* refactor(browser): give owner-initiated CDP aborts typed reasons

* fix(browser): give the page-side request fetch page-native abort reasons

The request callback runs in the page through page.evaluate and cannot
reach REA's modules. Define its deadline and cleanup reasons as
DOMExceptions inside the callback, and make the test fake evaluate the
callback from its source so module imports are unavailable, as in a page.
Closing the Darwin run-token reader aborts its compilation with OwnerCancellation.ownerClosed since the owner-abort change in this PR; the boundary test still expected the default DOMException.
@morluto
morluto force-pushed the refactor/caller-abort-reason branch from a9cc145 to fa54a49 Compare November 15, 2026 08:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa54a493e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/EvidenceMcpServerCore.ts Resolved
@morluto
morluto merged commit b655645 into main Nov 15, 2026
7 checks passed
@morluto
morluto deleted the refactor/caller-abort-reason branch November 15, 2026 09:28
@morluto morluto added the area: domain Domain logic, errors, and pure functions label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant