Skip to content

feat(process): add owned debugger shutdown lifecycle - #1959

Closed
dandgabr wants to merge 165 commits into
morluto:mainfrom
dandgabr:feat/owned-debugger-process-lifecycle
Closed

dandgabr wants to merge 165 commits into
morluto:mainfrom
dandgabr:feat/owned-debugger-process-lifecycle

Conversation

@dandgabr

@dandgabr dandgabr commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Owned debugger shutdown now shares each full stop attempt, requires verified independent inferior stdin/stdout/stderr before detaching and signalling a POSIX debugger, and retains sessions until process and inherited-output settlement are confirmed. Windows Job Object launches fail closed for direct-child termination; failed native observation continues with referenced, capped-backoff polling, and explicit cleanup promptly resumes polling and drains newly blocked output.

GDB and Rizin verify inferior input through Linux /proc, preserve caller-selected REA_PROCESS_RUN_ID values instead of leaking REA's ownership token, and fail closed on unknown descriptor state. The latest correction requires an explicit GDB input classification: an injected verifier returning no value previously became durable; it now rejects before detach or signalling. Fixtures have bounded lifetimes and ownership-based teardown. Existing CLI load budgets are retained.

This updates existing supervision and debugger consumers; no new provider, tool, execution authority, or mutation gate is introduced. It continues the lifecycle prerequisite split from #1279. Maintainer scope judgment remains required; no new approval is claimed.

Validation (Linux, Node 24.18.0 / npm 11.16.0)

Merged upstream/main through 9af0b6113 in d1c6619de, following the earlier 41aa15462 synchronization. The branch preserves both its CLI timeout and upstream's uninstall regression. GDB input-proof fix: 202d3f7c7.

  • New GDB regression: before correction, 151 passed / 1 failed because unconfirmed input incorrectly allowed successful close; afterward all 152 passed.
  • Focused batch: GdbSessionManagerCoverage, RizinInferiorTty, clientProfileLifecycle, nativeDemangleCli — 182 passed, 1 pre-existing macOS-only skip.
  • Focused batch: GdbSessionReviewRegressions, GdbSessionManagers, GdbCommandQueue, ownedDebuggerSession, providerProcessOutput, WindowsOwnedProcess, inferiorInputSink, RizinDebugSessionManagers, RizinInferiorEnvironment — 99 passed.
  • Latest upstream-sync verification at d1c6619de: 10 focused files passed, 299 tests passed / 4 platform-gated tests skipped, covering debugger lifecycle, GDB coverage, error projection/cleanup and upstream snapshot-handle cleanup through compiled CLI/MCP. npm run check:fast — typecheck and lint passed freshly and again from the pre-push hook; git diff --check passed.
  • Follow-up verification at 049603306: all 43 ownedDebuggerSession tests passed; npm run build:cached, npm run check:fast, and npm run docs:check passed. The actual rebuilt rea debug-with-rizin --help output explicitly includes stdin and warns that the inferior may consume terminal input. Checks used the pinned Node/npm above.
  • Real Rizin 0.7.4 TTY regression executed (not skipped): verified detach, target survival and output after debugger close.
  • Separate production-boundary probe using installed GDB 17.2 and the built GdbSessionManager: a source-owned Python inferior stopped at its own SIGTRAP, detached, survived debugger close, and wrote both stdout/stderr markers to its selected TTY. Fixture resources were cleaned up. Earlier exploratory probes used MI syntax through the console API or waited for a naturally exiting target and did not establish survival; the corrected probe above passed.

The prior 40 review threads were read alongside paginated comments/reviews. Two subsequent findings are corrected in 6ef308f3d and 049603306: Rizin CLI help now explicitly discloses inferior stdin and possible terminal-input consumption; debugger fixture setup prepares the ownership reader before launching fixtures, with the configured Swift compiler budget plus hook overhead. Full ownership-based teardown and its assertions are retained. Independent source review of these two follow-up commits found no actionable issue.

Limits and compatibility

No Windows or macOS runtime was executed here; the cold Swift compile/setup path is source-reviewed but was not reproduced on macOS; Windows tests use native-binding doubles and do not prove Job Object behavior on Windows. No full suite, package-install verification, or public CLI/MCP GDB end-to-end workflow was run. The GDB smoke establishes its production manager boundary only. Unknown detach, input, output, process identity, or settlement retains ownership rather than claiming cleanup. No performance improvement is claimed.

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.

@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-02T15:38:12.006944Z 715cb97 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: eada258ea3

ℹ️ 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/process/ownedDebuggerSession.ts Resolved
Comment thread src/process/ownedDebuggerSession.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: 2667a65daf

ℹ️ 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/process/ownedDebuggerSession.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: 6a68979e65

ℹ️ 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/process/ownedDebuggerSession.ts Resolved
Comment thread src/process/ownedDebuggerSession.ts Resolved
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The new head fixes the hang that Codex flagged and I reproduced. In my runs, Node now exits by itself when a grandchild is left running. Everything else I measured on the earlier head still holds.

I tested head 6a68979 on top of current main 04089d5. I copied the PR's four changed files onto main. The typecheck and lint pass on Node 24. All 13 tests in the two test files pass on Node 22, 24 and 26.

What changed since 2667a65

The new head adds unrefOutputStreams() to the process supervisor. The helper calls it after the debugger exits. That releases the pipes an orphan still holds, so they no longer keep Node alive. The old results are in the fold below.

Case Earlier head 2667a65 New head 6a68979
b2. bash stays, so a sleep is left Node stayed alive (driver exit 80) Node exited by itself (driver exit 0)
c. bash -c 'sleep 300 & wait' Node stayed alive (driver exit 80) Node exited by itself (driver exit 0)
Test count 8 tests in 1 file 13 tests in 2 files

Checks, by Node version

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
Both test files (13 tests) pass pass pass
Typecheck not run pass not run
oxlint on the four changed files not run pass not run
Build and test prep not run pass not run

oxlint exits 0 but warns that ProviderProcess.ts has 513 lines, over the 500 limit. Main alone already warns at 503 lines.

Real processes (Linux, Node 24)

Each child was started through REA's own launcher and supervisor. Times run from the helper call to its return. A batch job from another project ran on the box at the same time, so the times are rough.

Case Signals sent Time How the child ended Node exited by itself? Left behind after
a. sleep 300 SIGTERM 1 ms killed by SIGTERM yes nothing
b. bash -c 'trap "" TERM; sleep 300' SIGTERM, SIGKILL 301 ms killed by SIGKILL yes nothing (bash replaced itself with sleep)
b2. case b plus a trailing echo, so bash stays SIGTERM, SIGKILL 301 ms killed by SIGKILL yes one sleep 300, still running
c. bash -c 'sleep 300 & wait' SIGTERM 1 ms killed by SIGTERM yes one sleep 300, still running
d. gdb running sleep 300 SIGTERM 23 ms gdb exit code 0 yes nothing; gdb took its sleep down with it
d2. gdb attached to a sleep I started SIGTERM 23 ms gdb exit code 1 yes the attached sleep, still running
e1. child already exited none 0 ms exit code 0 yes nothing; result already_exited
e2. case e1's child, but the caller's exited flag is wrong SIGTERM (returned false) 0 ms exit code 0 yes nothing; result stopped
  • Node now exits. In c and b2 the driver exited with code 0, by itself. It took 1.5 and 1.8 seconds. Afterwards ps showed the leftover sleep still alive. I then killed each leftover by PID. On the earlier head the same two cases held Node open until I killed the orphan.
  • Orphans remain. In c and b2 the leftover sleep went to the user systemd (PID 1639). The helper still signals only the direct child, as the PR says.
  • The newest Codex note. It says an LLDB inferior vanished when LLDB got SIGTERM. My case d matches for gdb: its own sleep died with it. In d2 the attached sleep is not gdb's child, and it survived. I did not run LLDB, and I did not check how gdb ends its own sleep.
  • Waits. The helper waits 300 ms after SIGTERM and then 1,000 ms after SIGKILL. REA's supervisor defaults are 250 ms and 1,000 ms (read from the source).

I killed every leftover process by PID. A final ps on every PID I logged showed none left.

Not run

  • Whether output from an orphan is still captured after the debugger exits. The PR has a test for it, and it passed. I did not check it by hand.
  • A retry after an incomplete shutdown with a real process. Only a process stuck in the kernel survives SIGKILL, and I could not make one safely. The fake-process tests in the PR cover it.
  • LLDB, since the Codex note names it.
  • The Windows path. This box is Linux.
  • The full test suite.
  • macOS.

Thanks, dandgabr, for the quick fix.

Changes since the earlier head (old results)

These are my first results, on head 2667a65 added onto main 42b0ed1. I ran them at 10:35 PM to 10:43 PM on 2026-10-11.

Checks, by Node version

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
Test file (8 tests) pass pass pass
Typecheck not run pass not run
oxlint on the two files not run pass not run
Build and test prep not run pass not run

Real processes (Linux, Node 24)

Each child was started through REA's own launcher and supervisor. Times are from the helper call to its return.

Case Signals sent Time How the child ended Left behind after
a. sleep 300 SIGTERM 1 ms killed by SIGTERM nothing
b. bash -c 'trap "" TERM; sleep 300' SIGTERM, SIGKILL 301 ms killed by SIGKILL nothing (bash replaced itself with sleep)
b2. case b plus a trailing echo, so bash stays SIGTERM, SIGKILL 301 ms killed by SIGKILL one sleep 300, still running
c. bash -c 'sleep 300 & wait' SIGTERM 1 ms killed by SIGTERM one sleep 300, still running
d. gdb running sleep 300 SIGTERM 22 ms gdb exited with code 0 nothing; gdb took its sleep down with it
d2. gdb attached to a sleep I started SIGTERM 15 ms gdb exited with code 1 the attached sleep, still running
e1. child already exited none 0 ms exit code 0 nothing; result already_exited
e2. case e1's child, but the caller's exited flag is wrong SIGTERM (returned false) 0 ms exit code 0 nothing; result stopped
  • Grandchildren. In c and b2 the leftover sleep was handed to the user systemd (PID 1639). It kept its old process group number. The helper reported stopped both times. That fits the PR's "direct child only" rule.
  • Node stayed alive. In c and b2 the leftover sleep held the child's stdout and stderr pipes. I inferred this from the launcher's spawn options and from Node exiting as soon as the leftover died. I did not inspect its open files. My test script did not exit on its own. About 5 seconds after the helper returned, I killed the leftover by PID, and Node then exited. This is the situation the third Codex review note describes. I did not time how long Node would wait, because I never let it.
  • gdb. gdb handles SIGTERM fast, in 15 to 22 ms, so SIGKILL never came up. In d, gdb ended its own sleep. In d2, the attached sleep was not a child of gdb, and it kept running. How gdb ends its own sleep is something I did not check.
  • Waits. The helper waits 300 ms after SIGTERM and then 1,000 ms after SIGKILL. REA's supervisor defaults are 250 ms and 1,000 ms (read from the source). Worst case is about 1.3 seconds per session.
  • PR text. The PR body says 6 tests. The file at head has 8, and all 8 ran.

I killed every leftover process by PID. A final ps on every PID I logged showed none left.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • Ptrace scope: 0, so gdb could attach to a sibling process in case d2
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head: 6a68979
  • Base: 04089d5, which is current main.
  • The PR's own base: 7d92d93.
  • Tree: main with the PR's four changed files copied in. Main has not changed those files since their common ancestor 5e219de. I checked with git. So this equals a merge. I ran no git merge.
  • Other: gdb 17.2 (GPL-3.0-or-later)
  • Other: GNU bash 5.3.9 (GPL-3.0-or-later)
  • Other: GNU coreutils 9.10 (GPL-3.0-or-later), for sleep
  • Other: the procps tools 4.0.6 (GPL-2.0-or-later)
  • The box was shared: a batch job from another project ran during the real-process runs.
Commands
# build (Node 24, under an 8 GB memory cap)
npm ci
npm run build
npm run test:prepare
npm run typecheck
oxlint src/process/ownedDebuggerSession.ts src/process/ProviderProcess.ts tests/boundary/process/ownedDebuggerSession.test.ts tests/boundary/process/providerProcessOutput.test.ts
# the PR's two test files, once per Node version
npm run test:focused -- tests/boundary/process/ownedDebuggerSession.test.ts tests/boundary/process/providerProcessOutput.test.ts
# real processes, one case per run (a b b2 c d d2 e1 e2)
node driver.mjs <case>

The driver script starts each child with the repo's spawnOwnedProviderProcess and ProviderProcessSupervisor, from the built dist/process files. It then calls stopOwnedDebuggerProcess with a thin wrapper that logs each signal. After the call it watches the process table, and kills any leftover by PID after 5 seconds.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@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: 4b67b6045b

ℹ️ 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/process/ownedDebuggerSession.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: 310109f54d

ℹ️ 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/process/ownedDebuggerSession.ts Resolved
Comment thread src/process/ownedDebuggerSession.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: 03ac0b6257

ℹ️ 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/process/ownedDebuggerSession.ts Resolved
Comment thread src/process/ownedDebuggerSession.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: 064297f54f

ℹ️ 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/process/ownedDebuggerSession.ts Resolved
Comment thread src/process/ownedDebuggerSession.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.

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

# Conflicts:
#	.jscpd.json
#	docs/reverse-engineering-tools.md
#	src/gdb/GdbSessionManager.ts
#	src/process/ownedDebuggerSession.ts
#	src/rizin/RizinDebugSessionManager.ts
#	src/windows/WindowsOwnedProcess.ts
#	tests/boundary/filesystem/ciTestProjects.test.ts
#	tests/boundary/filesystem/jsonOutputOwnership.test.ts
#	tests/boundary/process/ownedDebuggerSession.test.ts
#	tests/boundary/providers/GdbSessionManagerCoverage.test.ts
#	tests/boundary/providers/RizinDebugSessionReviewRegressions.test.ts
#	vitest.config.ts
Comment thread src/windows/WindowsOwnedProcess.test.ts Resolved
Comment thread src/rizin/RizinDebugSessionManager.ts Resolved
Comment thread src/rizin/RizinDebugSessionManager.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: 4ea9d49981

ℹ️ 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 +1474 to +1478
if (session.completedDetachCommand !== undefined)
return this.#verifyCompletedDetachCommand(
session,
session.completedDetachCommand,
);

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 Synchronize transport before retrying a retained detach receipt

If a cleanup control reply exceeds a frame/output limit after o- completes, or while verifying a confirmed detach, the receiver leaves session.protocolError set. These new early-return paths bypass #synchronizeCleanup, so subsequent retries reject on the retained protocol error or queued late frames even after the provider starts returning valid replies. Consequently, retryCleanupFailures() cannot release the session through the recovery path that remains available without a retained receipt. Run the existing synchronization step before entering either retained-detach branch, preserving the receipt so recovery does not repeat the detach command.

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 4ad3fdb19. #detachInferiorUnlocked now synchronizes cleanup transport via #synchronizeCleanup(session) when session.protocolError !== undefined before verifying or returning retained detach command receipts. Focused tests and check:fast pass.

}
else if (line === "e dbg.exitkills") process.stdout.write("false\\0");
else if (line.startsWith("!echo ")) process.stdout.write(line.slice(6) + "\\0");
else process.stdout.write("\\0");

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 Fake providers accept unknown commands

The new fake provider answers every unknown command with an empty success frame. docs/testing.md requires protocol fixtures to reject unmodeled commands. A misspelled or unexpected cleanup command can therefore pass this boundary instead of failing where it was sent.

List expected no-output commands explicitly and surface unknown commands as test failures. The same fallback appears in createRetryableDetachProvider and elsewhere. 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: tests/boundary/providers/RizinDebugSessionReviewRegressions.test.ts
Line: 273

Comment:
**Fake providers accept unknown commands**

The new fake provider answers every unknown command with an empty success frame. `docs/testing.md` requires protocol fixtures to reject unmodeled commands. A misspelled or unexpected cleanup command can therefore pass this boundary instead of failing where it was sent.

List expected no-output commands explicitly and surface unknown commands as test failures. The same fallback appears in `createRetryableDetachProvider` and elsewhere. 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 715cb9797. Fake providers in RizinDebugSessionReviewRegressions.test.ts now reject unmodeled commands with unmodeled command: <line> to stderr and exit with non-zero code to fail closed rather than pretending unknown requests succeeded with \0.

Comment on lines +982 to +983
expect(started.ok).toBe(true);
if (!started.ok) return;

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 Startup failures lose their reason

The new success cases assert started.ok and then return on failure instead of throwing started.error. docs/testing.md explicitly requires throwing the typed error before asserting a successful Result. These failures currently show only a boolean mismatch, hiding the useful startup and cleanup details.

Replace this pattern here and in the other added success cases. 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: tests/boundary/providers/RizinDebugSessionReviewRegressions.test.ts
Line: 982-983

Comment:
**Startup failures lose their reason**

The new success cases assert `started.ok` and then return on failure instead of throwing `started.error`. `docs/testing.md` explicitly requires throwing the typed error before asserting a successful `Result`. These failures currently show only a boolean mismatch, hiding the useful startup and cleanup details.

Replace this pattern here and in the other added success cases. 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.

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 715cb9797. Replaced expect(started.ok).toBe(true); if (!started.ok) return; across all test cases with if (!started.ok) throw started.error; so startup failures preserve and surface the typed error.

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

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

const failure = cause instanceof Error ? cause : new Error(String(cause));
// Native polling is not atomic: it may drain one stream before a later
// read (stderr or job state) fails. Retrying cannot recover those bytes.
this.#outputIncomplete = true;

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 Keep native close failures separate from output loss

On Windows, when process_poll successfully reports a settled job with both output streams fully drained, #release() can still throw because process_close fails. This catch now sets the sticky outputIncomplete flag for that handle-release failure, so even a successful cleanup retry leaves ProviderProcessSupervisor.snapshot() and snapshotOutputSince() reporting the fully captured output as truncated/incomplete. Distinguish failed polling from failed handle release here so cleanup uncertainty does not invalidate an already completed output observation.

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

Useful? React with 👍 / 👎.

Comment thread src/rizin/RizinDebugSessionManager.ts Outdated
observedPids: [],
overflow: true,
error: new Error(
"Rizin `olj` response exceeds the safe inferior row limit.",

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 Limit errors hide their values

The new olj overflow errors omit the fixed 262,144-character and 1,024-row ceilings. The repository requires fixed-limit failures to state the value, say there is no runtime override, and name controls that cannot raise it.

Add those details to the size, row, and retained-identity overflow errors so callers do not try changing unrelated debugger budgets when close fails. 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/rizin/RizinDebugSessionManager.ts
Line: 2304

Comment:
**Limit errors hide their values**

The new `olj` overflow errors omit the fixed 262,144-character and 1,024-row ceilings. The repository requires fixed-limit failures to state the value, say there is no runtime override, and name controls that cannot raise it.

Add those details to the size, row, and retained-identity overflow errors so callers do not try changing unrelated debugger budgets when close fails. 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 715cb9797. parseRizinPtraceRows now explicitly states the exact limits (262,144 characters or 1,024 rows), notes that the release has no runtime override, and notes that debugger settings or controls cannot raise them.

Comment on lines +39 to +43
const createTempDirectory = async (prefix: string): Promise<string> => {
const dir = await mkdtemp(join(tmpdir(), prefix));
directories.push(dir);
directory = dir;
return dir;

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 Directory cleanup bypasses shared owner

createTempDirectory adds another directory tracker instead of the createTestTempDirectory owner required by CONTRIBUTING.md. The new removal loop also hides deletion failures.

Use the shared helper and remove the local tracking and deletion. Keep process teardown in afterEach, which runs first. The new RizinInferiorEnvironment.test.ts and inferiorInputSink.test.ts repeat this direct-mkdtemp pattern. This repository requirement must be met before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/boundary/providers/RizinDebugSessionReviewRegressions.test.ts
Line: 39-43

Comment:
**Directory cleanup bypasses shared owner**

`createTempDirectory` adds another directory tracker instead of the `createTestTempDirectory` owner required by `CONTRIBUTING.md`. The new removal loop also hides deletion failures.

Use the shared helper and remove the local tracking and deletion. Keep process teardown in `afterEach`, which runs first. The new `RizinInferiorEnvironment.test.ts` and `inferiorInputSink.test.ts` repeat this direct-`mkdtemp` pattern. This repository requirement must be met 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.

Comment on lines +71 to +77
expect(parsed.error?.message).toContain(
"safe inferior row limit of 1,024 rows",
);
expect(parsed.error?.message).toContain("no runtime override");
expect(parsed.error?.message).toContain(
"debugger settings or controls cannot raise 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 Tests depend on error wording

These new assertions pin explanatory phrases in Error.message, so harmless rewording breaks the tests. docs/testing.md requires checking limit facts instead of explanatory wording. It also says guidance checks should use the owning formatter alongside independent behavior checks.

Keep the overflow and empty-row checks, test the limit values and override policy as facts, and check delivered guidance against its owner. The oversized-text checks at lines 83–89 have the same issue. This repository requirement must be met before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/boundary/providers/RizinDebugSessionReviewRegressions.test.ts
Line: 71-77

Comment:
**Tests depend on error wording**

These new assertions pin explanatory phrases in `Error.message`, so harmless rewording breaks the tests. `docs/testing.md` requires checking limit facts instead of explanatory wording. It also says guidance checks should use the owning formatter alongside independent behavior checks.

Keep the overflow and empty-row checks, test the limit values and override policy as facts, and check delivered guidance against its owner. The oversized-text checks at lines 83–89 have the same issue. This repository requirement must be met 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!

@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: 715cb9797d

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

const parsed = parseLinuxProcessStat(stat);
if (parsed === undefined || parsed.pid !== Number(pid))
throw new Error(`Inferior PID ${pid} has an unreadable process identity.`);
if (parsed.lifecycle === "zombie" || parsed.lifecycle === "dead") return null;

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 Check all inferior threads before accepting a zombie as ended

When a multithreaded Linux inferior's main thread calls pthread_exit while a worker remains alive, /proc/<tgid>/stat reports Z for the leader even though the thread group is still running; a local pthread fixture confirmed this case. This new null result makes verifyOwnedInferiorsEnded return true, and Rizin's #resolveInferiorRowIdentity can discard the listed inferior and return no-inferior without checking its descriptors or debugger exit policy. Cleanup can therefore signal or release the debugger while live inferior threads remain. Retain the identity until the whole thread group is proven ended rather than treating the leader's zombie state as process exit.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

@CassieFox23

CassieFox23 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Results for head 715cb97 are in my review.

🤖 Written with Claude Code (Opus 5.5), posted with my OK 🦊

@CassieFox23 CassieFox23 left a comment

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.

TL;DR: My earlier findings still hold on head 715cb97, and I found nothing new that is wrong. 18 test files pass on Node 22, 24 and 26 in a Fedora VM, and they also pass on this head merged onto current main. Real gdb runs match my earlier ones, and a program with a pipe on stdin keeps the debugger session open, as the docs say.

This follows my earlier result on head 7fc92fa. Since then the PR grew from 15 files to 35, mostly Rizin. It now touches 19 test files, not 8. The base is now 144843c. All 8 files from my old list are among the 18 I ran.

Results

Check Node 22.23.4 Node 24.22.1 Node 26.12.1
PR's test files on head (18 files, 541 pass, 2 skipped) pass pass pass
Same files on head merged onto main c3647ad (#8824) not run pass (541 pass, 2 skipped) not run
Same files with the PR's source files put back to the merge base 144843c not run 12 files fail (92 tests), 6 files pass not run

The 18 files are the 17 test files the PR touches that I could run, plus providerProcessOutput.test.ts from my old list. The 2 skipped tests are the macOS-only case in nativeDemangleCli.test.ts and the one real-Rizin case, because the VM has no Rizin. In the last row, the two new inferiorInputSink test files cannot load without the new source file.

Real programs (Node 24.22.1, gdb 17.2), head 715cb97

Check Result now Same as on 7fc92fa?
Six single stops (listed below the tables) stopped or already exited, same signals yes
Two stop calls at once on a child that ignores SIGTERM 1 SIGTERM, then 1 SIGKILL; both calls return stopped yes
An orphan holds the output pipes (2 cases) incomplete after 1.3 s and 1.0 s; Node stays alive until my script kills the orphan yes
gdb debugging sleep, caller sets no run ID: the program's environment has no run ID yes
Same, caller sets REA_PROCESS_RUN_ID holds the caller's value yes

New checks at this head. Each one is new, so there is nothing from 7fc92fa to compare:

Check Result
Run ID =abc, and run ID x=y z reach the program unchanged
Run ID with a leading space, or with a line break gdb start refused, with an error that names the run ID
Program's stdin is /dev/null, a regular file, or closed close succeeds; the program keeps running
The program reopens its own stdin as a pipe close returns an error that says stdin is not the terminal, /dev/null or a regular file; the session stays owned
Identity read on a zombie process, a live one and a missing one zombie: none, live: a start time, missing: none
Process table after six debugger test files no user process left

The six single stops were a plain child and a child that ignores SIGTERM. Two used gdb, one attached to a running program. The last two were a child that had already exited, and a wrong exited flag. After close, the debugged program kept running and kept the selected terminal as its stdin, as before. I killed each program by its PID. I did not run main for the pipe case, so I cannot say what main does there.

Should fix

Nothing I could show.

Nit

  • Orphan keeps Node alive. When an orphan holds the output pipes, the stop returns incomplete and keeps ownership. The code then never reaches unrefOutputStreams() (src/process/ownedDebuggerSession.ts line 266), so Node waits for the orphan. This is the same as in my two earlier results and not a change from this PR. A line in the docs would help if it is meant.
  • Size. About 870 changed lines of Rizin source came in since my last result, plus 3,200 of Rizin tests. I could not run Rizin. There are also small edits outside the debugger folders (CdpEndpoint.ts, PcapSnapshot.ts, analysisErrorBase.ts). A separate PR for Rizin might be easier to review. That is the maintainers' call.

Looks good

  • Two stop calls at once now send each signal once (ownedDebuggerSession.ts line 391). The PR's test for it fails on the merge-base source.
  • The program gets no run ID, or the caller's own, while gdb itself keeps REA's. Values GDB cannot carry are refused at start.
  • The stdin check before detach works against a real gdb. It lets the terminal, /dev/null, a regular file and a closed descriptor through. It refuses a pipe.
  • A zombie process counts as gone, checked on a real zombie.
  • No process was left behind after the debugger tests.
  • CI on this head (I read it, I did not run it): 37 pass, 14 skipped, 0 failing.

Not run

  • Rizin for real: it is not installed in the VM, and the VM has no network. The Rizin changes ran only through the PR's fake-Rizin tests.
  • Windows: the Job Object changes ran only as the PR's unit tests with fake native calls. CI's Windows lane passed, but I did not run it.
  • macOS, and the one macOS-only case in nativeDemangleCli.test.ts.
  • clientProfileLifecycle.test.ts and hopperDownloadHttpFailure.test.ts: the first runs doctor and the second builds a doctor fixture, so I skipped both.
  • A process-table scan during the tests. I scanned before and after.
  • A retry after an incomplete stop with a real process stuck in the kernel.
  • Main again: I did not re-run main, so the "on main" rows of my earlier result stand as they were.
  • The whole suite. CI ran it.
  • Which bot review threads GitHub shows as resolved. I read only the ones about run IDs and stdin.

Thanks, dandgabr, for the fixes since my last result.

Test setup
  • Box: Fedora 44 VM (4 vCPUs, 8 GB) on my Nobara 44 machine; VM kernel Linux 7.2.11
  • Node: 22.23.4, 24.22.1, 26.12.1
  • Head / base: 715cb97 / 144843c
  • Other: main c3647ad (#8824) (for the merged run); gdb 17.2 (GPL-3.0-or-later)
Commands
# in the VM, offline, each Node's folder first on PATH
npm ci --offline
npm run test:prepare
npm run test:focused -- src/application/AnalysisContextQueries.test.ts src/browser/WebBundleAnalysisWorker.test.ts src/cliJsonPaths.test.ts src/domain/analysisErrorCleanup.test.ts src/ida/IdaOperationFailures.test.ts src/process/inferiorInputSink.identityRace.test.ts src/process/inferiorInputSink.test.ts src/windows/WindowsOwnedProcess.test.ts tests/boundary/cli/nativeDemangleCli.test.ts tests/boundary/pcap/pcapSnapshotCancellation.test.ts tests/boundary/process/ownedDebuggerSession.test.ts tests/boundary/process/providerProcessOutput.test.ts tests/boundary/providers/GdbSessionManagerCoverage.test.ts tests/boundary/providers/RizinDebugSessionManagers.test.ts tests/boundary/providers/RizinDebugSessionReviewRegressions.test.ts tests/boundary/providers/RizinInferiorEnvironment.test.ts tests/boundary/providers/RizinInferiorExit.test.ts tests/boundary/providers/RizinInferiorTty.test.ts

For the "merge-base source" row I copied the tree, put the merge base's version of each of the PR's 14 non-test source files over it, deleted inferiorInputSink.ts, and ran the same command on Node 24. For the merged row I took main's tree, laid the PR's files over it, merged the 2 files that both touched with git merge-file (no conflicts), re-ran test:prepare, and ran the same command on Node 24.

The real-process runs used the same small scripts as before. One calls stopOwnedDebuggerProcess on real children. The other starts GdbSessionManager with a pseudo-terminal as the program's terminal, runs starti 300 on sleep (with < /dev/null, < /etc/hostname or <&- added for the stdin cases; for the pipe case it runs bash -c 'exec 0< <(sleep 300); exec sleep 300' under catch syscall clock_nanosleep), reads the program's environment and stdin link under /proc, then calls close. The zombie check starts a shell whose child exits while the parent never waits for it, then calls readLinuxProcessStartTime on it. Each of these scratch scripts ran only in the VM.

🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @dandgabr, thanks for this! The addition looks good. What's left: it has merge conflicts with main in docs/reverse-engineering-tools.md and src/application/native/NativeFunctionMatchingService.ts (merging main into the branch is fine). Greptile is at 4/5 on the current head, mainly over "Directory cleanup bypasses shared owner". Once that's done I'm happy to merge it.

@CassieFox23

Copy link
Copy Markdown
Contributor

Hi! This PR's checks pass, but GitHub shows a merge conflict with main. A rebase on main should clear it, and then it's ready for a maintainer to review. No rush.

🤖 Written with Claude Code (Opus 5.5), posted with my OK 🦊

@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for this work! The owned debugger shutdown lifecycle changes were integrated and landed on main in commit 4aa51bfe19 ("fix(reverse): reconcile cleanup ownership and mutation diagnostics (#2799)"), so we are 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: providers Provider and capability discovery, including provider proposal triage area: runtime Process capture and runtime observation enhancement New feature or request P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants