Repository navigation
Conversation
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.
|
Warning Review limit reachedNext included review available in 5 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PTY IPC test environment now mocks 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation 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 💡
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/main/ipc/pty-ipc-suite-environment.tssrc/main/ipc/pty-renderer-liveness-guard.test.tssrc/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.
| // 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) |
There was a problem hiding this comment.
🎯 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.
| // 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.
…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)
…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)
…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.
…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.
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
maintoday. #15927 (f9750358096) really did collapse it to a window-onlyisRendererGone, 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-outsrc/main/ipc/pty/ipc/write-input.ts:51-53— the per-write reporterThe reported
4 → 0was scoped tosrc/main/ipc/pty.ts, which went from 8,031 lines to a 39-line re-export barrel. A per-file count acrossv1.4.188..HEADshows only relocation:Repo-wide total unchanged, every other file identical.
v1.4.188also predates #15927, so it was never the "before" side of that regression.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
webContentshad noisDestroyedat all, so both guards passed vacuously in every suite. That is also why production writes them defensively astypeof ... === 'function' && ....Changes
Give the fake an
isDestroyedmock (pty-ipc-suite-environment.ts), re-stubbed tofalseeachbeforeEachrather than leftundefinedby a baremockReset, 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:mainThe 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 itsisRendererGoneis exactly the weakened predicate. Its doc comment claims the headless path "now passesnull" — butregister-headless-runtime.ts:26still 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.tsare guarded with onlymainWindow.isDestroyed(), andoperations.ts:139(pty:clearBuffer:request) has no guard at all. All are byte-identical tov1.4.188— pre-existing, not from this cut — and none is demonstrably fatal: thepty:exitfan-out is renderer-initiated and try/catch-wrapped, and the unguardedclearBuffersend 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
src/main/ipcrun: 3,156 pass. 4 pre-existing@parcel/watcherfailures infilesystem-watcher-realandworktree-base-directory-poller— unrelated, import nothing touched here, and fail identically on a pristine tree (verified by stashing)pnpm typecheckclean;oxlintcleanFindings independently corroborated by two reviewers; a third model was unavailable (gateway failure).