Repository navigation
fix(processes): bound descendant traversal on cyclic snapshots - #22411
Conversation
Based on the report and proposal by @brynnclaw. Co-authored-by: brynnclaw <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
|
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 configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughcollectDescendantsFromIndex 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 No actionable merge-blocking issue remains; merge after normal CI checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Bounded descendant traversal —
collectDescendantsFromIndexnow seeds a per-walkvisitedset withrootPidand 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.tspins exact traversal order, depth, duplicate retention, root exclusion, disconnected cycles, 10k-deep/broad valid trees, and synthetic POSIX/Windows rows. TheboundedWalkhelper spies onchildrenByPpid.getwith arows.length + 1budget, 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.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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.
ORCA_BACKGROUND_LAUNCH=1AI 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
Notes
No full application build, full lint, or full suite is claimed; CI covers broader validation.
Checklist