Skip to content

fix(windows): let a build with no job exports still retire a dead agent - #16563

Merged
nwparker merged 2 commits into
mainfrom
nwparker/win-job-unavailable-console-fallback
Aug 26, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/win-job-unavailable-console-fallback

Conversation

@nwparker

@nwparker nwparker commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88 $\color{#cf222e}{\Huge{\mathbf{−}}}$​21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32

Follow-up to #16419 (a1ec0479e21). Found while triaging Windows issues, not reported by a user — but it affects every Windows user today.

ELI5

#16419 moved the foreground poll's "is this agent still alive?" question from a forked helper to the pane's Win32 job object — the #10857 fix. When the job read returns null, the verdict is 'unavailable', and per docs/reference/ssh-execution-boundary.md that must never be read as death. So the code holds the cached identity.

Correct rule, wrong case. Every shipped Windows release returns null here, because the node-pty patch that adds listJobProcessIds is in no v1.4.* tag, 1.4.188 included (#16059 — I confirmed with git tag --contains).

So for the entire current Windows fleet:

before #16419 after #16419 this PR
forks a helper per poll yes no no
can retire a dead agent yes no, ever yes

Two user-visible symptoms today: a pane keeps showing an agent's name indefinitely after it exits, and because a non-null cache makes idleNoEvidenceShell false, the refresh stays pinned at the 1 s TTL instead of backing off to 15 s — so every pane that ever ran an agent rescans the process table once a second, forever.

The fix

The verdict was missing a distinction:

  • "we could have asked and could not" — a patched build whose tree is no longer tracked. Genuinely unverifiable. Still 'unavailable', still holds. Unchanged.
  • "there is nothing to ask" — a build with no job exports at all. That is not loss of contact; there is simply no evidence source. Now 'unsupported', and the authoritative scan decides alone, exactly as it already does on macOS and Linux.

The scan that reaches this branch has already reported available and found no agent, so trusting it costs nothing extra.

Two things I deliberately did NOT do

No fallback to the forked console probe. That is the #10857 storm this path exists to eliminate, and re-forking per poll for the whole current fleet would be a worse trade than the bug being fixed.

No age-based retirement. My first draft returned 'unproven'/'expired' on age alone. That is wrong: 'unproven' short-circuits the scan, so a live agent that a scan would have confirmed gets retired at 30 s. Deferring to the scan has neither problem.

A testing trap worth flagging

isWindowsPtyJobReadable() is exported from windows-pty-job-membership.ts, beside the read, rather than imported from windows-pty-job.ts. That is not cosmetic: isPtyJobOwnershipAvailable() returns false off Windows, so on a macOS runner every Windows-simulating test would have silently taken the unsupported path — the suite would have been green about a configuration no Windows user has. Co-locating it means the module mock those 19 test files already use controls both facts, and each now declares which build it is simulating.

Verification

  • New verdict tests pin both directions; mutation-verified — collapsing 'unsupported' back into 'unavailable' turns them red.
  • End-to-end test in pty-subprocess-foreground-degraded-scan.test.ts drives a shipped-fleet build (no job exports) and asserts the identity actually retires. Also mutation-verified.
  • Lint 0, typecheck 0, 97/97 reliability gates.
  • src/main + src/shared diffed against an origin/main baseline run in a scratch worktree: no regressions. Six files differed; all six pass in isolation, and setup-agent-sequencing is flakier on main (2/3 runs fail there, 0/3 here).

Note on release ordering

This makes the code correct on both build kinds, so it does not depend on when the node-pty patch ships. But #16059's first item still stands independently: until a release is cut from a commit containing the patch, Windows users get no job-object teardown at all, and this PR only restores retirement for them — not the job mechanism itself.

#16419 (a1ec047) routed the foreground poll's liveness question to the job
object. On a build whose node-pty lacks the job exports the read returns null,
which judgeCachedAgentJobEvidence reports as 'unavailable' -- correctly refusing
to treat loss of contact as death. But that is the wrong reading here, and it
matters more than it looks:

**every shipped Windows release is such a build.** The patch adding
listJobProcessIds is in no v1.4.* tag, 1.4.188 included (#16059). So for every
Windows user today the read is null on every poll, the verdict is always
'unavailable', and the retire path never fires at all. Their panes keep a dead
agent's name indefinitely, and because a non-null cache makes idleNoEvidenceShell
false, the refresh also stays pinned at the 1s TTL instead of backing off to 15s.

That is worse than what #16419 replaced: the forked probe was expensive but it
did retire.

The distinction the verdict was missing is between "we could have asked and could
not" and "there is nothing to ask". Only the first is unverifiable. A build with
no job exports is the second, so it now returns 'unsupported' and the
authoritative scan decides alone -- exactly as it already does off Windows.

Deliberately NOT falling back to the forked console probe: that is the #10857
storm this whole path exists to avoid, and re-forking per poll for the entire
current fleet would be the worse trade. The scan that reaches this branch has
already reported available and found no agent; trusting it needs no fork.

Also deliberately not age-based: an earlier draft retired on age alone, which
would expire a LIVE agent that a scan could have confirmed, since 'unproven'
short-circuits the scan.

isWindowsPtyJobReadable() sits beside the read rather than being imported from
windows-pty-job, so one module mock controls both facts. Without that, every
Windows-simulating test on a macOS runner silently took the unsupported path,
because isPtyJobOwnershipAvailable() is false off Windows -- the suite would have
been testing a configuration no Windows user has.
@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d663b61a-a5e9-48d6-9c95-5779d76beaa5

📥 Commits

Reviewing files that changed from the base of the PR and between 61e93d2 and 5c6570c.

📒 Files selected for processing (9)
  • src/main/daemon/pty-subprocess-cwd-cancel-identity.test.ts
  • src/main/daemon/pty-subprocess-env-inheritance.test.ts
  • src/main/daemon/pty-subprocess-foreground-identity.test.ts
  • src/main/daemon/pty-subprocess-git-credential-guard.test.ts
  • src/main/daemon/pty-subprocess-handle-lifecycle.test.ts
  • src/main/daemon/pty-subprocess-managed-agent-env.test.ts
  • src/main/daemon/pty-subprocess-windows-shell-launch.test.ts
  • src/main/daemon/pty-subprocess-wsl-launch.test.ts
  • src/main/daemon/pty-subprocess.test.ts

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


📝 Walkthrough

Walkthrough

The change adds isWindowsPtyJobReadable() to report Windows PTY job-query support. Cached-agent evidence now distinguishes unsupported job queries from supported queries that return no data. Foreground tracking passes this capability to evidence evaluation and retires stale identity when inspection is unsupported. Tests cover both evidence verdicts, degraded foreground scans, and updated Windows PTY mocks across provider scenarios.

Merge Risk: ⚪ Minimal · up to 5c657

This change restores retirement of dead Windows agents on builds without job exports, with the described tests and checks passing; no actionable merge-blocking risk remains beyond normal review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Windows fix that allows builds without job exports to retire dead agents.
Description check ✅ Passed The description provides a clear ELI5 explanation, change summary, rationale, linked issue references, implementation boundaries, and detailed testing evidence. Several template headings and checklist…
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 24 files.
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 provides a clear ELI5 explanation, change summary, rationale, linked issue references, implementation boundaries, and detailed testing evidence. Several template headings and checklist items are not present, but the core required information is covered.

✨ Finishing Touches
📝 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.

Nine of the nineteen files mocking windows-pty-job-membership supplied only
readWindowsPtyJobProcessIds, so isWindowsPtyJobReadable resolved to undefined in
those suites. They pass today only because none of them reaches the call; the
first one that does gets 'isWindowsPtyJobReadable is not a function'.

Left alone this is the same trap the export exists to prevent -- a suite that is
green about a configuration no user runs -- just arriving as a crash instead of a
wrong answer. All nineteen now declare which build they simulate.
@nwparker
nwparker merged commit 5e900b1 into main Aug 26, 2026
54 checks passed
@nwparker
nwparker deleted the nwparker/win-job-unavailable-console-fallback branch August 26, 2026 07:10
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…nt (stablyai#16563)

* fix(windows): let a build with no job exports still retire a dead agent

stablyai#16419 (a1ec047) routed the foreground poll's liveness question to the job
object. On a build whose node-pty lacks the job exports the read returns null,
which judgeCachedAgentJobEvidence reports as 'unavailable' -- correctly refusing
to treat loss of contact as death. But that is the wrong reading here, and it
matters more than it looks:

**every shipped Windows release is such a build.** The patch adding
listJobProcessIds is in no v1.4.* tag, 1.4.188 included (stablyai#16059). So for every
Windows user today the read is null on every poll, the verdict is always
'unavailable', and the retire path never fires at all. Their panes keep a dead
agent's name indefinitely, and because a non-null cache makes idleNoEvidenceShell
false, the refresh also stays pinned at the 1s TTL instead of backing off to 15s.

That is worse than what stablyai#16419 replaced: the forked probe was expensive but it
did retire.

The distinction the verdict was missing is between "we could have asked and could
not" and "there is nothing to ask". Only the first is unverifiable. A build with
no job exports is the second, so it now returns 'unsupported' and the
authoritative scan decides alone -- exactly as it already does off Windows.

Deliberately NOT falling back to the forked console probe: that is the stablyai#10857
storm this whole path exists to avoid, and re-forking per poll for the entire
current fleet would be the worse trade. The scan that reaches this branch has
already reported available and found no agent; trusting it needs no fork.

Also deliberately not age-based: an earlier draft retired on age alone, which
would expire a LIVE agent that a scan could have confirmed, since 'unproven'
short-circuits the scan.

isWindowsPtyJobReadable() sits beside the read rather than being imported from
windows-pty-job, so one module mock controls both facts. Without that, every
Windows-simulating test on a macOS runner silently took the unsupported path,
because isPtyJobOwnershipAvailable() is false off Windows -- the suite would have
been testing a configuration no Windows user has.

* test: give every job-membership mock the readability export

Nine of the nineteen files mocking windows-pty-job-membership supplied only
readWindowsPtyJobProcessIds, so isWindowsPtyJobReadable resolved to undefined in
those suites. They pass today only because none of them reaches the call; the
first one that does gets 'isWindowsPtyJobReadable is not a function'.

Left alone this is the same trap the export exists to prevent -- a suite that is
green about a configuration no user runs -- just arriving as a crash instead of a
wrong answer. All nineteen now declare which build they simulate.
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 28, 2026
…nt (stablyai#16563)

* fix(windows): let a build with no job exports still retire a dead agent

object. On a build whose node-pty lacks the job exports the read returns null,
which judgeCachedAgentJobEvidence reports as 'unavailable' -- correctly refusing
to treat loss of contact as death. But that is the wrong reading here, and it
matters more than it looks:

**every shipped Windows release is such a build.** The patch adding
listJobProcessIds is in no v1.4.* tag, 1.4.188 included (stablyai#16059). So for every
Windows user today the read is null on every poll, the verdict is always
'unavailable', and the retire path never fires at all. Their panes keep a dead
agent's name indefinitely, and because a non-null cache makes idleNoEvidenceShell
false, the refresh also stays pinned at the 1s TTL instead of backing off to 15s.

That is worse than what stablyai#16419 replaced: the forked probe was expensive but it
did retire.

The distinction the verdict was missing is between "we could have asked and could
not" and "there is nothing to ask". Only the first is unverifiable. A build with
no job exports is the second, so it now returns 'unsupported' and the
authoritative scan decides alone -- exactly as it already does off Windows.

Deliberately NOT falling back to the forked console probe: that is the stablyai#10857
storm this whole path exists to avoid, and re-forking per poll for the entire
current fleet would be the worse trade. The scan that reaches this branch has
already reported available and found no agent; trusting it needs no fork.

Also deliberately not age-based: an earlier draft retired on age alone, which
would expire a LIVE agent that a scan could have confirmed, since 'unproven'
short-circuits the scan.

isWindowsPtyJobReadable() sits beside the read rather than being imported from
windows-pty-job, so one module mock controls both facts. Without that, every
Windows-simulating test on a macOS runner silently took the unsupported path,
because isPtyJobOwnershipAvailable() is false off Windows -- the suite would have
been testing a configuration no Windows user has.

* test: give every job-membership mock the readability export

Nine of the nineteen files mocking windows-pty-job-membership supplied only
readWindowsPtyJobProcessIds, so isWindowsPtyJobReadable resolved to undefined in
those suites. They pass today only because none of them reaches the call; the
first one that does gets 'isWindowsPtyJobReadable is not a function'.

Left alone this is the same trap the export exists to prevent -- a suite that is
green about a configuration no user runs -- just arriving as a crash instead of a
wrong answer. All nineteen now declare which build they simulate.

(cherry picked from commit 5e900b1)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…nt (stablyai#16563)

* fix(windows): let a build with no job exports still retire a dead agent

stablyai#16419 (882741f) routed the foreground poll's liveness question to the job
object. On a build whose node-pty lacks the job exports the read returns null,
which judgeCachedAgentJobEvidence reports as 'unavailable' -- correctly refusing
to treat loss of contact as death. But that is the wrong reading here, and it
matters more than it looks:

**every shipped Windows release is such a build.** The patch adding
listJobProcessIds is in no v1.4.* tag, 1.4.188 included (stablyai#16059). So for every
Windows user today the read is null on every poll, the verdict is always
'unavailable', and the retire path never fires at all. Their panes keep a dead
agent's name indefinitely, and because a non-null cache makes idleNoEvidenceShell
false, the refresh also stays pinned at the 1s TTL instead of backing off to 15s.

That is worse than what stablyai#16419 replaced: the forked probe was expensive but it
did retire.

The distinction the verdict was missing is between "we could have asked and could
not" and "there is nothing to ask". Only the first is unverifiable. A build with
no job exports is the second, so it now returns 'unsupported' and the
authoritative scan decides alone -- exactly as it already does off Windows.

Deliberately NOT falling back to the forked console probe: that is the stablyai#10857
storm this whole path exists to avoid, and re-forking per poll for the entire
current fleet would be the worse trade. The scan that reaches this branch has
already reported available and found no agent; trusting it needs no fork.

Also deliberately not age-based: an earlier draft retired on age alone, which
would expire a LIVE agent that a scan could have confirmed, since 'unproven'
short-circuits the scan.

isWindowsPtyJobReadable() sits beside the read rather than being imported from
windows-pty-job, so one module mock controls both facts. Without that, every
Windows-simulating test on a macOS runner silently took the unsupported path,
because isPtyJobOwnershipAvailable() is false off Windows -- the suite would have
been testing a configuration no Windows user has.

* test: give every job-membership mock the readability export

Nine of the nineteen files mocking windows-pty-job-membership supplied only
readWindowsPtyJobProcessIds, so isWindowsPtyJobReadable resolved to undefined in
those suites. They pass today only because none of them reaches the call; the
first one that does gets 'isWindowsPtyJobReadable is not a function'.

Left alone this is the same trap the export exists to prevent -- a suite that is
green about a configuration no user runs -- just arriving as a crash instead of a
wrong answer. All nineteen now declare which build they simulate.
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