Skip to content

fix(relay): bound cyclic process-table traversal - #20946

Merged
OrcaWin merged 1 commit into
mainfrom
np-oom-scan-relay-process-cycles
Sep 18, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
np-oom-scan-relay-process-cycles

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​55 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​55
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6

A process-table snapshot with repeated or cyclic parent links makes SSH relay foreground inspection revisit descendants indefinitely, growing its array until the relay runs out of memory.

Visit each PID once and exclude the root from its own descendants. Ordinary process trees keep the same foreground resolution. This fixes the relay's separate walker; #20715 guards the shared local/daemon walker.

Validation: 42 relay foreground tests passed, including self-cycles, two-process cycles, duplicate rows, and ordinary trees. The regression bounds traversal reads so removing the guard fails without hanging or exhausting the test worker. Targeted oxlint and oxfmt passed.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

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: 166e9d83-0d20-46e5-b757-61c7c1d19be6

📥 Commits

Reviewing files that changed from the base of the PR and between 07c7606 and 47a50b6.

📒 Files selected for processing (2)
  • src/relay/pty-shell-utils-process-cycles.test.ts
  • src/relay/pty-shell-utils.ts

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


📝 Walkthrough

Walkthrough

The change makes collectDescendants track visited PIDs and skip repeated rows. New tests cover self-parented roots, two-process cycles, duplicate rows, and ordinary trees. The tests also limit child-map reads to detect non-terminating traversal and verify that getForegroundProcessName resolves to codex.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 47a50

The process traversal remains correct for ordinary trees and now safely terminates for cyclic or duplicate process snapshots.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, solution, scope, and validation, but it does not follow the required template. It omits the required Linked Issue entry, Visual Proof or an N/A explanation, AI Di… Rewrite the description using the repository template. Add a Linked Issue entry with the required issue reference, state N/A with a reason for Visual Proof, complete the Testing and checklist sections, and address AI Disclosure, Review, Age…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing cyclic process-table traversal in the relay.
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.
Full details: Description check

Explanation

The description explains the problem, solution, scope, and validation, but it does not follow the required template. It omits the required Linked Issue entry, Visual Proof or an N/A explanation, AI Disclosure, Review, Agent skill upstream boundary, Notes, and checklist details.

Resolution

Rewrite the description using the repository template. Add a Linked Issue entry with the required issue reference, state N/A with a reason for Visual Proof, complete the Testing and checklist sections, and address AI Disclosure, Review, Agent skill upstream boundary, and Notes.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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

  • Relay descendant walk bounded — collectDescendants in src/relay/pty-shell-utils.ts:182 now seeds a seen set with the root pid and skips any pid already visited, so duplicate rows and parent/child cycles terminate instead of growing descendants without bound. Ordinary acyclic tables are unaffected.
  • Regression coverage — pty-shell-utils-process-cycles.test.ts covers a self-parented root, a two-process cycle, duplicate rows, and an ordinary tree, with a childrenByPpid.get spy that caps reads so an unguarded traversal fails rather than OOMs the worker.

I verified locally: pnpm tc:node passes; the new file plus pty-shell-utils.test.ts pass (42 tests); oxlint and check:code-quality:changed are clean. Removing the guard makes 3 of the 4 new cases fail ('node' instead of 'codex') without hanging, so the test is a real regression pin rather than theatre.

ℹ️ Nitpicks

  • collectDescendants here is collectDescendantsFromIndex from src/shared/process-table-index.ts:68 plus this guard, and the relay already imports from that module. #20715 is adding the same guard to the shared walker, so once it lands the relay can drop this private copy and call the shared function. Not a blocker for this fix — deleting the duplicate before #20715 merges would reopen the relay OOM — just flagging it so the two-copies state does not become permanent.

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

@OrcaWin
OrcaWin merged commit df88f83 into main Sep 18, 2026
35 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
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