Repository navigation
fix(debuggers): report Rizin shell refusals and why debugger sessions stopped - #10398
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR changes result reporting for one-shot Rizin commands and session handling for both persistent debuggers. Appears safe to merge, with two non-blocking fixes for debugger stop diagnostics. FindingsFix with agent prompt### Issue 1
src/rizin/RizinDebugSessionManager.ts:1118-1126
`closed_reason` is rebuilt from cleanup state instead of being saved when the session stops. If Rizin or GDB exits and close cannot verify the target's state, close sets `closeRequested` and retains the session. Later status and commands then report that close started, hiding the earlier exit code and signal.
Rizin also saves `stopReason` only after cleanup synchronization succeeds. Late oversized output can therefore replace an earlier timeout or output-limit reason before it is saved. Save the first stop reason when the session stops, separately from cleanup progress.
### Issue 2
src/gdb/GdbSessionManager.ts:2227
The new `session.protocolError ??=` never saves its deadline message. The same timer callback always assigns `session.protocolError` at lines 2182–2183 first, with no intervening clear. Status keeps the old generic timeout text, while this second write misleadingly suggests that the accepted deadline is retained. Put the deadline-specific message in the existing assignment and remove this redundant write.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds Rizin shell-refusal detection and keeps stopped debugger sessions addressable until explicit close.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[One-shot Rizin completes] --> B{Recognized refusal on stderr?}
B -->|Yes| C[Rejected observation with raw output]
B -->|No| D[Complete observation]
E[Debugger session ready] --> F[Debugger exits or REA stops admission]
F --> G[Retain stopped session and report reason]
G --> H[Later commands refused with recovery steps]
G --> I[Explicit close]
I --> J{Cleanup confirmed?}
J -->|Yes| K[Release session ID and capacity]
J -->|No| G
Reviews (1) · Last reviewed commit: "fix(debuggers): keep stopped Rizin and G..." · Reviewed by Greptile |
| const diagnosed = session.stopReason ?? session.protocolError; | ||
| if (diagnosed !== undefined) return diagnosed; | ||
| if (this.#closingAll) | ||
| return "REA is shutting down and closing every Rizin debug session."; | ||
| if (session.closeRequested) | ||
| return "close_rizin_debug_session started releasing this session, and its owned cleanup has not completed."; | ||
| if (session.exited) { | ||
| const { exitCode, signalCode } = session.launched.process; | ||
| return `The Rizin process exited (exit code ${String(exitCode)}, signal ${String(signalCode)}); a command such as q, or a crash, can end it.`; |
There was a problem hiding this comment.
Original stop reason disappears
closed_reason is rebuilt from cleanup state instead of being saved when the session stops. If Rizin or GDB exits and close cannot verify the target's state, close sets closeRequested and retains the session. Later status and commands then report that close started, hiding the earlier exit code and signal.
Rizin also saves stopReason only after cleanup synchronization succeeds. Late oversized output can therefore replace an earlier timeout or output-limit reason before it is saved. Save the first stop reason when the session stops, separately from cleanup progress.
Knowledge Base Used: Debugger and disassembler integrations
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/rizin/RizinDebugSessionManager.ts
Line: 1118-1126
Comment:
**Original stop reason disappears**
`closed_reason` is rebuilt from cleanup state instead of being saved when the session stops. If Rizin or GDB exits and close cannot verify the target's state, close sets `closeRequested` and retains the session. Later status and commands then report that close started, hiding the earlier exit code and signal.
Rizin also saves `stopReason` only after cleanup synchronization succeeds. Late oversized output can therefore replace an earlier timeout or output-limit reason before it is saved. Save the first stop reason when the session stops, separately from cleanup progress.
**Knowledge Base Used:** [Debugger and disassembler integrations](https://app.greptile.com/-/switch-tenant?tenant=pre&next=%2Fcustom-context%2Fknowledge-base%2Fmorluto%2Frea%2F-%2Fdocs%2Fdebugger-and-disassembler-integrations.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| "The unrestricted GDB console can access local shell, filesystem, network, and target controls.", | ||
| ], | ||
| }); | ||
| session.protocolError ??= `A GDB command exceeded its ${String(acceptedDeadline.value)} ms deadline; owned-session shutdown was requested because output correlation can no longer be guaranteed.`; |
There was a problem hiding this comment.
Deadline message is never saved
The new session.protocolError ??= never saves its deadline message. The same timer callback always assigns session.protocolError at lines 2182–2183 first, with no intervening clear. Status keeps the old generic timeout text, while this second write misleadingly suggests that the accepted deadline is retained. Put the deadline-specific message in the existing assignment and remove this redundant write.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gdb/GdbSessionManager.ts
Line: 2227
Comment:
**Deadline message is never saved**
The new `session.protocolError ??=` never saves its deadline message. The same timer callback always assigns `session.protocolError` at lines 2182–2183 first, with no intervening clear. Status keeps the old generic timeout text, while this second write misleadingly suggests that the accepted deadline is retained. Put the deadline-specific message in the existing assignment and remove this redundant write.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.b32a3b1 to
662f5e2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 662f5e2b59
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| export const RIZIN_DEBUG_SESSION_TOOLS = { | ||
| providerId: "rizin", | ||
| name: "Rizin", | ||
| start: "start_rizin_debug_session", | ||
| close: "close_rizin_debug_session", |
There was a problem hiding this comment.
Keep provider tool metadata out of the domain layer
This new domain module hard-codes Rizin operation names and provider identity, and the following constant does the same for GDB, making provider/adapter vocabulary flow into the domain layer. Keep the shared error construction provider-neutral and define this metadata in the corresponding provider or server adapters.
AGENTS.md reference: AGENTS.md:L15-L17
Useful? React with 👍 / 👎.
| for (const text of stderr.split(/\r?\n/u)) | ||
| for (const { line, refused } of RIZIN_SHELL_REFUSALS) { | ||
| const match = line.exec(text); | ||
| if (match !== null) | ||
| return `Rizin refused ${refused(match)} (ERROR line on stderr). It skips a refused statement and every later one, so stdout holds at most the output of earlier statements; empty stdout is not an empty result. Correct the statement, using <command>? for Rizin's help, and run it again.`; |
There was a problem hiding this comment.
Do not infer rejection from unauthenticated stderr text
When a valid caller-selected command, retained plugin, or invoked shell program writes a matching ERROR: line to the shared process stderr, this parser reports completion_status: "rejected" and claims later statements did not run even though the Rizin shell may have accepted the command. Because stderr does not identify which component produced a line, preserve this as an observed diagnostic or obtain provider-authenticated refusal provenance rather than converting the text match into a definitive rejection.
AGENTS.md reference: AGENTS.md:L19-L21
Useful? React with 👍 / 👎.
Rizin exits 0 when its shell refuses a statement, so execute_rizin_command reported completion_status complete with exit code 0 and an empty stdout that read as a genuine empty result. Rizin 0.6 through 0.9.1 log exactly four refusal lines from librz/core/cmd/cmd.c: an unknown command, a wrong argument count, an invalid statement (RZ_CMD_STATUS_INVALID, which also stops the remaining statements) and a parse error. The Rizin command profile now classifies a completed process's stderr against those lines; the shared one-shot service reports completion_status "rejected" and a limitation that names the refusal and says stdout holds only earlier statements' output. Other ERROR lines come from commands that ran and stay diagnostics. Fixes #10364 Co-Authored-By: gensokyo-dev <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
After REA stopped a Rizin debug session (frame or output limit, deadline, cancellation, protocol failure) or the debugger exited, later commands returned a generic invalid_request and status gave no reason. GDB collapsed the same states the same way. Both managers now keep a published session addressable until close_*_session releases it, record the first reason it stopped, report it as closed_reason in session status, and refuse later commands with capability_unavailable naming that reason and the close-then-restart recovery. An ID the server never returned, or that close released, still fails as invalid_request with its own recovery. Retained stopped sessions keep their slot, which the capacity recovery now says. A GDB command deadline now records its reason like cancellation already did. Fixes #8024 Co-Authored-By: gensokyo-dev <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
662f5e2 to
21e974c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21e974cddf
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (session.closeRequested) | ||
| return "close_gdb_session started releasing this session, and its owned cleanup has not completed."; | ||
| if (session.exited) | ||
| return `The GDB process exited (exit code ${String(session.exitCode)}, signal ${String(session.exitSignal)}); a command such as quit, or a crash, can end it.`; |
There was a problem hiding this comment.
Preserve the process-exit reason when close cleanup fails
When an already-exited debugger still has inherited output open, close() sets closeRequested before cleanup can return incomplete; this ordering then makes status and later commands report that close started instead of retaining the earlier process-exit reason. The same precedence exists in RizinDebugSessionManager.ts:1122-1126, contradicting the documented first-reason guarantee and discarding the useful exit provenance while the failed cleanup remains addressable; prefer the exit reason or store the first reason explicitly.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
gensokyo-dev
left a comment
There was a problem hiding this comment.
Approved after CI.
Summary
Two debugger and command results that hid what actually happened.
execute_rizin_commandreportedcompletion_status: "complete"with exit code 0 when Rizin's shell refused the command, so an empty stdout read as a real empty result.invalid_requestand status gave no reason. GDB had the same pattern.Fixes #10364
Fixes #8024
Problem and expected behavior
librz/core/cmd/cmd.cfor v0.6.0, v0.8.1 and v0.9.1: an unknown command, a wrong argument count,RZ_CMD_STATUS_INVALID(which also jumps past the remaining statements) and parse errors log fixedERROR:lines. Expected: report a refusal, not a complete empty result.Change and scope
rejection(stderr), which classifies only those four lines and only for a completed process. The shared one-shot service reportscompletion_status: "rejected"and a limitation naming the refusal; it says stdout holds only earlier statements' output. OtherERROR:lines (for exampleCannot find function) come from commands that ran and stay diagnostics. The objdump profile is unchanged: objdump reports failures through its exit status.src/domain/debuggerSessionErrors.tsgives both managers one owner for "unknown session" (invalid_request) and "stopped session" (capability_unavailablewith the reason and close-then-restart recovery).close_*_session, record the first stop reason, and report it asclosed_reasonin status. A GDB command deadline now records its reason, as cancellation already did. Retained stopped sessions keep theirmax_sessionsslot, and the capacity recovery now says so.log.levelor redirects stderr hides refusals from REA; this is documented, not detected.Contribution scope: ordinary fix within existing boundaries; maintainer scope decision not applicable.
Contract and boundary impact
CLI and MCP:
completion_statusgains"rejected"(one-shot command observations only).rizin_debug_session_statusandgdb_session_statusgain optionalclosed_reason. Commands on a stopped session returncapability_unavailableinstead ofinvalid_request.Evidence: rejected commands keep raw stdout/stderr; the refusal is a limitation, not a rewrite.
Launch or attach to a process.
Evidence and regression coverage
tests/acceptance/rizinCommandRejection.test.ts: CLI and MCP with simulated Rizin, using outputs captured from the official Rizin 0.9.1 static build. It covers each refusal line, multi-statement prefixes and benignERROR:lines. A real-Rizin variant is skipped whenrizinis absent.tests/boundary/mcp/rizinStoppedSessionMcp.test.ts, plus updates togdbCancellationMcp,GdbSessionManagerCoverageandRizinDebugSessionCoverage.part3: stopped-session status, command refusal, and unknown-ID behavior.src/reverted, 18 of those tests fail across all 5 files.Validation performed
npm run test:focused --with allGdb*/Rizin*provider tests plus the new and updated MCP and acceptance files and thecompletion_statusconsumers (44 files): 719 passed, 8 skipped. The one failure in that run came from my own wording change in the acceptance expectation; I fixed it and the rerun passes.npm run check:fast: passed.npm run docs:check: passed.Compatibility, safety, and release
"complete"status as unknown are unaffected. Callers that matchedinvalid_requestfor a stopped session now seecapability_unavailable.Author readiness
Human owner: N0zoM1z0 (PR author, exempt from the declaration per CONTRIBUTING.md).
Related: #10377 (merged) added an always-present limitation that command validity is unverified. This PR keeps it, narrowed to what stays unverified after refusal detection: statements that ran and failed while Rizin exits 0. #10377's acceptance test now expects
rejectedfor its refusedaxffjcase, and keepscompleteforqand for refusal text on stdout. #8025 (Nikhila-Dhevi-R) addressed the Rizin half of #8024.🤖 Generated with Claude Code