Skip to content

refactor(native): build debugger and native cancellations with a required reason - #10599

Merged
morluto merged 17 commits into
mainfrom
refactor/cancellation-reason-debuggers
Nov 15, 2026
Merged

morluto merged 17 commits into
mainfrom
refactor/cancellation-reason-debuggers

Conversation

@morluto

@morluto morluto commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Migrates every AnalysisCancelledError construction under src/native/, src/gdb/ and src/rizin/ (59 sites) to cancelledBy, the reason-requiring owner from #10566, and deletes Rizin's local rizinCancellation constructor. The guard baseline drops by 59, to 513 on the current base branch. Stacked on refactor/cancellation-owner (#10566).

Refs #8223

Overlap: #10551 (gdb retained cancellation) edits GdbSessionManager.ts around the gdb_console cancellation and Rizin's #retainCleanupFailure, which this PR also touches. Whichever lands second needs a small rebase. If #10551 lands after the guard, its new new AnalysisCancelledError( sites must use cancelledBy.

Problem and expected behavior

  • rizinCancellation(operation, signal?, cause?, options) was a local constructor that chose the cause in this order: the caller's reason when the signal had aborted, otherwise an earlier cancellation's cause, otherwise the raw cause. It is replaced by rizinCancellationReason(signal, cause): CancellationReason. That helper makes the same choice in the owner's vocabulary (isAborted(signal) ? signal : earlier cancellation : carriedReason(cause)), and every construction now goes through cancelledBy.
  • GDB's cancelledWithCallerReason keeps its separate job (copying the earlier cancellation's diagnostics, output and cleanup), but now builds through cancelledBy.
  • GdbSessionManager.close aborted active startups with no reason; it now aborts with OwnerCancellation.ownerClosed.

Change and scope

  • Mechanical: new AnalysisCancelledError(op, { cause: s.reason, ...rest }) became cancelledBy(op, s, rest) wherever s is a narrowed AbortSignal. Every other cause became carriedReason(x), which keeps the existing value.
  • Option bags that carried cause (GDB startup details/errorDetails, NativeCommandAnalysisError, LldbCallTracer, NativeMacOSProvider, Rizin #retainCleanupFailure) are split, so the cancellation branch receives no cause.
  • GDB startup cancellations that wrapped an earlier AnalysisCancelledError as their cause still wrap it, through carriedReason(cause). Whether to flatten that wrapper is a behaviour question for the GDB/Rizin drift work and is left unchanged here.
  • Listener and wait sites that run only after an abort (GDB console abort listener, Rizin frame waiter, LLDB cancelled exit, pwntools admission, Apple dispatch metadata) keep carriedReason(signal?.reason).
  • Not included: Hopper (last slice), a shared debugger registry (W4f), and W4b finalization.

Contract and boundary impact

  • Semantic owner and earliest changed stage: cancelledBy and isAborted (refactor(errors): require a reason for every analysis cancellation #10566); the debugger and native adapters are consumers.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none; cause is not projected.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: none; debugger stop and cleanup paths are unchanged.
  • Generated metadata, package, or installation impact: none.

Expected effects: none checked. This changes error construction only.

Evidence and regression coverage

  • Tests added or updated: none in this PR. The Rizin coverage tests pass a signal-shaped fake. At first they failed because the owner matched signals with instanceof AbortSignal; the owner now matches signals structurally, with its own unit test on the base branch (fix(errors): read the reason of any signal-shaped cancellation source).
  • Remaining proof gaps: no real gdb, rizin or lldb run. The GDB close reason is source-derived.

Validation performed

  • npm run check:fast — passed (typecheck, lint).
  • node scripts/verify/architecture-guards.mjs — passed; baseline 513 sites in 186 files, none under src/native/, src/gdb/ or src/rizin/.
  • npm run test:focused -- the test files beside the changed modules, the tests/ files that import a changed module and assert on cancellation or cause, and every tests/boundary/providers/Gdb*, Rizin* and tests/boundary/mcp/gdb* file (49 files):
    • first run: 2 failed in RizinDebugSessionCoverage.part3.test.ts (signal-shaped fake, see above);
    • after the owner fix: 47 passed, 2 skipped (platform); 906 tests passed, 38 skipped.
  • npx oxfmt on changed files — formatted.
  • Merge with main (b0e3257), 2026-11-15: GdbSessionManager conflicts resolved onto main's OwnedDebuggerSessionRegistry and classifyLaunchFailure owners, keeping this PR's cancelledBy construction. npm run check:fast passed; node scripts/verify/architecture-guards.mjs --shrink-baselines, then the guard passed (it also lowered the stale McpRegistrationGit.ts bindCleanupDependencies entry, already 0 on main); npm run test:focused -- GdbSessionReviewRegressions, GdbSessionManagers, GdbSessionManagerCoverage, gdbCancellationMcp, debuggerSessionLimits: 249 tests passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: none.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

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.

Add cancelledBy, the one constructor for AnalysisCancelledError. Its
reason argument is required: an aborted signal, an earlier cancellation,
a reason carried from an inner failure, or an OwnerCancellation when REA
closed the work's owner itself.

Closed adb, apktool, firmware, sqlite, gdb, web-bundle analyzer and
binary-session record owners now report OwnerCancellation.ownerClosed
instead of an absent reason. Firmware's predecessor wait returns its
cancellation as a Result, removing an unreachable reason-less fallback.

An architecture guard rejects new direct constructions, with a counted
per-file baseline that can only shrink.
…equired reason (#10587)

Migrate every AnalysisCancelledError construction under src/ghidra,
src/ida, src/cutter, src/jeb and src/kuna to cancelledBy and lower the
guard baseline from 671 to 572. Closed Kuna target commands report
OwnerCancellation.ownerClosed instead of an absent reason, and Kuna and
JEB close abort their lifetimes with that typed reason.
…ired reason

Migrate every AnalysisCancelledError construction under src/native,
src/gdb and src/rizin to cancelledBy and delete Rizin's local
rizinCancellation constructor; its reason choice becomes a
CancellationReason. GDB close aborts active startups with
OwnerCancellation.ownerClosed.
@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:52:11.920596Z cf5ebcd 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

[Medium impact] The reviewed changes appear safe to merge; no blocking issue was found.

Summary

Moves debugger and native cancellation construction to cancelledBy without changing the traced error behavior.

  • Native-analysis code builds cancellations with an explicit reason.
  • GDB sessions build cancellation errors with an explicit reason.
  • Rizin startup and commands build cancellations through the shared helper.

Reviews (10) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
#	scripts/verify/architecture-guards.mjs
…o HEAD

# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
#	src/native/pe/PeBinaryFailure.ts
#	src/rizin/RizinDebugSessionManager.ts
Base automatically changed from refactor/cancellation-owner to main November 14, 2026 20:20
# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
#	src/gdb/GdbSessionManager.ts
# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
…-reason-debuggers

# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
#	src/gdb/GdbSessionManager.ts
…-reason-debuggers

# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
#	src/native/pwntools/PwntoolsFailures.ts
…-reason-debuggers

# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
#	src/gdb/GdbSessionManager.ts
…-reason-debuggers

# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
#	src/gdb/GdbSessionManager.ts
#	src/rizin/RizinDebugSessionManager.ts
…-reason-debuggers

# Conflicts:
#	scripts/verify/architecture-guard-baselines.json
#	src/native/LldbCallTracer.ts
#	src/native/SignatureTargetBinding.ts
@morluto
morluto merged commit 57f75bb into main Nov 15, 2026
7 checks passed
@morluto
morluto deleted the refactor/cancellation-reason-debuggers branch November 15, 2026 10:07
@morluto morluto added the area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant