Skip to content

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.

fix(webgl-budget): a superseding registration reclaims the predecessor's grant

enes8cf52061a2e3
diff --git a/src/renderer/terminal/webgl-budget.test.ts b/src/renderer/terminal/webgl-budget.test.ts
index 6502657da..dae66a53d 100644
--- a/src/renderer/terminal/webgl-budget.test.ts
+++ b/src/renderer/terminal/webgl-budget.test.ts
@@ -173,4 +173,19 @@ describe('webgl-budget coordinator', () => {
clients.forEach(grant)
expect(clients.every((c) => c.rec.held)).toBe(true)
})
+
+ it('re-registering an id releases the superseded grant (no leaked context, no phantom slot)', () => {
+ const a = fakeClient('dup')
+ grant(a)
+ expect(a.rec.acquires).toBe(1)
+ // Remount races teardown: a second registration under the same id supersedes the first. The
+ // predecessor's grant must be reclaimed here — its own dispose() will short-circuit (stale
+ // handle), so skipping this leaks a real browser context the coordinator no longer counts.
+ const b = fakeClient('dup')
+ expect(a.rec.releases).toBe(1)
+ a.handle.dispose() // stale handle: inert
+ grant(b)
+ expect(b.rec.acquires).toBe(1)
+ b.handle.dispose()
+ })
})
diff --git a/src/renderer/terminal/webgl-budget.ts b/src/renderer/terminal/webgl-budget.ts
index 795e09680..8c83362a8 100644
--- a/src/renderer/terminal/webgl-budget.ts
+++ b/src/renderer/terminal/webgl-budget.ts
@@ -203,10 +203,21 @@ function setVisible(c: Client, visible: boolean): void {
*/
export function registerWebglClient(id: string, callbacks: WebglClientCallbacks): WebglClientHandle {
// A re-register under the same id (e.g. a remount that raced teardown) supersedes the old entry.
+ // Release a still-granted predecessor: its handle's dispose() will short-circuit (stale-handle
+ // guard), so without this the old WebglAddon would leak a real browser context while the
+ // coordinator forgets it held a slot — exactly the overshoot this module exists to prevent.
const existing = clients.get(id)
if (existing) {
cancelAcquire(existing)
cancelRelease(existing)
+ if (existing.granted) {
+ try {
+ existing.release()
+ } catch {
+ // fail-open: a throwing release must not block the new registration
+ }
+ existing.granted = false
+ }
}
const client: Client = {
id,