Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(desktop): a crashed, reloaded or closed window releases its GitHub subscription
review00309726b454
diff --git a/src/main/index.ts b/src/main/index.tsindex baa1cb1db..ba8f0d14d 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -102,6 +102,7 @@ import { makeProjectSpawnOverrides } from '../core/project-spawn-overrides'import { makeLocalSetupRunner } from '../core/project-setup-runner-local'import { makeSshSetupRunner } from './remote-ssh/ssh-setup-runner'import { registerGitHubIntegration } from '../core/github/integration'+import { releaseOnRendererDeparture } from './renderer-client-release'import { runGitHubCliCommand } from '../core/github/credentials'import {ElectronGitHubSecretStore,@@ -468,13 +469,15 @@ const speechService = new SpeechService({ models: whisperModels, isPremium })// viewer. Inert with zero peers: the registry holds no sink, so none of this ever runs.// Wired once here — do not double-wire (4b Task 4). A second wirePeerRegistry() call would silently// overwrite these deps (last write wins), so keep this the sole call site in src/main.-let dropGitHubRelayClient: ((id: number) => void) | undefined+// Releases a departed client's GitHub issue subscriptions (and the 60 s poll they keep alive).+// Relay peers call it from onPeerGone; the app window from releaseOnRendererDeparture.+let dropGitHubClient: ((id: number) => void) | undefinedwirePeerRegistry({setFlow: (id, sid, resume, owner) => ptyManager.setFlow(id, sid, resume, owner),captureForResync: (sid) => ptyManager.captureForResync(sid),onPeerGone: (id) => {ptyManager.dropClient(id)- dropGitHubRelayClient?.(id)+ dropGitHubClient?.(id)}})@@ -1063,6 +1066,9 @@ function createWindow(): BrowserWindow {// its webContents are destroyed by then.)const presenceId = win.webContents.idpresenceHub.join(presenceId, 'desktop')+ // The GitHub board's subscriptions, released on every way this page can go: closed, crashed,+ // or replaced by a reload (which reuses this webContents id with nothing subscribed).+ releaseOnRendererDeparture(win, win.webContents, () => dropGitHubClient?.(presenceId))win.on('closed', () => {presenceHub.leave(presenceId)// This webContents is a pty SUBSCRIBER (co-attach: one pty, N subscribers, keyed by the@@ -1743,7 +1749,7 @@ app.whenReady().then(async () => {secret: githubSecret,run: runGitHubCliCommand})- dropGitHubRelayClient = (id) => github.service.dropClient(id)+ dropGitHubClient = (id) => github.service.dropClient(id)// Machine-local record of what has already been reported, per project — never git-shared, or a// cloned repo could hand this machine a pre-loaded "already reported" ledger.const reportLedger = new ReportLedgerStore(app.getPath('userData'))diff --git a/src/main/renderer-client-release.test.ts b/src/main/renderer-client-release.test.tsnew file mode 100644index 000000000..83dadf3ba--- /dev/null+++ b/src/main/renderer-client-release.test.ts@@ -0,0 +1,46 @@+import { EventEmitter } from 'node:events'+import { describe, expect, it, vi } from 'vitest'+import { releaseOnRendererDeparture } from './renderer-client-release'++function wired() {+ const win = new EventEmitter()+ const contents = new EventEmitter()+ const release = vi.fn()+ releaseOnRendererDeparture(win, contents, release)+ return { win, contents, release }+}++describe('releaseOnRendererDeparture', () => {+ it('releases when the window closes', () => {+ const { win, release } = wired()+ win.emit('closed')+ expect(release).toHaveBeenCalledTimes(1)+ })++ it('releases when the renderer process dies', () => {+ const { contents, release } = wired()+ contents.emit('render-process-gone', {}, { reason: 'oom' })+ expect(release).toHaveBeenCalledTimes(1)+ })++ it('releases when a reload commits a new document (the same webContents id comes back empty)', () => {+ const { contents, release } = wired()+ contents.emit('did-navigate', {}, 'file:///app/index.html', 200, 'OK')+ expect(release).toHaveBeenCalledTimes(1)+ })++ it('does not release for an in-page navigation, where the page and its subscriptions live on', () => {+ const { contents, release } = wired()+ contents.emit('did-navigate-in-page', {}, 'file:///app/index.html#x', true)+ contents.emit('did-start-navigation', { isMainFrame: true, isSameDocument: false })+ expect(release).not.toHaveBeenCalled()+ })+})++describe('main/index.ts wiring', () => {+ it('releases the window GitHub subscriber through the shared helper', async () => {+ const { readFileSync } = await import('node:fs')+ const source = readFileSync(new URL('./index.ts', import.meta.url), 'utf8').replace(/\r\n/g, '\n')+ expect(source).toMatch(/releaseOnRendererDeparture\(win, win\.webContents, \(\) => dropGitHubClient\?\.\(presenceId\)\)/)+ })+})diff --git a/src/main/renderer-client-release.ts b/src/main/renderer-client-release.tsnew file mode 100644index 000000000..24e91fb5b--- /dev/null+++ b/src/main/renderer-client-release.ts@@ -0,0 +1,28 @@+// A renderer that goes away without saying so still holds whatever it subscribed to in core. The+// GitHub issue service keys subscribers by the webContents id and polls every 60 s for each+// repository that has one; a crashed, reloaded or closed window sends no unsubscribe, so its+// subscription (and that poll) lived for the rest of the app run. Relay peers and Server Edition+// sockets already release theirs on departure; this is the desktop window's equivalent.+//+// Electron-free on purpose (structural emitters), so the three signals are pressed by a test:+// - `closed`: the window is gone (`close` only hides it on macOS).+// - `render-process-gone`: the page died; the crash policy may reload it under the SAME id.+// - `did-navigate`: a new document COMMITTED in the main frame (a reload, ⌘R). Deliberately not+// `did-start-navigation`, which also fires for a navigation the navigation guard then blocks —+// releasing there would silently drop a live board's subscription. An in-page navigation+// (`did-navigate-in-page`) keeps the document, so it keeps the subscription.+// Releasing is idempotent; firing twice (a crash followed by its reload) is harmless.++interface EmitterLike {+ on(event: string, listener: (...args: unknown[]) => void): unknown+}++export function releaseOnRendererDeparture(+ win: EmitterLike,+ contents: EmitterLike,+ release: () => void+): void {+ win.on('closed', () => release())+ contents.on('render-process-gone', () => release())+ contents.on('did-navigate', () => release())+}