Skip to content

fix(native): name the retained pwntools process group in cleanup resources - #2281

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/issue-2274
Oct 13, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/issue-2274

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

Sometimes a pwntools or pwndbg provider stage can't confirm that its owned process group stopped. PwntoolsDecoder.#retireProcess then builds the retained ProviderCleanupError with only the run ID and the private runtime directory. In that state a descendant of the retained group can still be live: the existing stage-retirement test asserts process.kill(descendant, 0) succeeds. Yet the projected cleanup_incomplete result did not identify the process group the caller must inspect.

While the supervisor is retained, the resources now also include pid:<leaderPid> and process-group:<processGroupId> from its launch ownership. That matches OwnedCommand's own non-transferred cleanup error ([runId, cwd, pid:…, process-group:…]). Nothing else changes.

Codex raised this on #1708 after it merged (PwntoolsDecoder.ts:521).

Fixes #2274

Before / after (does not read unresolved $stage files after command $outcome, all four cases)

before: details.resources = ["rea-artifact-decoder-<uuid>", "/…/owned-XXXX"]
after:  details.resources = ["rea-artifact-decoder-<uuid>", "/…/owned-XXXX", "pid:<n>", "process-group:<n>"]

Validation

  • tests/process-global/pwntoolsStageRetirement.test.ts: the four unresolved-cleanup cases now assert pid: and process-group: resources. They fail on main and pass with this change; all 8 tests in the file pass. The tests simulate the Linux x64 decoder gate and use real owned processes on this macOS host.
  • npm run lint passes.
  • npm test: 9566 passed, 15 failed in 8 files:
    • 7 are the environmental files that fail on clean origin/main on this host: Hopper not installed, Command Line Tools only (ibtool), hdiutil, and inspector target-location cases.
    • The 8th, tests/boundary/process/processSettlementDeadline.test.ts > still reports observed liveness as alive_at_deadline (added today in fix(process): report single empty settlement observation as unverifiable #2232), also fails when run alone on clean origin/main here. It is unrelated to this change: it spawns /bin/sleep and waits to observe the run token in that process's environment, which this macOS host does not expose for a platform binary.

Not addressed here: Codex's other post-merge note on #1708 (PwntoolsDecoder.ts:477, refresh captured diagnostics after a successful cleanup retry). It depends on output arriving between the first incomplete stop and the retry, which I could not reproduce deterministically.

🤖 Generated with Claude Code

…urces

When a pwntools or pwndbg stage cannot confirm that its owned process
group stopped, the cleanup_incomplete result listed only the run ID and
runtime directory, although a descendant can still be live. Add the
retained supervisor's pid and process-group coordinates, as
OwnedCommand reports for a non-transferred cleanup failure.

Fixes #2274

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: On Linux with the real pwntools 4.15.0, this change works. If a stage cannot confirm its group retired, the error now adds the leader pid and the group id from the retained launch. A launch with no ownership record still gets no made-up ids.

Thanks, kaoru0822-kitauji, for the issue and the fix. Two other PRs also target #2274: #2282 and #2284. I ran all three the same way.

Results

Head 8d1a4be, base ec2d251 (#2212). Every pass below exited 0.

Check Node 22 Node 24 Node 26
This PR's retirement test, 8 tests pass pass pass
Same test on base not run 4 fail, 4 pass not run
Pwntools tests and ownedCommand, 32 tests not run pass not run

This PR's test checks the form of the two labels, not their numbers. The real run below checks the numbers.

Real run. With the real pwntools 4.15.0 and a real core file, rea inspect-recorded-crash ends in cleanup_incomplete. The setup is in the fold below.

base:    [run id, runtime dir]
this PR: [run id, runtime dir, "pid:1870926", "process-group:1870926"]

ps listed only the surviving child, pid 1870927, in group 1870926. That matches the group id in the error. The leader had exited by then, so only the group id points at a live process.

No ownership. In a test file of mine, not part of the PR, I removed the ownership record from the launch. The list stayed ["owned-decoder", <runtime dir>], the same as on base.

Limit. On Linux the group id equals the leader pid, so both labels show one number. No test can catch a swap of the two labels.

Not run

  • macOS and Windows.
  • The debugger stage with real GDB and pwndbg. The real run used the decoder stage. The debugger stage ran only in the PR's test, with a stand-in process.
  • The newest main, 1c37914. It has not changed the two files this PR touches since the base, but I did not build it.
  • npm run lint and the full suite. The PR body reports a macOS run of both.
Real run setup

I wrote a small wrapper for REA_PWNTOOLS_PYTHON. It leaves one child in the same process group, with no run token (the marker REA gives each process it owns). Then it starts the real pwntools. REA cannot prove the child is its own, so it keeps the group. I made the core file with gdb from a small crashing C program.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • 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 8d1a4be on base ec2d251 (fix(adb): count UTF-8 bytes in logcat total_bytes #2212)
  • pwntools 4.15.0: mostly MIT, some GPL and BSD
  • pyelftools 0.33 is in the public domain
  • Unicorn 2.1.2: BSD
  • These are REA's pins. The licenses are the fields in each package's metadata.
  • Other: The head's parent is 2e45b4d, which differs from the base only in src/adb. Other agents may have shared the box.
Commands
npm ci && npm run build && npm run test:prepare
npm run test:focused -- tests/process-global/pwntoolsStageRetirement.test.ts
npm run test:focused -- tests/process-global/pwntoolsStageRetirement.test.ts tests/process-global/pwntoolsCleanup.test.ts tests/process-global/pwntoolsCliFinalization.test.ts tests/boundary/binaryDiagnostics/pwntoolsDecoderOwnership.test.ts tests/boundary/process/ownedCommand.test.ts
REA_PWNTOOLS_PYTHON=./pwpython.sh rea inspect-recorded-crash ./crash.core --json

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

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 4303dcd into main Oct 13, 2026
30 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/issue-2274 branch October 13, 2026 04:11
@morluto morluto mentioned this pull request Oct 13, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the provider: pwntools Analysis provider / engine: pwntools label Nov 23, 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: pwntools Analysis provider / engine: pwntools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] pwntools cleanup_incomplete omits the retained process group from its resources

3 participants