Skip to content

fix(debuggers): report Rizin shell refusals and why debugger sessions stopped - #10398

Merged
N0zoM1z0 merged 2 commits into
mainfrom
fix/rizin-command-and-session-outcomes
Nov 14, 2026
Merged

N0zoM1z0 merged 2 commits into
mainfrom
fix/rizin-command-and-session-outcomes

Conversation

@N0zoM1z0

@N0zoM1z0 N0zoM1z0 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Two debugger and command results that hid what actually happened.

  • execute_rizin_command reported completion_status: "complete" with exit code 0 when Rizin's shell refused the command, so an empty stdout read as a real empty result.
  • After REA stopped a Rizin debug session, or the debugger exited, later commands failed with a generic invalid_request and status gave no reason. GDB had the same pattern.

Fixes #10364
Fixes #8024

Problem and expected behavior

Change and scope

  • The Rizin command profile adds rejection(stderr), which classifies only those four lines and only for a completed process. The shared one-shot service reports completion_status: "rejected" and a limitation naming the refusal; it says stdout holds only earlier statements' output. Other ERROR: lines (for example Cannot 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.ts gives both managers one owner for "unknown session" (invalid_request) and "stopped session" (capability_unavailable with the reason and close-then-restart recovery).
  • Both managers keep a published session addressable until close_*_session, record the first stop reason, and report it as closed_reason in status. A GDB command deadline now records its reason, as cancellation already did. Retained stopped sessions keep their max_sessions slot, and the capacity recovery now says so.
  • fix(rizin): qualify process completion in command evidence #10377 reconciliation: see Related below.
  • Not included: log-level handling. A command that lowers log.level or 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_status gains "rejected" (one-shot command observations only). rizin_debug_session_status and gdb_session_status gain optional closed_reason. Commands on a stopped session return capability_unavailable instead of invalid_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 added or updated:
    • 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 benign ERROR: lines. A real-Rizin variant is skipped when rizin is absent.
    • tests/boundary/mcp/rizinStoppedSessionMcp.test.ts, plus updates to gdbCancellationMcp, GdbSessionManagerCoverage and RizinDebugSessionCoverage.part3: stopped-session status, command refusal, and unknown-ID behavior.
  • Base reproduction: with src/ reverted, 18 of those tests fail across all 5 files.

Validation performed

  • npm run test:focused -- with all Gdb*/Rizin* provider tests plus the new and updated MCP and acceptance files and the completion_status consumers (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

  • Breaking changes: callers that treat any non-"complete" status as unknown are unaffected. Callers that matched invalid_request for a stopped session now see capability_unavailable.
  • Real coverage: Linux x64. The GDB and Rizin session tests use the repo's existing provider fixtures; I did not separately confirm a real-debugger run. Rizin is not installed here, so the Rizin refusal path is simulated using captured 0.9.1 output.
  • Process/containment: stopped sessions keep no live process, only bounded history (64 frames × 16 KiB).

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 rejected for its refused axffj case, and keeps complete for q and for refusal text on stdout. #8025 (Nikhila-Dhevi-R) addressed the Rizin half of #8024.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-14T02:53:26.924597Z 21e974c 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 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5 Tier: plus

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

Findings

  1. P2 Original stop reason disappears ▶
  2. P2 Deadline message is never saved ▶
Fix 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.

Summary

Adds Rizin shell-refusal detection and keeps stopped debugger sessions addressable until explicit close.

  • Rizin command results identify shell refusals.
  • Stopped GDB and Rizin sessions explain why they ended.

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
Loading

Reviews (1) · Last reviewed commit: "fix(debuggers): keep stopped Rizin and G..." · Reviewed by Greptile

Comment on lines +1118 to +1126
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.`;

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 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.`;

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

@gensokyo-dev
gensokyo-dev force-pushed the fix/rizin-command-and-session-outcomes branch from b32a3b1 to 662f5e2 Compare November 13, 2026 18:57

@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: 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".

Comment on lines +46 to +50
export const RIZIN_DEBUG_SESSION_TOOLS = {
providerId: "rizin",
name: "Rizin",
start: "start_rizin_debug_session",
close: "close_rizin_debug_session",

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 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 👍 / 👎.

Comment thread src/rizin/RizinCommand.ts
Comment on lines +74 to +78
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.`;

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 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 👍 / 👎.

gensokyo-dev and others added 2 commits November 14, 2026 02:49
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]>
@gensokyo-dev
gensokyo-dev force-pushed the fix/rizin-command-and-session-outcomes branch from 662f5e2 to 21e974c Compare November 14, 2026 02:51

@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: 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".

Comment on lines +1488 to +1491
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.`;

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 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 gensokyo-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved after CI.

@N0zoM1z0
N0zoM1z0 merged commit ee339e5 into main Nov 14, 2026
47 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/rizin-command-and-session-outcomes branch November 14, 2026 03:42
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working provider: rizin Analysis provider / engine: rizin labels 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 bug Something isn't working provider: rizin Analysis provider / engine: rizin

Projects

None yet

3 participants