Skip to content

fix(gdb)!: preserve interrupt and provider cleanup ownership - #1961

Closed
dandgabr wants to merge 466 commits into
morluto:mainfrom
dandgabr:feat/gdb-debugger-integration
Closed

dandgabr wants to merge 466 commits into
morluto:mainfrom
dandgabr:feat/gdb-debugger-integration

Conversation

@dandgabr

@dandgabr dandgabr commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix persistent GDB control and cleanup ownership: interrupt can reach an admitted run, cancelled runs retain their mutation barrier, and interrupted artifact reads return bounded failures without losing descriptor ownership. Synchronize the shared lifecycle corrections from #1959/#1960 and merge current upstream/main (9af0b6113). Related scope discussion: #3656; this PR originated in the split of closed #1279.

Problem and expected behavior

A run waiting for *stopped also blocked its queued interrupt; cancellation could instead detach a running writer and release admission. An interrupted digest could then hang on FileHandle.close(), or hide that cleanup behind an earlier provider timeout. Commands now preserve the exact execution/cleanup owner until correlated protocol settlement and confirmed cleanup, while returning partial observations and typed failures.

Change and scope

  • Separate target-running state and interrupted-token synchronization from command serialization. Only exact argument-free interrupt gets one bounded control slot under the original run's admission. Real GDB console execution blocks MI input, so delivery queues MI and sends SIGINT only through the retained owned debugger handle, then awaits correlated MI/async stop.
  • Normalize shutdown failures at the GDB owner; keep failed close/cancel errors bound to that same owner. Preserve delayed startup stderr.
  • Hash through the canonical descriptor chunk reader and OwnedFileHandle; bounded late-open/fstat/read/close settlement retains a retryable cleanup owner. Compose secondary cleanup through the existing error algebra without losing the primary failure.
  • Carry shared preflight/admission, fixed-source, Windows lookup, inferior-input, caller-token and CLI recovery corrections. Close retries retained writers within the same session transition, preserves snapshot receipts, and composes every independent cleanup owner (including typed callback rejections). CLI admission conflicts report retryable capacity. Failed terminal-helper readiness now closes/awaits its own child; real-provider CI follows ownership primitives and checks actual MI result classes and SIGINT.
  • Disclose the reserved REA_PROCESS_RUN_ID override in static Rizin/plugins. This is documentation of existing behavior; environment equivalence is not claimed and ambient inheritance does not authorize persistence.

No new target-execution authority is added by these corrections. Maintainer scope approval for the overall debugger integration remains unknown/pending in #3656; passing checks do not authorize integration.

Contract and boundary impact

  • Semantic owner and earliest changed stage: provider command preparation, GDB MI/running state, descriptor read/close ownership, and shared binary mutation admission.
  • Contribution scope fit and linked maintainer decision: routine corrections within the existing proposed integration; the final integration decision is still pending in #3656.
  • CLI and MCP/tool-catalog contract: existing tool names/schema shapes; exact interrupt control behavior and truthful Rizin environment description. Fixed analysis sources with no mutation lifecycle no longer advertise unrestricted Rizin.
  • Provider, bridge, target-format, or platform compatibility: caller-supplied tools; GDB live-inferior verification remains Linux-only. Windows lookup is cancellation-aware; actual Windows/macOS runtime behavior was not executed here.
  • Evidence, artifact, provenance, or reconstruction contract: retained partial output/primary failures and live cleanup resources; actual interrupt delivery is recorded. No ambient environment snapshot is persisted.
  • Target selection, authority, upstream behavior, and cleanup details: caller-selected commands/targets; only the retained debugger handle receives interrupt signals, never an inferior PID or group. Unknown cleanup remains owned and blocks unsafe replacement.
  • Generated metadata, package, or installation impact: canonical description regenerated/validated through docs checks; ignored catalogs/build outputs are not committed. No provider installation.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code. (existing unrestricted debugger/Rizin commands)
  • Change process memory, registers, files, or configuration. (existing caller-selected debugger authority)
  • Contact network services. (possible through caller-selected commands/plugins)
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: GDB provider/MCP run interruption, cancellation/timeout settlement, rejected shutdown, startup pipe ordering; digest late-open/fstat/stream-close ownership and composed failures; helper startup failure, CI selection, shared mutation/preflight/CLI recovery.
  • Base reproduction or other evidence: observed failing regressions before fixes; independent review replayed the hidden cancellation-stop and primary-timeout/secondary-cleanup failures and confirmed recovery. Real GDB exposed the synchronous-console MI limitation before the retained-handle delivery correction.
  • User-visible CLI/MCP output: exact interrupt yields complete correlated MI and the run retains a *stopped record with reason="signal-received",signal-name="SIGINT"; incomplete cleanup remains a typed error with live resources.
  • Remaining proof gaps: no Windows/macOS execution, no full arbitrary-plugin environment equivalence or containment of unrestricted persistent shell background writers. Rizin was deliberately omitted for the skip-path check; the host does have Rizin.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Current head db95b1fdc; shared close/admission follow-ups b69d50fbb, fa41732bc, db95b1fdc were independently reviewed and imported from #1960. Pinned Node 24.18.0 / npm 11.16.0.

Fresh verification on this head: four focused files (registerCloseLifecycleTool, binarySession, sessionMcp, reverseEngineeringCommands), 80/80 passed; check:fast passed. Independent production-adapter probe: 17/17 passed, covering all cleanup-owner combinations, both settlement orders, resource unions and exactly-once typed synchronous failure. No provider backend/protocol implementation changed in this follow-up, so the real-provider matrix was not rerun.

The following earlier broader evidence is pinned to executable source f9d47d8ec; documentation-only follow-ups 89d4a53c7 and 98690fc05 (Rizin terminal-input help) were separately checked:

  • npm run test:focused with 21 selected provider, MCP, composition, CLI and CI files: 697 passed, 1 platform skip.
  • npm run check:fast: passed, including the post-commit/pre-push gates.
  • npm run docs:check and npm run verify:test-discovery: passed; docs/contract follow-up also passed its fast/docs checks. Built debug-with-rizin --help now explicitly reports stdin/stdout/stderr and possible consumption of terminal input.
  • npm run verify:reverse-providers -- objdump gdb rizin: 48/48 assertions passed on final executable source, real GNU GDB 17.2, objdump 2.46.1 and Rizin 0.7.4 on Linux x86-64. Checks include explicit SIGINT stop, register read, artifact digest preservation, MI rejection negative control and owned debugger count 0 before/after.
  • node scripts/verify-real-reverse-providers.mjs objdump gdb '--skipped=rizin:deliberately omitted to verify multiword skip reporting on a host with Rizin installed': 45/45 passed; exact multiword skip reason and status: skipped independently asserted in the receipt.

The final full command including build took 28.81 s elapsed, 61.14 s user / 8.93 s system CPU; GNU time reported maximum RSS 2,768,948 KiB. These are shared-host observations, not a speedup claim; no equivalent successful before measurement, token totals or aggregate process-family peak memory were measured. The provider-only full run separately took 19.21 s elapsed.

Compatibility, safety, and release

  • Breaking changes or migration steps: fixed analysis sources must use a session-backed server with mutation admission for unrestricted Rizin. Hosts lacking ownership baselines reject required token-sweep launches before execution; use a supported ownership host. These narrow previously unsafe acceptance and cannot be preserved through deprecation without losing the cleanup boundary.
  • Real Hopper/Ghidra, browser, or OS coverage: real GNU providers on Linux only; no new Hopper/Ghidra/browser or Windows/macOS runtime claim.
  • Package or release metadata impact: generated canonical contract description only; no binaries/installers or generated outputs committed.
  • Security, privacy, process, or containment review: exact retained resource owners; incomplete cleanup remains visible. Persistent raw commands/plugins retain their documented host/target/filesystem/network effects. REA_PROCESS_RUN_ID stays reserved inside static Rizin/plugins; caller-value restoration is established separately for debugger inferiors. Overall integration still requires the maintainer decision in [Design] Scope and authority for the GDB, objdump and Rizin providers #3656.

Author readiness

Human owner: @dandgabr

  • 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.

@dandgabr
dandgabr marked this pull request as ready for review October 11, 2026 21:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T16:27:45.797770Z cc3d8d3 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.

@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: 896e1799b3

ℹ️ 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/createServer.ts Resolved
Comment thread docs/reverse-engineering-tools.md 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: 3486fe6f20

ℹ️ 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/cli/reverseEngineeringCommands.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/contracts/toolEffects.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: b9107b97eb

ℹ️ 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/gdb/GdbSessionManager.ts Resolved
Comment thread src/contracts/toolEffects.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/contracts/toolEffects.ts Resolved
Comment thread src/cli/reverseEngineeringCommands.ts Resolved
Comment thread docs/architecture.mermaid 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: 0690e2d77a

ℹ️ 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/contracts/gdbToolContracts.ts Resolved
Comment thread src/server/registerGdbTools.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.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: c43628d519

ℹ️ 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/gdb/GdbSessionManager.ts Resolved
Comment thread src/cli/reverseEngineeringCommands.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.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: 40ede0d75d

ℹ️ 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/contracts/toolEffects.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/objdump/ObjdumpCommand.ts Resolved
Comment thread src/gdb/GdbSessionManager.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: 0ceb1efc4d

ℹ️ 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/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.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: ef26154f3f

ℹ️ 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/cli/reverseEngineeringCommands.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: a226064e63

ℹ️ 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/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

10 similar comments
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

2 similar comments
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: apex

[High impact] The PR reaches shared debugger, analysis-session, and process-ownership paths used by CLI and MCP workflows.

Not ready to merge because failed Rizin preparation can still discard active analysis.

Findings

  1. P1 Failed preparation discards analysis ▶
  2. P2 Cleanup facts have competing copies ▶
Fix with agent prompt
### Issue 1
src/application/binary/BinarySession.ts:undefined-881
The production Rizin adapter still calls `withAdmittedExternalMutation` with four arguments, leaving `mutationStart` at `"admission"`. This line therefore invalidates the snapshot before artifact checks run. A missing file or directory then closes the active analysis despite never launching Rizin. Pass `"provider-dispatch"` from `createServer`, as the new regression does.

### Issue 2
src/gdb/GdbSessionManager.ts:2307-2315
Failure results now rebuild `records`, `console`, `target` and `log` inline, while normal results still use `snapshotGdbCommandRecords`. This violates the repository directive to give each interpretation one owner and remove superseded copies. Future output fixes now have several places to drift.

Reuse the helper across failure paths. Two other examples need the same cleanup: the superseded, test-only `assertRizinEmptyInferiorInventory` and the unused `DEFAULT_TIMEOUT_MS` alternative to `DEFAULT_REVERSE_COMMAND_TIMEOUT_MS`. The pattern appears elsewhere too. This repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The latest update strengthens cancellation tests. The broader PR changes GDB interrupt control, retained cleanup owners, artifact reads, and shared session admission.

  • An exact GDB interrupt can stop a running command without losing its owner.
  • Analysis opens wait while an external debugger may still own a writer.
  • Debugger detach checks target input and output before releasing ownership.
  • One-shot provider calls keep cleanup owners and delay mutation until dispatch.
  • Shared process cleanup keeps ownership and late output visible until it settles.
  • Linux CI checks installed reverse-engineering providers through public commands.
  • Supporting type and test updates keep existing behavior unchanged.

Reviews (76) · Last reviewed commit: "test(reverse): assert cancellation error..." · Reviewed by Greptile

@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: 65a36e28cf

ℹ️ 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/application/binary/BinarySession.ts Outdated
// Do not hold the lifecycle queue while an external writer is still
// active. Its owner may need this queue to interrupt or dispose the
// target before the open can continue.
if (this.#externalMutationOwnerPending) return undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve deferred opens' ordering against later closes

When open_binary is waiting for a retained inferior, queuing its disposition and then close_binary can make the close succeed before the older open resumes. Returning undefined releases the open's queue position, so once disposition settles the writer, the retry is appended behind the already-queued close and recreates an active provider after that close reports success. This reproduces with the actual BinarySession transition methods and stubbed provider collaborators. Preserve a lifecycle reservation, or cancel an open superseded by a later close, while still permitting owner cleanup to run.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in . Added tracking in . Deferred calls capture the epoch when queued and reject with if a subsequent , , or occurs before they resume.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in b1c2ebb63. Added #closeEpoch tracking in BinarySession. Deferred open_binary calls capture the epoch when queued and reject with AnalysisCancelledError if a subsequent close, closeWithSnapshot, or dispose occurs before they resume.

Comment thread src/gdb/GdbSessionManager.ts Resolved
Comment thread src/domain/analysisErrorBase.ts Resolved
Comment thread src/gdb/GdbSessionManager.ts Outdated
Comment on lines +2307 to +2315
const records = [...pending.lines];
pending.reject(
new GdbProtocolFailureError(message, {
command: pending.evidenceCommand,
mi: "",
...snapshotGdbCommandRecords(pending.lines),
records,
console: records.filter((line) => line.startsWith("~")).join("\n"),
target: records.filter((line) => line.startsWith("@")).join("\n"),
log: records.filter((line) => line.startsWith("&")).join("\n"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Cleanup facts have competing copies

Failure results now rebuild records, console, target and log inline, while normal results still use snapshotGdbCommandRecords. This violates the repository directive to give each interpretation one owner and remove superseded copies. Future output fixes now have several places to drift.

Reuse the helper across failure paths. Two other examples need the same cleanup: the superseded, test-only assertRizinEmptyInferiorInventory and the unused DEFAULT_TIMEOUT_MS alternative to DEFAULT_REVERSE_COMMAND_TIMEOUT_MS. The pattern appears elsewhere too. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gdb/GdbSessionManager.ts
Line: 2307-2315

Comment:
**Cleanup facts have competing copies**

Failure results now rebuild `records`, `console`, `target` and `log` inline, while normal results still use `snapshotGdbCommandRecords`. This violates the repository directive to give each interpretation one owner and remove superseded copies. Future output fixes now have several places to drift.

Reuse the helper across failure paths. Two other examples need the same cleanup: the superseded, test-only `assertRizinEmptyInferiorInventory` and the unused `DEFAULT_TIMEOUT_MS` alternative to `DEFAULT_REVERSE_COMMAND_TIMEOUT_MS`. The pattern appears elsewhere too. This repository requirement must be satisfied before merging.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in . Reused in , removed dead in , and eliminated dead in .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in b1c2ebb63. Reused snapshotGdbCommandRecords(pending.lines) in #failProtocol, removed dead assertRizinEmptyInferiorInventory in RizinDebugSessionManager, and eliminated dead DEFAULT_TIMEOUT_MS in ReverseEngineeringService.

@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: 94010f8fa0

ℹ️ 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".

...(partialObservation === undefined ? {} : { partialObservation }),
...(cleanupReport === undefined ? {} : { cleanupReport }),
}).bindCleanupDependencies([
}).resolveCleanup();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep finalized capture errors pending until their owners settle

When capture execution fails and final cleanup also leaves a live cleanup error, resolveCleanup() clears the new wrapper's flag before its dependencies are installed. AnalysisError.bindCleanupDependencies() records owners but never sets cleanupIncomplete back to true: a parent-versus-this-commit source probe reports false on the finalized error while its cleanup dependency remains incomplete and retains resources. projectAnalysisError() consequently unwraps to the ordinary primary and omits cleanup_incomplete and live-resource attribution in the CLI/MCP paths using withFinalization(). Keep the wrapper incomplete until all bound owners resolve.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in . In , properly retains dependency-derived cleanup status while owners remain active.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0477dbd81. In ProcessCaptureError, resolveCleanup() properly retains dependency-derived cleanup status while owners remain active.

Comment thread src/application/binary/BinarySession.ts Resolved
@dandgabr
dandgabr force-pushed the feat/gdb-debugger-integration branch from e444cb2 to 8783800 Compare November 2, 2026 03:59
Comment thread src/application/binary/BinarySession.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: ca1af67c87

ℹ️ 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/application/binary/BinarySession.ts Outdated
Comment on lines +539 to +540
if (this.#closeEpoch !== queuedAtCloseEpoch)
return err(new AnalysisCancelledError("open_binary"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve opens queued after an earlier close

With no debugger owner or aborted signal, enqueueing session.close() and then session.open(path) in the same turn now cancels the open: it captures the current epoch, but the earlier close increments that epoch only when its serialized callback runs. A parent-versus-target probe of the queue methods with provider/snapshot collaborators stubbed confirms success becomes AnalysisCancelledError, leaving the session closed instead of opening the requested target. closeWithSnapshot() has the same ordering problem. Record close generations when closes are enqueued, or restrict this supersession check to deferred-open re-entry, so preceding closes cannot cancel later opens.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1a45578a9. Restricting the epoch supersession check to deferred-open re-entry allows FIFO queued opens to execute naturally without cancellation when preceded by close calls.

@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: cc3d8d36b3

ℹ️ 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 on lines +200 to +202
Session snapshots are invalidated only after provider preparation and artifact
validation succeed, immediately before attempting dispatch. A missing or
non-regular artifact preserves the current session and its replay state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Wire dispatch-based admission before promising preservation

For the production session-backed MCP server, this new preservation guarantee does not hold: src/server/createServer.ts:384–390 still calls withAdmittedExternalMutation with only four arguments, leaving mutationStart at its "admission" default. Consequently, execute_rizin_command with a missing or directory path invalidates replay and retires the healthy analysis client even though Rizin never launches. The added preflight-preservation regression explicitly supplies "provider-dispatch", so it does not exercise the production binding. Pass that mode from the production callback before advertising that failed preflight preserves the session and replay state.

AGENTS.md reference: AGENTS.md:L13-L13

Useful? React with 👍 / 👎.

@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @dandgabr, thanks for the PR! This fix looks good to me. What's left: it has merge conflicts with main in docs/reverse-engineering-tools.md, src/application/binary/BinarySession.ts, src/application/binary/BinarySessionPort.ts and 3 other files (merging main into the branch is fine). Greptile is at 4/5 on the current head, mainly over "Failed preparation discards analysis". Once that's done I'm happy to merge it.

@morluto morluto added bug Something isn't working provider: gdb Analysis provider / engine: gdb labels Nov 23, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for this work! The GDB interrupt and provider cleanup ownership fixes were integrated and landed on main in commit 4aa51bfe19 ("fix(reverse): reconcile cleanup ownership and mutation diagnostics (#2799)", with further cleanup ownership refinements in #12537 / fa9abed521), and related issue #3656 is closed as completed. Closing this PR as already landed.

@morluto morluto closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: providers Provider and capability discovery, including provider proposal triage bug Something isn't working enhancement New feature or request i18n Translations and localization workflow P2: medium Medium priority issue provider: gdb Analysis provider / engine: gdb

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants