Skip to content

fix(processes): bound descendant traversal on cyclic snapshots - #22411

Merged
nwparker merged 2 commits into
mainfrom
nwparker/external-20715-process-cycle
Sep 26, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/external-20715-process-cycle

Conversation

@nwparker

@nwparker nwparker commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A malformed process snapshot no longer makes Orca loop forever while collecting child processes.

What Changed

The existing traversal records each PID when it is queued, with the root already recorded. Valid-tree order and depth remain unchanged; repeated PIDs and root cycles are excluded.

Why

A per-walk set bounds both queued work and output without adding a second process traversal or changing host process enumeration.

Linked Issue

Related to #20715 and #16797. Adapted from @brynnclaw (Brynn Bendixen), retaining the original Claude Fable co-author credit. Actual OS PID-reuse causality and the broader Windows exits are not established.

Visual Proof

N/A — shared process-table traversal has no visual interface. A bounded regression fixture fails before exhausting memory and verifies exact descendants.

Testing

51 focused traversal/parser tests pass. Node typecheck and changed-code quality pass. Tests execute on macOS with synthetic POSIX and Windows rows; no native Windows/Linux/WSL/SSH incident reproduction.

  • Native end-to-end flow manually tested
  • Focused automated regression tests added and run with ORCA_BACKGROUND_LAUNCH=1

AI Disclosure

Review

Reviewed termination, root exclusion, duplicate rows, traversal order, depth and input ownership. The original bot request to assert exact root exclusion is covered.

Agent skill upstream boundary

  • Not applicable; no upstream skill source is copied.

Notes

No full application build, full lint, or full suite is claimed; CI covers broader validation.

Checklist

  • Small and focused
  • Before/after, mechanism and rationale explained
  • Visual proof attached or N/A explained
  • Reviewed for correctness, security and performance
  • Cross-platform, SSH/remote and compatibility impact considered
  • Required CI checks pass, including the verify aggregate, types, static analysis, packages and tests

nwparker and others added 2 commits September 22, 2026 22:39
Based on the report and proposal by @brynnclaw.

Co-authored-by: brynnclaw <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 07955246-4bcc-40c3-b67f-0114660da30f

📥 Commits

Reviewing files that changed from the base of the PR and between 9fef7a0 and 57ec88b.

📒 Files selected for processing (2)
  • src/shared/process-table-index.test.ts
  • src/shared/process-table-index.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

collectDescendantsFromIndex now tracks visited PIDs, including the root, and queues each PID at most once. The added Vitest suite covers cycles, duplicate PIDs, traversal order and depth, large trees, cloned rows, and retention of row fields.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 57ec8

No actionable merge-blocking issue remains; merge after normal CI checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: bounding descendant traversal for cyclic process snapshots.
Description check ✅ Passed The description covers the change, reason, testing, visual proof, review notes, scope, and checklist. It provides linked issue references, although it does not use the template's exact "Fixes #" forma…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

✅ No new issues found.

Reviewed changes

  • Bounded descendant traversal — collectDescendantsFromIndex now seeds a per-walk visited set with rootPid and queues each PID at most once (pushUnvisited), so a cyclic or duplicate-row snapshot terminates. Valid-tree ordering and depth are unchanged, and the root is excluded even when reachable through a cycle.
  • Regression coverage — src/shared/process-table-index.test.ts pins exact traversal order, depth, duplicate retention, root exclusion, disconnected cycles, 10k-deep/broad valid trees, and synthetic POSIX/Windows rows. The boundedWalk helper spies on childrenByPpid.get with a rows.length + 1 budget, so removing the guard fails the test instead of OOMing the worker. I confirmed locally that 8 of the 12 cases fail with the guard reverted, so this is real coverage, not theatre.

ℹ️ Same unbounded pattern remains in the shutdown validation script

Not in scope for this PR and not blocking — but the identical unbounded walk exists at config/scripts/codex-validation-process-shutdown.mjs:77 (readPosixDescendantPids), which has no seen/visited set. Every other sibling traversal over the shared index (relay/pty-shell-utils.ts, main/pty-descendant-termination.ts, the two batch/remote-evidence providers, config/scripts/idle-cpu-process-sampling.mjs) is already guarded, so this script is the last one that would still hang on a cyclic snapshot. Worth folding into a follow-up if you want the pattern fully closed, but it is CI tooling rather than app runtime and does not block this change.

Technical details
# Unguarded sibling traversal

## Affected sites
- `config/scripts/codex-validation-process-shutdown.mjs:77` — `readPosixDescendantPids` pushes `childrenByParent.get(pid)` unconditionally with no visited set; a self-parented root or PID-reuse cycle loops until the process is killed.

## Required outcome
- Optional follow-up only: bound the walk the same way (per-walk visited set, root included) so it cannot hang a validation run.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant