Skip to content

fix(pty): preserve child-process inspection uncertainty - #20756

Merged
AmethystLiang merged 6 commits into
mainfrom
err-probe-pty-children
Sep 15, 2026
Merged

AmethystLiang merged 6 commits into
mainfrom
err-probe-pty-children

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​82 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​76
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35

When a local PTY closes while its process descriptor is being read, the inspection can be temporarily unreadable. Treating that read as “no children” can incorrectly classify a live or closing pane as idle and trigger premature cleanup.

This PR:

  • preserves an explicit unverifiable child-process verdict for local PTYs
  • samples child-process evidence synchronously with foreground inspection
  • keeps the legacy boolean provider API compatible
  • adds regression coverage for descriptor failures, idle panes, busy panes, and cadence behavior

Validation:

  • pnpm test src/main/providers/local-pty-child-process-verdict.test.ts src/renderer/src/components/terminal-pane/agent-completion-coordinator-process-cadence.test.ts
  • pnpm tc
  • pnpm run check:code-quality:changed

Separate foreground and child-process sampling. Sample child processes
synchronously after confirming foreground availability, returning
unverifiable verdicts when pty reads fail. Handle both transport loss
and local read failures uniformly in the completion coordinator.
@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ae3a0d42-8da2-4aea-899c-05a4cf7a3e13

📥 Commits

Reviewing files that changed from the base of the PR and between 30eb2a9 and 0a378a4.

📒 Files selected for processing (1)
  • src/main/providers/local-pty-child-process-verdict.test.ts

📝 Walkthrough

Walkthrough

The change adds isRetiredPtyMaster to identify retired node-pty descriptors. Child-process inspection now returns 'unverifiable' before reading retired master data. LocalPtyProvider.inspectProcess verifies that the PTY instance remains unchanged across asynchronous inspection. Tests cover unreadable descriptors, retired masters, boolean conversion, replacement PTYs, and readable foreground data with unverifiable child evidence.

Merge Risk: 🔵 Low · up to 30eb2

The boolean compatibility test can pass even if it stops performing the descriptor inspection it is intended to protect. This is a bounded regression-coverage gap and is mergeable with follow-up awareness.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, the main changes, and validation commands, but it omits most required template sections, including Linked Issue, Visual Proof or an explicit N/A, Review, Agent sk… Update the description to include all required template sections. Add the linked issue, state N/A with a reason for Visual Proof if there is no UI change, complete the testing checkboxes and platform coverage, address AI Disclosure as appli…
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 6 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 identifies the main change: preserving uncertainty during PTY child-process inspection.
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, the main changes, and validation commands, but it omits most required template sections, including Linked Issue, Visual Proof or an explicit N/A, Review, Agent skill upstream boundary, Notes, and the Checklist.

Resolution

Update the description to include all required template sections. Add the linked issue, state N/A with a reason for Visual Proof if there is no UI change, complete the testing checkboxes and platform coverage, address AI Disclosure as applicable, complete Review, confirm the Agent skill upstream boundary, add Notes, and complete the Checklist.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 97323877-25ea-4744-9996-e3f9e93eafb0

📥 Commits

Reviewing files that changed from the base of the PR and between b61a234 and a3f8b1c.

📒 Files selected for processing (5)
  • src/main/providers/local-pty-child-process-verdict.test.ts
  • src/main/providers/local-pty-foreground-inspection.ts
  • src/main/providers/local-pty-provider.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator-process-cadence.test.ts
  • src/renderer/src/components/terminal-pane/agent-completion-inspection-result.ts

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

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

Important

The new unverifiable verdict is only produced when proc.process throws, and with the shipped node-pty it does not. That would make the fix inert for the failure it targets — see the inline comment for the evidence and what to confirm.

Reviewed changes

  • Local child-process verdict — inspectLocalPtyChildProcesses returns 'children' | 'no-children' | 'unverifiable'; hasLocalPtyChildProcesses becomes a boolean adapter (=== 'children') so IPtyProvider.hasChildProcesses stays compatible.
  • Local inspectProcess — LocalPtyProvider now implements the optional inspectProcess, reading foreground then child evidence in one call, so inspectPtyProviderProcess stops using its getForegroundProcess + hasChildProcesses fallback.
  • Renderer gating — local (!remote) results with childProcessEvidence === 'unverifiable' now reset pending exit confirmation and retry instead of confirming a process exit.
  • Tests — new local-pty-child-process-verdict.test.ts and a parameterized cadence case for 'host child-process uncertainty'.

ℹ️ probeTerminalLiveness never sees the new verdict

The workspace-cleanup liveness probe still reads the collapsed boolean (window.api.pty.hasChildProcesses), so it cannot distinguish "read it, found nothing" from "could not read it" — the same collapse the PR describes. If the symptom being fixed is premature cleanup, this guard is the other consumer worth migrating.

Technical details
# Workspace cleanup still collapses the child read

## Affected sites
- `src/renderer/src/store/slices/workspace-cleanup-local-evidence.ts:170-190` — `!hasChildProcesses && (shell || null)` → `continue` → `'idle'`; any rejection → `'unknown'`.
- `src/main/providers/local-pty-foreground-inspection.ts:43-45` — the boolean adapter discards `'unverifiable'`.

## Required outcome
- Decide whether this guard should read `inspectProcess` (which now carries `childProcessEvidence`) or stay boolean-only; document the intent either way.

## Open questions for the human
- Is workspace cleanup in scope for this PR's "premature cleanup" motivation, or is the close guard the only target?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Detect when node-pty retires the master fd (fd == -1) and return
unverifiable instead of misreading the spawn file as an idle shell.
Guard inspectProcess against PTY replacement mid-read to avoid pairing
old foreground with replacement's children.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: af586e5f-54ad-42c3-8609-d29c83674944

📥 Commits

Reviewing files that changed from the base of the PR and between a3f8b1c and 464328e.

📒 Files selected for processing (4)
  • src/main/providers/local-pty-child-process-verdict.test.ts
  • src/main/providers/local-pty-foreground-inspection.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/pty/node-pty-master-fd-retirement.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/providers/local-pty-foreground-inspection.ts
  • src/main/providers/local-pty-provider.ts

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

@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

Reviewed the delta since the prior pullfrog review (a3f8b1c → 464328e): the fix now detects a retired node-pty master directly instead of waiting for proc.process to throw, and the local inspectProcess guards against a pane swap across its await.

  • Retired-master detection — new isRetiredPtyMaster reads node-pty's public fd accessor, and inspectLocalPtyChildProcesses returns 'unverifiable' when it is negative, making the previously unreachable verdict reachable for the state Orca's node-pty patch actually produces.
  • Pane-swap guard in inspectProcess — captures the IPty before the foreground await and returns 'unverifiable' when the map now holds a different instance, so one pane's foreground is never paired with its replacement's children.
  • Tests — the new registerRetiredPane helper spawns a real node-pty and asserts its silent spawn-file answer, so the 'unverifiable' path is exercised against the shipped runtime rather than a throwing mock; a pty-swapped case covers the identity guard.

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: de43750a-abd9-4f9c-88c0-540e83ac4a86

📥 Commits

Reviewing files that changed from the base of the PR and between 464328e and 18a235c.

📒 Files selected for processing (2)
  • src/main/providers/local-pty-child-process-verdict.test.ts
  • src/main/providers/local-pty-foreground-inspection.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/providers/local-pty-foreground-inspection.ts

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

@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

Reviewed the delta since the prior pullfrog review (464328e → 30eb2a9): a single test-only hardening, no production-code change.

  • Deterministic retirement wait — registerRetiredPane in local-pty-child-process-verdict.test.ts replaces the fixed 400 ms setTimeout with vi.waitFor(() => isRetiredPtyMaster(term)), so the fixture waits for the actual fd retirement rather than racing a wall-clock delay.

Verified locally: pnpm test src/main/providers/local-pty-child-process-verdict.test.ts → 13 passed (retired-master cases now resolve in milliseconds instead of a flat ~405 ms). No specialists dispatched — the delta has no behavioral surface beyond the fixture.

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

@AmethystLiang
AmethystLiang merged commit 3ec6193 into main Sep 15, 2026
6 of 9 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
* fix(pty): preserve unverifiable local child reads

* fix(pty): make child-process inspection synchronous

Separate foreground and child-process sampling. Sample child processes
synchronously after confirming foreground availability, returning
unverifiable verdicts when pty reads fail. Handle both transport loss
and local read failures uniformly in the completion coordinator.

* fix(pty): handle retired masters and pane instance swaps

Detect when node-pty retires the master fd (fd == -1) and return
unverifiable instead of misreading the spawn file as an idle shell.
Guard inspectProcess against PTY replacement mid-read to avoid pairing
old foreground with replacement's children.

* fix test

* fix tests
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