Skip to content

fix(pwntools): report retained process cleanup identities - #2282

Closed
1052326311 wants to merge 3 commits into
morluto:mainfrom
1052326311:fix/pwntools-cleanup-identities
Closed

1052326311 wants to merge 3 commits into
morluto:mainfrom
1052326311:fix/pwntools-cleanup-identities

Conversation

@1052326311

@1052326311 1052326311 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2274. Retained pwntools/pwndbg cleanup failures now identify the owned process leader and process group, alongside the run ID and runtime directory.

Problem and expected behavior

When a stage cannot confirm process-group retirement, cleanup_incomplete.details.resources previously omitted the process identity even while descendants were still alive. Callers should receive pid:<leaderPid> and process-group:<processGroupId> from retained launch ownership, matching the existing non-transferred OwnedCommand error.

Change and scope

Extend PwntoolsDecoder.#retireProcess resource projection using the retained supervisor's ownership. Do not infer ownership from a raw PID, and do not invent IDs for launches without ownership. Cleanup execution, retained supervisors, retry behavior and source-read guards are unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: pwntools stage retirement error construction.
  • Contribution scope fit and linked maintainer decision: ordinary error-evidence fix within existing provider; no new-capability scope decision applicable.
  • CLI and MCP/tool-catalog contract: unchanged schemas; more complete existing resource list.
  • Provider, bridge, target-format, or platform compatibility: shared decoder/debugger retirement path; no changes to supported hosts or tools.
  • Evidence, artifact, provenance, or reconstruction contract: preserve retained process identity and existing partial observations/primary failures.
  • Target selection, authority, upstream behavior, and cleanup details: no new authority or cleanup actions; process-group IDs are diagnostic ownership evidence, not authorization to kill an arbitrary PID.
  • Generated metadata, package, or installation impact: none.

Expected effects of the exercised existing workflow:

  • Read existing files or captured data.
  • Launch or attach to a process.

Evidence and regression coverage

Extended the existing real owned-process regression for decoder/debugger × command success/failure. Assertions compare projected resource IDs to the actual launch ownership while the existing test confirms the descendant remains alive, producer files are not consumed, and cleanup retries run during teardown.

  • Base 2e45b4d7: four new assertions fail, four existing cases pass.

  • Candidate: 17 tests passed across retirement, cleanup and CLI finalization; three Linux-only decoder integration tests skipped on macOS.

  • Representative resources retain run ID/directory and additionally include pid:123 and process-group:123 with actual launched values.

  • Remaining proof gaps: real macOS process ownership exercised while the existing fixture simulates the Linux x64 provider admission gate and producer output. This is not a real pwntools/pwndbg installation run or Windows proof.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • 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 — 17 passed, 3 platform-skipped.
  • npm run check — six tasks and architecture guards passed.
  • git diff --check — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; additive diagnostics.
  • Real Hopper/Ghidra, browser, or OS coverage: real macOS owned processes; no real debugger engine claimed.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: report only retained launch ownership; no additional process actions or ambient-data capture.

Review checklist

  • Concrete issue, focused conventional title and existing-boundary scope.
  • Regression covers actual owner and shared error projection.
  • Existing cleanup/source-read protections retained.
  • No schema or generated metadata changes needed.
  • Proof limitations and representative output stated.
  • Final diff checked for secrets, generated output and unrelated edits.

Independent validation — 2026-10-13

CassieFox23 reported Linux validation of head 8eb6a8b7a: all 8 retirement tests passed on Node 22/24/26; the focused pwntools/ownership set passed 32 tests on Node 24, including the three cases skipped in our macOS run. A real pwntools 4.15.0 decoder/core-file run retained the expected leader PID and process-group identity; a separate no-ownership case added no invented IDs. These are third-party reported results, not author-run tests or maintainer approval. Real GDB/pwndbg, Windows, and newest-main execution were not covered by that report.

@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, 1052326311, for the fix and for a test that checks the real numbers. Two other PRs also target #2274: #2281 and #2284. I ran all three the same way.

Results

Head 8eb6a8b, 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

The 3 tests your macOS run skipped also ran.

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

ps listed only the surviving child, pid 1870824, in group 1870823. 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 your 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 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 8eb6a8b 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) 🦊

@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

[Low impact] The test-only change appears safe to merge.

Summary

Strengthens the existing cleanup regression to compare reported process IDs with the actual retained launch.

  • The retirement test checks cleanup IDs against the retained launch.

Reviews (2) · Last reviewed commit: "fix(pwntools): reconcile retained cleanu..." · Reviewed by Greptile

@cursor

cursor Bot commented Oct 13, 2026

Copy link
Copy Markdown

Closing this. The branch has commits, but the diff against main is empty. The retained pwntools cleanup identities are already on main.

@morluto morluto closed this Oct 13, 2026
@morluto morluto added bug Something isn't working area: runtime Process capture and runtime observation 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: 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