Skip to content

fix(windows): detect agents in panes whose ConPTY root process has exited - #45592

Merged
nwparker merged 1 commit into
stablyai:mainfrom
lbvargas99:fix/windows-agent-exited-pane-root
Nov 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
lbvargas99:fix/windows-agent-exited-pane-root

Conversation

@lbvargas99

@lbvargas99 lbvargas99 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Before Orca sends text to an agent on Windows, it checks that an agent is really running in that terminal. It used to look only under the terminal's first process. Sometimes that first process exits after it starts the agent, and the agent keeps running. Orca then found nothing, treated the terminal as a plain shell, and refused the send with a "no agent" message. Now, when the first process is gone, Orca also checks the processes it left running in the same terminal.

What Changed

Before: if the pane's ConPTY root process had exited (for example cmd.exe → sh.exe npm shim → claude.exe, then the root exits), queryWindowsPaneProcessInventory returned null. The send guard (confirmFreshPtyForeground → terminalHasShellForegroundProcess) read that as a shell in the foreground, so terminal.agentStatus reported isRunningAgent: false and sends failed with no-agent.

After: the running agent is recognized and the send goes through.

How it works:

  • process-rows.ts: on fresh scans that know the pane's spawn time, a missing root returns its orphans with rootExited: true instead of null. Windows keeps the dead parent's PID on orphans, so the existing descendant walk finds them. Direct orphans created before the pane's spawn are pruned in that walk, so a recycled root PID can't lend an older process tree to the pane. Cached scans and roots with no orphans still return null, as before.
  • bundled-conpty-fallback.ts / conpty-spawn-time.ts: spawnWithSystemConptyFallback, which every daemon, local and preflight ConPTY spawn goes through, records the time just before the spawn in a WeakMap keyed by the IPty object. pty-confirmation.ts passes it as paneSpawnedAtMs.
  • console-attached-processes.ts: once the root is gone, console membership is read through a direct orphan (readPaneConsoleProcessIds), and every direct orphan must be on that console. If one isn't, it opened its own console, so the read isn't proven to be the pane's and the result stays unavailable.
  • agent-process.ts: orphans can prove an agent, never a shell. If no agent is recognized, the result stays unavailable. If a cached agent has left the exited root's console, it is retired (anchorPidForeign).
  • The context-path helpers moved unchanged to context-path-match.ts so agent-process.ts stays under the max-lines limit.

Why

The null for a missing root was meant to guard against stale or filtered snapshots. On a fresh table it is wrong for exactly this case. Alternatives considered:

  • Treat "unavailable" as "not a shell" in the guard. Smaller, but it weakens the guard for every scan failure, including the case where an agent just exited back to a real shell. This change only adds positive evidence for one case.
  • Use PTY job membership. The native job closes when the root exits, so it has nothing to report here.
  • Trust the orphans' parent PID alone. PIDs get reused. Checking the spawn time plus console membership ties the orphans to this pane.
  • Record the spawn time at each call site. Recording it in the one shared spawn helper covers daemon, local and preflight spawns at once.

Linked Issue

Fixes #45590

Original fix by @lbvargas99 in #45592; final version reworked during the bug bash.

Reported by @lbvargas99

Visual Proof

N/A. This is a Windows-only change to process detection. The only visible difference is that the send succeeds instead of showing the no-agent toast, and the bug can't be reproduced on macOS or Linux. The reporter measured it on Windows 11 against the live process table of an affected terminal (dead root 5368, orphans sh.exe 5656 → claude.exe 15864): before { available: false }, after { available: true, processName: "claude", processId: 15864 }.

Testing

  • I manually tested these changes locally: the reporter ran the resolver on Windows 11 against an affected terminal's live process table (see Visual Proof). macOS: targeted unit tests only. These code paths run only on Windows.
  • Automated tests added/updated: agent-process-exited-root.test.ts covers four cases:
    • an agent kept on the pane console by the orphans is named;
    • orphans of an older process that held the reused root PID are never credited;
    • a direct orphan that left the console keeps the result unavailable;
    • a cached agent that exits while another orphan keeps the console is retired.
      bundled-conpty-fallback.test.ts checks that the spawn time is recorded on the fallback path.
  • Every added test fails without this change and avoids the test anti-patterns.

Run locally: vitest run --config config/vitest.config.ts src/main/providers/foreground src/main/windows src/main/daemon/pty-subprocess src/main/providers/local-pty passes (21 passed, 3 skipped as platform-gated). oxlint, oxfmt, the anti-slop and code-quality oxlint configs, ast-grep, and check-changed-code-quality report no findings on the touched files.

Performance

None on hot paths. Spawn adds one Date.now() and one WeakMap.set per ConPTY spawn. The live-root inventory path is unchanged: same index, same walk. The new orphan walk runs only on a fresh send-guard confirmation when the root is missing, and reuses the snapshot index that is already built.

Benchmarks (queryWindowsPaneProcessInventory, shared snapshot, median per call):

  • live root, 3k rows: main 0.5 µs, branch 0.5 µs.
  • dead root, 1 orphan: main 0.2 µs, branch 0.5 µs.
  • 200 orphans: branch ~50 µs.
  • 15k rows with 1000×5 orphans (adversarial): branch ~0.57 ms.

These are all far below a frame, on a path that runs only when the user sends. No new subprocesses, polling, or sync I/O. The console helper is still forked only when an agent candidate is recognized, as before.

Risk

The riskiest part is that the send guard gets more permissive: it now accepts an agent found among an exited root's orphans. The bounds:

  • fresh scans only;
  • only orphans created after the pane's spawn;
  • every direct orphan must be on the console that was read;
  • absence is never inferred.

If it went wrong, a send could reach a terminal whose agent had just exited. With the root gone, though, no shell is left on that console. Windows-only: POSIX, SSH and remote panes don't pass paneSpawnedAtMs, so they keep the old null behavior. Back out with a plain revert.

Level: Medium

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: only adds positive evidence under fresh-scan, spawn-time and console checks. Cross-platform: Windows-only path. Remote SSH and mobile: untouched. Backwards compatible: no persisted data or protocol changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

Fresh Windows process scans can now return descendants when the pane root has exited. The foreground resolver checks those candidates for a recognized agent and uses a depth-1 candidate PID for console membership checks. PTY spawn paths record process start times, which foreground confirmation passes to the scan. Tests cover exited-root candidates, console membership, unavailable results, and the live-root path.

Severity of issue fixed: Medium

Merge Risk: Moderate · up to 1d10b

This change lets the Windows send guard find an agent that keeps running after its pane's shell exits. One narrow case can still report an agent name after the cached process ID has been reused by another program. Two edge cases involving console binding remain open. Fix the dropped foreign-anchor flag before merging. The two console-binding limits can be accepted or tracked as follow-ups.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Issue #45590 requires that a running Claude Code agent is recognized on Windows after the pane root shell exits, so the send guard does not return no-agent. At head 1d10beb:
- process-rows.ts: queryWi…
Out of Scope Changes check Passed All inspected changes connect to the Windows exited-root case in #45590:
- process-rows.ts: opt-in exitedRootPaneSpawnedAtMs option, rootExited flag, and creationTimeMs projection. The exited-root pat…
Title check Passed The title names the main change: Windows agent detection in panes whose ConPTY root process has exited. It follows the conventional commit format and matches the changeset, which adds orphan-based age…
Description check Passed The description follows the repository template. It covers ELI5, What Changed, Why, Linked Issue (Fixes #45590), Visual Proof (N/A with reason), Testing, Performance, Risk (Level: Medium), AI Disclosu…
Full details: Linked Issues check

Explanation

Issue #45590 requires that a running Claude Code agent is recognized on Windows after the pane root shell exits, so the send guard does not return no-agent. At head 1d10beb:

  • process-rows.ts: queryWindowsPaneProcessInventory returns orphans only when fresh is true and exitedRootPaneSpawnedAtMs is set. It returns rootExited: true with the surviving orphans. Otherwise it returns null.
  • exited-root-orphans.ts: orphansBornAfterSpawn keeps a depth-1 orphan only when creationTimeMs is known and not earlier than the pane spawn time. Descendants of dropped orphans are dropped too. findOrphanOnInheritedConsole selects a depth-1 orphan with no conhost.exe or openconsole.exe child.
  • agent-process.ts: for rootExited, the resolver requires a recognized candidate, a memberPid, and a console reader. It then requires one resolved agent identity. Without these, it returns unavailable. The dead shell name is never used.
  • Spawn time is recorded before the PTY spawn (native-pty-spawn.ts, local-pty-runtime-spawn.ts, pty-spawn-time.ts) and supplied through pty-confirmation.ts.
    The reported case (orphan sh.exe 5656 keeps the pane console, claude.exe 15864 is the agent) is covered by this logic. Not verified: test-file contents and an end-to-end send through the toast.
    Note on description drift: the PR description still says a root seen alive is remembered by creation time and that a root never seen alive keeps all orphans. The head code instead gates on the pane spawn time, and drops orphans of unknown creation time. The objectives state this replacement. The description also mentions a pane-job membership check for the console member. That check does not appear in the head code of agent-process.ts or exited-root-orphans.ts. This is a description mismatch. It does not change whether the #45590 requirement is met.
Full details: Out of Scope Changes check

Explanation

All inspected changes connect to the Windows exited-root case in #45590:

  • process-rows.ts: opt-in exitedRootPaneSpawnedAtMs option, rootExited flag, and creationTimeMs projection. The exited-root path runs only on fresh scans.
  • exited-root-orphans.ts: orphan selection and spawn-time filtering. Used only on the exited-root path.
  • agent-process.ts: the exited-root branch is gated on rootExited. The live-root path is unchanged apart from the optional memberPid argument.
  • pty-confirmation.ts, native-pty-spawn.ts, local-pty-runtime-spawn.ts, pty-spawn-time.ts: record and pass the spawn time and the console member PID. These support the spawn-time filter.
  • Tests in agent-process-exited-root.test.ts cover the new behavior.
    POSIX, SSH, and remote paths do not pass the new option. No unrelated change was found.
Full details: Title check

Explanation

The title names the main change: Windows agent detection in panes whose ConPTY root process has exited. It follows the conventional commit format and matches the changeset, which adds orphan-based agent detection for exited roots and the spawn-time plumbing for it.

Full details: Description check

Explanation

The description follows the repository template. It covers ELI5, What Changed, Why, Linked Issue (Fixes #45590), Visual Proof (N/A with reason), Testing, Performance, Risk (Level: Medium), AI Disclosure, the upstream boundary checkbox, Notes and the Checklist. The Performance section gives measured numbers. The template's Review heading is left empty, and the AI Disclosure section is left as template text, which the template says to skip for team members. The final typecheck/test checkbox is unchecked and the description says CI will cover it. None of these gaps are critical.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@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: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 58359119-2105-43b2-9fd7-f4be7b0336f2
Commits

Reviewing files that changed from the base of the PR and between 22da81c and f630841.

Files selected for processing: 4

  • src/main/providers/foreground/pty-confirmation.ts
  • src/main/providers/foreground/windows/agent-process-exited-root.test.ts
  • src/main/providers/foreground/windows/agent-process.ts
  • src/main/providers/foreground/windows/process-rows.ts

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

const consoleProcessIds = await options.readWindowsConsoleAttachedProcessIds()
// With the root gone, attach through a direct orphan: it is still a member of this console.
const consoleProcessIds = await options.readWindowsConsoleAttachedProcessIds(
inventory.rootExited ? candidates.find((candidate) => candidate.depth === 1)?.pid : undefined

@coderabbitai coderabbitai Bot Nov 20, 2026 •

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.

Major · Functional Correctness · Heavy lift

Bind the root-exit console read to the pane's original console.

When the root has exited, the resolver reads console membership through the first depth-1 orphan. That orphan can be a direct child that detached into a different console, such as a child started with its own console. The helper reads that other console's member set. A recognized agent in that set can then be credited as the pane's foreground agent, even though it does not share the pane's input console.

The resolver must read membership only from the pane's original console. The fix must identify a process that is attached to that console, or it must establish that the selected orphan shares it. The inspected code provides neither check. Choose the mechanism that fits the pane lifecycle.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in 1d04599: the console read now goes through a direct orphan that kept its inherited console. A process that opened its own console owns a conhost.exe/OpenConsole.exe child, so such orphans are skipped (exited-root-orphans.ts); with no eligible orphan the result is unavailable. Covered by never reads membership through an orphan that opened its own console and reads membership through the orphan that kept the pane console. Re-checked on the original machine: still resolves claude (15864), reading the console through sh.exe (5656).

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.

Analysis chain

Script executed:

#!/bin/bash
set -u
for f in src/main/providers/foreground/windows/exited-root-orphans.ts src/main/providers/foreground/windows/agent-process-exited-root.test.ts src/main/providers/foreground/windows/process-rows.ts src/main/providers/foreground/windows/agent-process.ts src/main/providers/foreground/pty-confirmation.ts; do
  echo "===== $f outline ====="
  ast-grep outline "$f" --items all
done
echo '===== Helper ====='
cat -n src/main/providers/foreground/windows/exited-root-orphans.ts
echo '===== Tests ====='
cat -n src/main/providers/foreground/windows/agent-process-exited-root.test.ts | sed -n '1,260p'
echo '===== Relevant process inventory ====='
rg -n -C5 'queryWindowsPaneProcessInventory|rootExited|collectWindowsProcess|depth|ppid' src/main/providers/foreground/windows/process-rows.ts
echo '===== Resolver calls and console reader ====='
rg -n -C4 'resolveWindowsAgentForegroundProcessWithAvailability\s*\(|readWindowsConsoleAttachedProcessIds|findOrphanOnInheritedConsole' src/main/providers/foreground
echo '===== Current revision ====='
git rev-parse HEAD

Length of output: 35654


web_search executed:

For Windows 11, what do the Microsoft documentation for FreeConsole and AttachConsole say about a process leaving its inherited console and attaching to a different existing process's console? Is creating a child conhost.exe process required when attaching to an existing console? Include authoritative citations.

Length of output: 8470


@lbvargas99 Thanks for the fix and the Windows check. One case remains: the absence of a console-host child does not prove that an orphan kept the pane’s console.

A process can call FreeConsole and then AttachConsole to join another existing console. If it starts Claude there, findOrphanOnInheritedConsole can select that orphan and report Claude as the pane’s agent.

Please verify membership against the original pane console, or return unavailable when that cannot be established. A test for an orphan that joins an existing console would cover this case. I am not marking the finding as addressed.


📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that the missing conhost child doesn't prove the orphan stayed on the pane console: a descendant that calls FreeConsole + AttachConsole onto another existing console would pass. I looked for a way to bind to the original console and couldn't find one Orca can use once the root has exited:

  • readWindowsConsoleAttachedProcessIds needs a live member of the console to attach through, and the root is gone.
  • The ConPTY job doesn't help either: listPtyJobProcessIds notes that shell exit closes the job, and readWindowsPtyJobProcessIds requires the root in it.
  • The documented APIs don't map a process to its console host. Only the undocumented ProcessConsoleHostProcess class of NtQueryInformationProcess does.

So the remaining options are to accept this case, or to return unavailable whenever the root has exited, which brings back the original bug (#45590) for every pane whose root shell exits after starting the agent.

For it to matter, a descendant of the pane root would have to deliberately move to another console and run a recognized agent there, seen in a fresh table. The send would then type into the pane console, which by then only holds processes waiting on that agent.

I'd lean towards keeping the check as is and documenting the limit. I'll leave this open for a maintainer to decide, and I'm happy to switch to fail-closed if you'd rather have that.

@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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 99dfa15c-2d7c-496e-ad60-1296db0c904c
Commits

Reviewing files that changed from the base of the PR and between f630841 and 1d04599.

Files selected for processing: 3

  • src/main/providers/foreground/windows/agent-process-exited-root.test.ts
  • src/main/providers/foreground/windows/agent-process.ts
  • src/main/providers/foreground/windows/exited-root-orphans.ts

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

(candidate) =>
candidate.depth === 1 &&
!candidates.some(
(child) => child.ppid === candidate.pid && CONSOLE_HOST_NAMES.has(child.name.toLowerCase())

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.

Minor · Functional Correctness · Quick win

Distinguish nested console hosting from leaving the pane console.

A process can host a nested ConPTY while retaining its inherited console. Creating that ConPTY creates a console-host child. The child therefore does not prove that its parent left the pane console. (learn.microsoft.com)

For example, a direct node.exe launcher can keep Claude on the pane console while hosting another ConPTY. This predicate rejects that launcher. If it is the only direct orphan, the resolver returns unavailable without reading membership.

Distinguish this case from an orphan that changed its own console. Add a regression with an attached launcher, its attached Claude child, and a nested console-host child.

@lbvargas99

Copy link
Copy Markdown
Contributor Author

Self-review pass on the exited-root path, fixed in 6feb04e:

  • Recycled root PID: Windows reuses PIDs, so another pane's orphan whose parent once had our dead root's PID could pass for ours. The orphan used for the console read must now be in this pane's job (paneMemberConsoleReader, raw listPtyJobProcessIds); otherwise the result stays unavailable.
  • Ambiguous identity: with no live root, an identity that names no agent or two different agents now stays unavailable instead of returning available: true with a null name, which the wrapper turned into the dead shell's name.
  • No console reader: an exited root without console evidence now stays unavailable. Every Windows fresh caller passes a reader, so behaviour there is unchanged.

The console-binding question in the open thread is unchanged and still left for maintainers.

@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: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e1855e8b-d102-46a6-b257-11036ff97cc5
Commits

Reviewing files that changed from the base of the PR and between 1d04599 and 6feb04e.

Files selected for processing: 4

  • src/main/providers/foreground/pty-confirmation.ts
  • src/main/providers/foreground/windows/agent-process-exited-root.test.ts
  • src/main/providers/foreground/windows/agent-process.ts
  • src/main/providers/foreground/windows/exited-root-orphans.ts

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

@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: 2

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: deefae1f-4b81-459e-96a6-690a5165985e
Commits

Reviewing files that changed from the base of the PR and between 6feb04e and 69a50a8.

Files selected for processing: 4

  • src/main/providers/foreground/pty-confirmation.ts
  • src/main/providers/foreground/windows/agent-process-exited-root.test.ts
  • src/main/providers/foreground/windows/exited-root-orphans.ts
  • src/main/providers/foreground/windows/process-rows.ts

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Preserve foreign-anchor evidence when the orphan identity is unavailable. · agent-process.ts:113

src/main/providers/foreground/windows/agent-process.ts:113
Major · Functional Correctness · Quick win

Preserve foreign-anchor evidence when the orphan identity is unavailable.

If the console filter removes the recognized agent, identity.processName is null. This return then drops the anchorPidForeign value computed at Lines 98–105.

For example, the cached Claude PID can now belong to notepad.exe, while another Claude descendant is excluded by the console filter. With an unavailable job verdict, reconcileWindowsAgentDecision restores the cached Claude name because this result omits anchorPidForeign. The send guard then receives an agent name despite explicit PID-reuse evidence.

Include anchorPidForeign in this unavailable result when it is true. Keep the successful identity return unchanged.

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f2df1216-4d35-417e-81a8-243b652f4d6c
Commits

Reviewing files that changed from the base of the PR and between 69a50a8 and 1d10beb.

Files selected for processing: 8

  • src/main/daemon/pty-subprocess/native-pty-spawn.ts
  • src/main/providers/foreground/pty-confirmation.ts
  • src/main/providers/foreground/windows/agent-process-exited-root.test.ts
  • src/main/providers/foreground/windows/agent-process.ts
  • src/main/providers/foreground/windows/exited-root-orphans.ts
  • src/main/providers/foreground/windows/process-rows.ts
  • src/main/providers/local-pty/local-pty-runtime-spawn.ts
  • src/main/windows/pty-spawn-time.ts

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

@lbvargas99

Copy link
Copy Markdown
Contributor Author

@coderabbitai Thanks, the outside-diff note on agent-process.ts:113 was right. Fixed in 75bb09f: the anchor check now runs right after the inventory query, and every unavailable result after it keeps anchorPidForeign: true when the anchor row proves PID reuse. That covers the exited-root returns and the unreadable-console return, so reconcileWindowsAgentDecision no longer restores the cached agent over that proof. Available results are unchanged. To keep agent-process.ts under the line limit, the check moved without changes to anchor-pid-reuse.ts.

New case: "keeps proof that the cached agent pid was reused when no identity is available". The console filter removes the only agent and the cached Claude pid now belongs to notepad.exe. It fails without the fix.

On the parentage note: agreed. That is the residual window already described under Risk in the PR description.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- revision ---'
git rev-parse HEAD
printf '%s\n' '--- find named and relevant files ---'
fd -a '^(agent-process|anchor-pid-reuse|agent-process-exited-root)\.test\.ts$|^(agent-process|anchor-pid-reuse)\.ts$'
printf '%s\n' '--- map named source files ---'
for name in agent-process.ts anchor-pid-reuse.ts agent-process-exited-root.test.ts; do
  while IFS= read -r path; do
    echo "--- $path ---"
    ast-grep outline "$path" --items all 2>/dev/null || true
    cat -n "$path" | sed -n '1,300p'
  done < <(fd -t f -g "$name")
done
printf '%s\n' '--- reconciliation definitions and calls ---'
rg -n -C 5 'reconcileWindowsAgentDecision\s*\(' src/main || true
printf '%s\n' '--- repository guidance on thread resolution ---'
rg -n -i -C 2 'resolv(e|ing|ed).*thread|thread.*resolv(e|ing|ed)' AGENTS.md .coderabbit.yaml .coderabbit.yml 2>/dev/null || true

Length of output: 44719


Script executed:

#!/bin/bash
set -u
for path in src/main/providers/foreground/windows/cached-agent-revalidation.ts src/main/providers/foreground/pty-confirmation.ts; do
  echo "--- $path ---"
  ast-grep outline "$path" --items all 2>/dev/null || true
  cat -n "$path" | sed -n '1,170p'
done

Length of output: 10788


@lbvargas99 Thanks for the fix. I inspected 75bb09ffaa7: the resolver preserves anchorPidForeign on the later unavailable paths, and reconcileWindowsAgentDecision will not restore the cached agent when that flag is set.

The regression case is present. I did not run it. The parentage risk and the separate console-binding question remain for maintainers.


📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.


Learnings used

Learnt from: CR
Repo: stablyai/orca PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-11-22T06:57:34.024Z
Learning: Source excerpt:
# Repo Rules

- **Tests are the exception.** Prove a change by running it (app via CDP screenshot, CLI, script), not by committing a test. Commit one only for logic where a silent regression is costly: parsers/codecs/round-trips, security boundaries (escaping, path traversal, auth, crypto), persistence/migrations/data loss, concurrency or state-machine invariants, cross-platform paths. It must call real code with minimal mocks, hardcode its expectations, and fail if the fix is reverted; prefer one invariant over many examples. Never test UI behavior ("button does X"), wiring/IPC glue, mock calls, copy, constants, or timing. Critical user flows belong in the golden E2E journeys (`tests/e2e/golden-journeys`), not unit tests. Delete low-value tests you touch instead of updating them. Perf contracts: `*.performance.test.*` only ([rules](./docs/agents-md-refs/test-antipatterns.md#perf-contracts)); more in [anti-patterns](./docs/agents-md-refs/test-antipatterns.md).

If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

…ited

When a Windows pane's root shell exits after starting an agent, the agent
keeps running as an orphan whose parent PID still names the dead root. The
pane inventory returned null for a missing root, so the send guard read the
pane as a shell and refused a running agent with "no-agent".

- On fresh scans, return the dead root's orphans (rootExited) instead of null.
  Direct orphans created before the pane's ConPTY spawn are pruned, so a
  recycled root PID cannot lend an older process tree to the pane.
- Record the spawn time in spawnWithSystemConptyFallback, the shared path for
  daemon, local and preflight ConPTY spawns, keyed by the IPty object.
- Read console membership through a direct orphan once the root is gone, and
  require every direct orphan on that console.
- Orphans can prove an agent, never a shell: no recognized agent stays
  unavailable, and a cached agent that left the console is retired.
- Move context-path helpers to context-path-match.ts.

Fixes stablyai#45590

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/windows-agent-exited-pane-root branch from a7a3dfc to f38a371 Compare November 26, 2026 23:51
@nwparker nwparker changed the title fix(agent-status): recognize a Windows agent whose pane root shell has exited fix(windows): detect agents in panes whose ConPTY root process has exited Nov 26, 2026
@nwparker nwparker closed this Nov 27, 2026
@nwparker nwparker reopened this Nov 27, 2026
@nwparker nwparker closed this Nov 27, 2026
@nwparker nwparker reopened this Nov 27, 2026
@nwparker
nwparker merged commit 613a0fb into stablyai:main Nov 27, 2026
259 of 274 checks passed
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.

[Bug]: Windows send guard refuses a running agent (no-agent) after the pane's root shell exits

2 participants