Skip to content

fix: preserve process identities in pwntools cleanup errors - #2284

Merged
morluto merged 2 commits into
morluto:mainfrom
jeonjw85:fix/pwntools-cleanup-resources
Oct 13, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
jeonjw85:fix/pwntools-cleanup-resources

Conversation

@jeonjw85

Copy link
Copy Markdown
Contributor

Summary

Fixes #2274.

Include the recorded leader PID and process-group ID when a pwntools decoder or debugger retains a process after incomplete cleanup.

Problem and expected behavior

The provider retained the supervisor but reported only its run ID and runtime directory. A caller inspecting cleanup_incomplete could not identify the retained process group. The direct OwnedCommand failure path already reported those identifiers.

Change and scope

Both paths now use ownedCommandResources to format the recorded launch ownership. The decoder continues to retain its supervisor and runtime until cleanup succeeds.

This is a diagnostic fix within the existing provider boundary; no new capability or maintainer scope decision is needed.

Contract and boundary impact

  • Owner and stage: owned-command resource reporting during failed cleanup.
  • CLI/MCP: details.resources gains pid:<leaderPid> and process-group:<processGroupId> entries. No schema or catalog change.
  • Evidence: original errors, captured output, partial observations, run ID, and runtime path remain available.
  • Authority: identifiers describe the recorded launch. They do not establish current liveness or grant permission to signal a process.
  • Provider/platform and packaging: no admission, launcher, dependency, installation, or generated-metadata changes.

Evidence and regression coverage

The existing stage-retirement tests now assert the exact projected resources for decoder and debugger stages, after both successful and failed commands. Those four cases failed on the base revision because the PID/group entries were missing. The direct owned-command tests also check both identifiers.

Representative resource list:

["rea-artifact-decoder-<run-id>", "/path/to/owned-runtime", "pid:1234", "process-group:1234"]

Validation performed

Using Node 24.18.0 and npm 11.16.0 on macOS:

  • npm run test:focused -- tests/process-global/pwntoolsStageRetirement.test.ts tests/boundary/process/ownedCommand.test.ts — 20 passed.
  • npm run check — passed, with no lint errors.
  • git diff --check — passed.

The process tests use real macOS child processes with injected decoder launchers. I did not run the real Linux pwntools/pwndbg lane or native Windows verification.

Compatibility and release

Additive error diagnostics; no migration or release metadata changes.

Before merge

  • One focused fix, linked to the issue.
  • Existing scope and cleanup authority preserved.
  • Regression tests cover the changed observable output.
  • Final diff checked for unrelated changes and credentials.

@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, jeonjw85, for the fix and for sharing one helper between both error paths. Two other PRs also target #2274: #2281 and #2282. I ran all three the same way.

Results

Head 818c72c, base ec2d251 (#2212). Every pass below exited 0.

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

The 4 failures on base are the retirement cases. The 12 ownedCommand tests also pass on base, because OwnedCommand already listed those ids. I read ProviderProcess.ts: both launchers there set the ownership run id from the spawn's run id, so the list stays the same.

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:1871040", "process-group:1871040"]

ps listed only the surviving child, pid 1871041, in group 1871040. 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.
  • Other callers of runOwnedCommand, which now share the helper. They are Wabt, EVM, Apktool, the history decoder and the command runner.
  • Test-only launchers. I read only the two real launchers in ProviderProcess.ts.
  • The newest main, 1c37914. It has not changed the four files this PR touches since the base, but I did not build it.
  • npm run check, lint and the full suite.
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 818c72c 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 the base itself. 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 tests/boundary/process/ownedCommand.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) 🦊

@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

This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge.

Summary

Shares cleanup resource formatting through ownedCommandResources and strengthens tests to check exact recorded process identities.

  • Pwntools cleanup errors name the recorded process and group.

Reviews (2) · Last reviewed commit: "fix(pwntools): integrate current cleanup..." · Reviewed by Greptile

@morluto
morluto merged commit d853744 into morluto:main Oct 13, 2026
5 checks passed
@morluto morluto added bug Something isn't working area: runtime Process capture and runtime observation labels Oct 14, 2026
@morluto morluto added area: domain Domain logic, errors, and pure functions provider: pwntools Analysis provider / engine: pwntools labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions area: runtime Process capture and runtime observation 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