Skip to content

test(pty): pin the renderer-liveness guard STA-2373 relies on (STA-5373) - #16345

Merged
nwparker merged 2 commits into
mainfrom
neil/sta-5373-releaseblocker-15927-refactor-reverted-the-sta-2373
Aug 25, 2026
Merged

nwparker merged 2 commits into
mainfrom
neil/sta-5373-releaseblocker-15927-refactor-reverted-the-sta-2373

Conversation

@nwparker

@nwparker nwparker commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​167 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​167
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31 $\color{#cf222e}{\Huge{\mathbf{−}}}$​44 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13

STA-5373 is not a blocker — no production fix in this PR

The ticket reports that #15927 dropped the webContents.isDestroyed() half of the renderer-liveness guard #10065 added for STA-2373, and that the app therefore dies when a daemon death fans out to every pane while the WebContents is torn down.

The guard is present on main today. #15927 (f9750358096) really did collapse it to a window-only isRendererGone, but #15172 (3bc13f7b8cb) landed two days later — despite the lower PR number — and restored the full two-part check at both senders when it split the PTY monolith:

  • src/main/ipc/pty/provider/bind-listeners.ts:31-34 — the daemon-death fan-out
  • src/main/ipc/pty/ipc/write-input.ts:51-53 — the per-write reporter

The reported 4 → 0 was scoped to src/main/ipc/pty.ts, which went from 8,031 lines to a 39-line re-export barrel. A per-file count across v1.4.188..HEAD shows only relocation:

< src/main/ipc/pty.ts:4
> src/main/ipc/pty/ipc/write-input.ts:2
> src/main/ipc/pty/provider/bind-listeners.ts:2

Repo-wide total unchanged, every other file identical. v1.4.188 also predates #15927, so it was never the "before" side of that regression.

Caveat worth checking before closing the ticket: no RC tag exists between #15927 (Aug 22) and #15172 (Aug 24), but if the scanned candidate binary was built from a SHA in that window, that artifact genuinely is affected. The remedy there is a rebuild from current main, not a code change.

What was actually wrong

Nothing pinned the guard. It survived #15927 only because #15172 happened to re-expand it — and the shared PTY test fake made that invisible: its webContents had no isDestroyed at all, so both guards passed vacuously in every suite. That is also why production writes them defensively as typeof ... === 'function' && ....

Changes

Give the fake an isDestroyed mock (pty-ipc-suite-environment.ts), re-stubbed to false each beforeEach rather than left undefined by a bare mockReset, so "renderer alive" is stated rather than accidental.

Cover both senders red/green (pty-renderer-liveness-guard.test.ts). Verified red against a window-only guard and green with the real one:

window-only guard (#15927) guard on main
fan-out, WebContents destroyed ❌ fails ✅ passes
per-write, WebContents dies mid-write ❌ fails ✅ passes

The per-write case needs a chunked write. A single-chunk write is already fenced by isPtyWriteEventFromMainWindow, which rejects the event outright once the WebContents is gone — so a naive test passes for the wrong reason. Only the multi-chunk path awaits a macrotask between chunks, letting the renderer die after the sender check passes. That is the sole route to this sender with a dead WebContents, and what makes its own guard load-bearing.

Delete src/main/ipc/pty-renderer-surface.ts. Zero importers repo-wide, and its isRendererGone is exactly the weakened predicate. Its doc comment claims the headless path "now passes null" — but register-headless-runtime.ts:26 still fakes { isDestroyed: () => true }, because #15172 rolled that back too. The file documents a design that no longer exists and invites reintroducing STA-5373 for real.

Deliberately not in scope

Five other PTY senders and four in ssh-relay-session.ts are guarded with only mainWindow.isDestroyed(), and operations.ts:139 (pty:clearBuffer:request) has no guard at all. All are byte-identical to v1.4.188 — pre-existing, not from this cut — and none is demonstrably fatal: the pty:exit fan-out is renderer-initiated and try/catch-wrapped, and the unguarded clearBuffer send is caught by the RPC dispatcher and degrades to an error response. Worth a tracked cleanup, not a release blocker.

I'd also push back on consolidating these behind a shared helper: that is precisely what #15927 did, and centralizing the predicate is what let it silently weaken.

Verification

  • 17 tests across the two PTY write suites pass
  • Full src/main/ipc run: 3,156 pass. 4 pre-existing @parcel/watcher failures in filesystem-watcher-real and worktree-base-directory-poller — unrelated, import nothing touched here, and fail identically on a pristine tree (verified by stashing)
  • pnpm typecheck clean; oxlint clean

Findings independently corroborated by two reviewers; a third model was unavailable (gateway failure).

STA-5373 reported that #15927 dropped the `webContents.isDestroyed()` half of
the guard #10065 added for STA-2373, and that the app therefore dies when a
daemon death fans out to every pane. The guard is present on main: #15172
restored it at both senders when it split the PTY monolith, and a per-file
count across v1.4.188..HEAD shows only relocation (pty.ts:4 ->
write-input.ts:2 + bind-listeners.ts:2). The reported 4 -> 0 was scoped to
`src/main/ipc/pty.ts`, now a 39-line barrel. No production fix is needed.

What was real is that nothing pinned the guard — it survived #15927 only
because #15172 happened to re-expand it — and the shared PTY test fake made
that invisible: its `webContents` had no `isDestroyed` at all, so both guards
passed vacuously in every suite. That is also why they are written defensively
as `typeof ... === 'function' && ...`.

- Give the fake an `isDestroyed` mock, re-stubbed to `false` each beforeEach
  rather than left `undefined`, so "alive" is stated rather than accidental.
- Cover both senders red/green: the daemon-death fan-out
  (bind-listeners.ts:37) and the per-write reporter (write-input.ts:57).
  Verified red against a window-only guard and green with the real one.

The per-write case needs a chunked write. A single-chunk write is already
fenced by `isPtyWriteEventFromMainWindow`, which rejects the event once the
WebContents is gone; only the multi-chunk path yields a macrotask mid-write,
letting the renderer die after the sender check passes. That is the sole route
to this sender with a dead WebContents, and what makes its own guard
load-bearing.

Also deletes `src/main/ipc/pty-renderer-surface.ts`: zero importers repo-wide,
and its `isRendererGone` is exactly the weakened predicate. Its comment claims
the headless path "now passes null", but register-headless-runtime.ts:26 still
fakes `{ isDestroyed: () => true }` — #15172 rolled that back too. Adopting it
would reintroduce STA-5373 for real.

Verified: 17 tests across the two pty write suites; full src/main/ipc run 3156
pass (4 pre-existing @parcel/watcher failures in filesystem-watcher-real and
worktree-base-directory-poller, unrelated and failing identically on a
pristine tree); pnpm typecheck clean; oxlint clean.
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 5 minutes.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bf64082f-46de-483e-be41-18c5516b1fe9

📥 Commits

Reviewing files that changed from the base of the PR and between 8ea0ed8 and 0276e91.

📒 Files selected for processing (2)
  • src/main/ipc/pty/register-headless-runtime.ts
  • src/main/orcad/orcad-entry.ts
📝 Walkthrough

Walkthrough

The PTY IPC test environment now mocks webContents.isDestroyed() for main and foreign windows and restores its alive state before each test. A new test suite covers pty:writeUnavailable notifications from per-write failures and daemon-death fan-out. The tests verify notifications are sent for live WebContents and suppressed after destruction. The obsolete pty-renderer-surface.ts helper module was removed.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the PTY renderer-liveness guard and regression-test purpose. It is concise and related to the main changes.
Description check ✅ Passed The description is detailed and explains the problem, changes, scope, and verification results. It covers the main template content, although it does not use all template headings or explicitly provid…
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 is detailed and explains the problem, changes, scope, and verification results. It covers the main template content, although it does not use all template headings or explicitly provide the required linked-issue, visual-proof, review, notes, and checklist sections.

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

@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: Pro Plus

Run ID: cc0ab172-cb45-4a5c-9806-a37dbfccc581

📥 Commits

Reviewing files that changed from the base of the PR and between cc48013 and 8ea0ed8.

📒 Files selected for processing (3)
  • src/main/ipc/pty-ipc-suite-environment.ts
  • src/main/ipc/pty-renderer-liveness-guard.test.ts
  • src/main/ipc/pty-renderer-surface.ts
💤 Files with no reviewable changes (1)
  • src/main/ipc/pty-renderer-surface.ts

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

Comment on lines +172 to +175
// Why re-stub, not just reset: a bare mockReset returns undefined, which reads as "alive"
// by accident rather than by intent, and hides a test that forgot to restore liveness.
mainWindow.webContents.isDestroyed.mockReset()
mainWindow.webContents.isDestroyed.mockReturnValue(false)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reset the foreign sender mock as well.

foreignWindowIpcEvent.sender.isDestroyed is created once and is not reset in beforeEach. If a test sets it to true, later tests inherit the destroyed state and can incorrectly suppress IPC sends. Reset it and restore false here, matching mainWindow.webContents.isDestroyed.

Proposed fix
    mainWindow.webContents.isDestroyed.mockReset()
    mainWindow.webContents.isDestroyed.mockReturnValue(false)
+   foreignWindowIpcEvent.sender.isDestroyed.mockReset()
+   foreignWindowIpcEvent.sender.isDestroyed.mockReturnValue(false)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Why re-stub, not just reset: a bare mockReset returns undefined, which reads as "alive"
// by accident rather than by intent, and hides a test that forgot to restore liveness.
mainWindow.webContents.isDestroyed.mockReset()
mainWindow.webContents.isDestroyed.mockReturnValue(false)
// Why re-stub, not just reset: a bare mockReset returns undefined, which reads as "alive"
// by accident rather than by intent, and hides a test that forgot to restore liveness.
mainWindow.webContents.isDestroyed.mockReset()
mainWindow.webContents.isDestroyed.mockReturnValue(false)
foreignWindowIpcEvent.sender.isDestroyed.mockReset()
foreignWindowIpcEvent.sender.isDestroyed.mockReturnValue(false)

#15927 made `registerPtyHandlers` accept `BrowserWindow | null` so the headless
path could pass null instead of faking a window. #15172 reverted that signature
while splitting the PTY monolith, but the comments describing it survived, so
three of them now document an API that does not exist.

- orcad-entry.ts: the module docstring claimed orcad installs its controller via
  `registerPtyHandlers(null, …)`. It uses `registerHeadlessPtyRuntime`, and null
  is not accepted. It also claimed desktop surfaces are "declared rather than
  faked" — true except for the renderer window, which is still faked.
- register-headless-runtime.ts: record why the fake is safe rather than leaving
  `isDestroyed: () => true` looking arbitrary. It is load-bearing: every
  renderer-liveness guard reads it and skips, so no send is attempted.

Also gives the fake a `webContents.isDestroyed`. The real guards check both, and
a missing method reads as "alive" — the same gap this PR fixes in the test fake.
No behavior change: the window-level check already short-circuits.

Verified: 45 tests across the liveness-guard, startup-barrier, management and
kill/exit suites; pnpm typecheck clean; oxlint clean.
@nwparker
nwparker merged commit 0bfd380 into main Aug 25, 2026
50 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 25, 2026
…73) (stablyai#16345)

* test(pty): pin the renderer-liveness guard STA-2373 relies on (STA-5373)

STA-5373 reported that stablyai#15927 dropped the `webContents.isDestroyed()` half of
the guard stablyai#10065 added for STA-2373, and that the app therefore dies when a
daemon death fans out to every pane. The guard is present on main: stablyai#15172
restored it at both senders when it split the PTY monolith, and a per-file
count across v1.4.188..HEAD shows only relocation (pty.ts:4 ->
write-input.ts:2 + bind-listeners.ts:2). The reported 4 -> 0 was scoped to
`src/main/ipc/pty.ts`, now a 39-line barrel. No production fix is needed.

What was real is that nothing pinned the guard — it survived stablyai#15927 only
because stablyai#15172 happened to re-expand it — and the shared PTY test fake made
that invisible: its `webContents` had no `isDestroyed` at all, so both guards
passed vacuously in every suite. That is also why they are written defensively
as `typeof ... === 'function' && ...`.

- Give the fake an `isDestroyed` mock, re-stubbed to `false` each beforeEach
  rather than left `undefined`, so "alive" is stated rather than accidental.
- Cover both senders red/green: the daemon-death fan-out
  (bind-listeners.ts:37) and the per-write reporter (write-input.ts:57).
  Verified red against a window-only guard and green with the real one.

The per-write case needs a chunked write. A single-chunk write is already
fenced by `isPtyWriteEventFromMainWindow`, which rejects the event once the
WebContents is gone; only the multi-chunk path yields a macrotask mid-write,
letting the renderer die after the sender check passes. That is the sole route
to this sender with a dead WebContents, and what makes its own guard
load-bearing.

Also deletes `src/main/ipc/pty-renderer-surface.ts`: zero importers repo-wide,
and its `isRendererGone` is exactly the weakened predicate. Its comment claims
the headless path "now passes null", but register-headless-runtime.ts:26 still
fakes `{ isDestroyed: () => true }` — stablyai#15172 rolled that back too. Adopting it
would reintroduce STA-5373 for real.

Verified: 17 tests across the two pty write suites; full src/main/ipc run 3156
pass (4 pre-existing @parcel/watcher failures in filesystem-watcher-real and
worktree-base-directory-poller, unrelated and failing identically on a
pristine tree); pnpm typecheck clean; oxlint clean.

* docs(pty): correct headless-path comments the stablyai#15172 rebase left stale

path could pass null instead of faking a window. stablyai#15172 reverted that signature
while splitting the PTY monolith, but the comments describing it survived, so
three of them now document an API that does not exist.

- orcad-entry.ts: the module docstring claimed orcad installs its controller via
  `registerPtyHandlers(null, …)`. It uses `registerHeadlessPtyRuntime`, and null
  is not accepted. It also claimed desktop surfaces are "declared rather than
  faked" — true except for the renderer window, which is still faked.
- register-headless-runtime.ts: record why the fake is safe rather than leaving
  `isDestroyed: () => true` looking arbitrary. It is load-bearing: every
  renderer-liveness guard reads it and skips, so no send is attempted.

Also gives the fake a `webContents.isDestroyed`. The real guards check both, and
a missing method reads as "alive" — the same gap this PR fixes in the test fake.
No behavior change: the window-level check already short-circuits.

Verified: 45 tests across the liveness-guard, startup-barrier, management and
kill/exit suites; pnpm typecheck clean; oxlint clean.

(cherry picked from commit 0bfd380)
Pierre-Mike pushed a commit to Pierre-Mike/orca that referenced this pull request Aug 26, 2026
…73) (stablyai#16345)

* test(pty): pin the renderer-liveness guard STA-2373 relies on (STA-5373)

STA-5373 reported that stablyai#15927 dropped the `webContents.isDestroyed()` half of
the guard stablyai#10065 added for STA-2373, and that the app therefore dies when a
daemon death fans out to every pane. The guard is present on main: stablyai#15172
restored it at both senders when it split the PTY monolith, and a per-file
count across v1.4.188..HEAD shows only relocation (pty.ts:4 ->
write-input.ts:2 + bind-listeners.ts:2). The reported 4 -> 0 was scoped to
`src/main/ipc/pty.ts`, now a 39-line barrel. No production fix is needed.

What was real is that nothing pinned the guard — it survived stablyai#15927 only
because stablyai#15172 happened to re-expand it — and the shared PTY test fake made
that invisible: its `webContents` had no `isDestroyed` at all, so both guards
passed vacuously in every suite. That is also why they are written defensively
as `typeof ... === 'function' && ...`.

- Give the fake an `isDestroyed` mock, re-stubbed to `false` each beforeEach
  rather than left `undefined`, so "alive" is stated rather than accidental.
- Cover both senders red/green: the daemon-death fan-out
  (bind-listeners.ts:37) and the per-write reporter (write-input.ts:57).
  Verified red against a window-only guard and green with the real one.

The per-write case needs a chunked write. A single-chunk write is already
fenced by `isPtyWriteEventFromMainWindow`, which rejects the event once the
WebContents is gone; only the multi-chunk path yields a macrotask mid-write,
letting the renderer die after the sender check passes. That is the sole route
to this sender with a dead WebContents, and what makes its own guard
load-bearing.

Also deletes `src/main/ipc/pty-renderer-surface.ts`: zero importers repo-wide,
and its `isRendererGone` is exactly the weakened predicate. Its comment claims
the headless path "now passes null", but register-headless-runtime.ts:26 still
fakes `{ isDestroyed: () => true }` — stablyai#15172 rolled that back too. Adopting it
would reintroduce STA-5373 for real.

Verified: 17 tests across the two pty write suites; full src/main/ipc run 3156
pass (4 pre-existing @parcel/watcher failures in filesystem-watcher-real and
worktree-base-directory-poller, unrelated and failing identically on a
pristine tree); pnpm typecheck clean; oxlint clean.

* docs(pty): correct headless-path comments the stablyai#15172 rebase left stale

stablyai#15927 made `registerPtyHandlers` accept `BrowserWindow | null` so the headless
path could pass null instead of faking a window. stablyai#15172 reverted that signature
while splitting the PTY monolith, but the comments describing it survived, so
three of them now document an API that does not exist.

- orcad-entry.ts: the module docstring claimed orcad installs its controller via
  `registerPtyHandlers(null, …)`. It uses `registerHeadlessPtyRuntime`, and null
  is not accepted. It also claimed desktop surfaces are "declared rather than
  faked" — true except for the renderer window, which is still faked.
- register-headless-runtime.ts: record why the fake is safe rather than leaving
  `isDestroyed: () => true` looking arbitrary. It is load-bearing: every
  renderer-liveness guard reads it and skips, so no send is attempted.

Also gives the fake a `webContents.isDestroyed`. The real guards check both, and
a missing method reads as "alive" — the same gap this PR fixes in the test fake.
No behavior change: the window-level check already short-circuits.

Verified: 45 tests across the liveness-guard, startup-barrier, management and
kill/exit suites; pnpm typecheck clean; oxlint clean.

(cherry picked from commit 0bfd380)
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…73) (stablyai#16345)

* test(pty): pin the renderer-liveness guard STA-2373 relies on (STA-5373)

STA-5373 reported that stablyai#15927 dropped the `webContents.isDestroyed()` half of
the guard stablyai#10065 added for STA-2373, and that the app therefore dies when a
daemon death fans out to every pane. The guard is present on main: stablyai#15172
restored it at both senders when it split the PTY monolith, and a per-file
count across v1.4.188..HEAD shows only relocation (pty.ts:4 ->
write-input.ts:2 + bind-listeners.ts:2). The reported 4 -> 0 was scoped to
`src/main/ipc/pty.ts`, now a 39-line barrel. No production fix is needed.

What was real is that nothing pinned the guard — it survived stablyai#15927 only
because stablyai#15172 happened to re-expand it — and the shared PTY test fake made
that invisible: its `webContents` had no `isDestroyed` at all, so both guards
passed vacuously in every suite. That is also why they are written defensively
as `typeof ... === 'function' && ...`.

- Give the fake an `isDestroyed` mock, re-stubbed to `false` each beforeEach
  rather than left `undefined`, so "alive" is stated rather than accidental.
- Cover both senders red/green: the daemon-death fan-out
  (bind-listeners.ts:37) and the per-write reporter (write-input.ts:57).
  Verified red against a window-only guard and green with the real one.

The per-write case needs a chunked write. A single-chunk write is already
fenced by `isPtyWriteEventFromMainWindow`, which rejects the event once the
WebContents is gone; only the multi-chunk path yields a macrotask mid-write,
letting the renderer die after the sender check passes. That is the sole route
to this sender with a dead WebContents, and what makes its own guard
load-bearing.

Also deletes `src/main/ipc/pty-renderer-surface.ts`: zero importers repo-wide,
and its `isRendererGone` is exactly the weakened predicate. Its comment claims
the headless path "now passes null", but register-headless-runtime.ts:26 still
fakes `{ isDestroyed: () => true }` — stablyai#15172 rolled that back too. Adopting it
would reintroduce STA-5373 for real.

Verified: 17 tests across the two pty write suites; full src/main/ipc run 3156
pass (4 pre-existing @parcel/watcher failures in filesystem-watcher-real and
worktree-base-directory-poller, unrelated and failing identically on a
pristine tree); pnpm typecheck clean; oxlint clean.

* docs(pty): correct headless-path comments the stablyai#15172 rebase left stale

stablyai#15927 made `registerPtyHandlers` accept `BrowserWindow | null` so the headless
path could pass null instead of faking a window. stablyai#15172 reverted that signature
while splitting the PTY monolith, but the comments describing it survived, so
three of them now document an API that does not exist.

- orcad-entry.ts: the module docstring claimed orcad installs its controller via
  `registerPtyHandlers(null, …)`. It uses `registerHeadlessPtyRuntime`, and null
  is not accepted. It also claimed desktop surfaces are "declared rather than
  faked" — true except for the renderer window, which is still faked.
- register-headless-runtime.ts: record why the fake is safe rather than leaving
  `isDestroyed: () => true` looking arbitrary. It is load-bearing: every
  renderer-liveness guard reads it and skips, so no send is attempted.

Also gives the fake a `webContents.isDestroyed`. The real guards check both, and
a missing method reads as "alive" — the same gap this PR fixes in the test fake.
No behavior change: the window-level check already short-circuits.

Verified: 45 tests across the liveness-guard, startup-barrier, management and
kill/exit suites; pnpm typecheck clean; oxlint clean.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…73) (stablyai#16345)

* test(pty): pin the renderer-liveness guard STA-2373 relies on (STA-5373)

STA-5373 reported that stablyai#15927 dropped the `webContents.isDestroyed()` half of
the guard stablyai#10065 added for STA-2373, and that the app therefore dies when a
daemon death fans out to every pane. The guard is present on main: stablyai#15172
restored it at both senders when it split the PTY monolith, and a per-file
count across v1.4.188..HEAD shows only relocation (pty.ts:4 ->
write-input.ts:2 + bind-listeners.ts:2). The reported 4 -> 0 was scoped to
`src/main/ipc/pty.ts`, now a 39-line barrel. No production fix is needed.

What was real is that nothing pinned the guard — it survived stablyai#15927 only
because stablyai#15172 happened to re-expand it — and the shared PTY test fake made
that invisible: its `webContents` had no `isDestroyed` at all, so both guards
passed vacuously in every suite. That is also why they are written defensively
as `typeof ... === 'function' && ...`.

- Give the fake an `isDestroyed` mock, re-stubbed to `false` each beforeEach
  rather than left `undefined`, so "alive" is stated rather than accidental.
- Cover both senders red/green: the daemon-death fan-out
  (bind-listeners.ts:37) and the per-write reporter (write-input.ts:57).
  Verified red against a window-only guard and green with the real one.

The per-write case needs a chunked write. A single-chunk write is already
fenced by `isPtyWriteEventFromMainWindow`, which rejects the event once the
WebContents is gone; only the multi-chunk path yields a macrotask mid-write,
letting the renderer die after the sender check passes. That is the sole route
to this sender with a dead WebContents, and what makes its own guard
load-bearing.

Also deletes `src/main/ipc/pty-renderer-surface.ts`: zero importers repo-wide,
and its `isRendererGone` is exactly the weakened predicate. Its comment claims
the headless path "now passes null", but register-headless-runtime.ts:26 still
fakes `{ isDestroyed: () => true }` — stablyai#15172 rolled that back too. Adopting it
would reintroduce STA-5373 for real.

Verified: 17 tests across the two pty write suites; full src/main/ipc run 3156
pass (4 pre-existing @parcel/watcher failures in filesystem-watcher-real and
worktree-base-directory-poller, unrelated and failing identically on a
pristine tree); pnpm typecheck clean; oxlint clean.

* docs(pty): correct headless-path comments the stablyai#15172 rebase left stale

stablyai#15927 made `registerPtyHandlers` accept `BrowserWindow | null` so the headless
path could pass null instead of faking a window. stablyai#15172 reverted that signature
while splitting the PTY monolith, but the comments describing it survived, so
three of them now document an API that does not exist.

- orcad-entry.ts: the module docstring claimed orcad installs its controller via
  `registerPtyHandlers(null, …)`. It uses `registerHeadlessPtyRuntime`, and null
  is not accepted. It also claimed desktop surfaces are "declared rather than
  faked" — true except for the renderer window, which is still faked.
- register-headless-runtime.ts: record why the fake is safe rather than leaving
  `isDestroyed: () => true` looking arbitrary. It is load-bearing: every
  renderer-liveness guard reads it and skips, so no send is attempted.

Also gives the fake a `webContents.isDestroyed`. The real guards check both, and
a missing method reads as "alive" — the same gap this PR fixes in the test fake.
No behavior change: the window-level check already short-circuits.

Verified: 45 tests across the liveness-guard, startup-barrier, management and
kill/exit suites; pnpm typecheck clean; oxlint clean.
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