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(glyphgrid): contain the generation fan-out, and close the Phase-1b review's doc gaps

enes1b901403174d
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
index 2435fca13..880a95c8e 100644
--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
@@ -13,6 +13,14 @@ engine is caught before the integration is judged.
Branch: `feat/glyphgrid-engine`. Setting: **Settings → Terminal → Terminal rendering**
(`Auto (default)` / `GPU per terminal` / `Shared GPU (experimental)` / `Off (DOM renderer)`).
+**Before you start — the setting is one-way against older builds.** `"shared"` is a value only this
+branch knows: running an OLDER build against the same data dir (the released desktop app, or a
+Server Edition still on `main` pointed at that `settings.json`) validates the unknown value away and
+**permanently rewrites `"terminalGpuRendering": "shared"` back to `"auto"`** on its next settings
+save. This is safe — it degrades to the default renderer, nothing is lost but the choice itself —
+but it is silent and not undone by relaunching this branch, so if a checklist item suddenly reads
+Auto after you switched builds, that is why: re-select Shared and carry on.
+
---
## 1. Setup and baseline
@@ -75,6 +83,10 @@ Branch: `feat/glyphgrid-engine`. Setting: **Settings → Terminal → Terminal r
how visible these are at normal zoom, and whether any padding seam shows on the left/top.
- [ ] **2.14 Scroll area after a font change.** Change the font size while shared is on, then look
at the scrollbar/scroll area geometry: the thumb matches the content, no phantom region.
+- [ ] **2.15 Cursor on a wide glyph.** Put the cursor ON a double-width character (type `日本語`
+ and walk the cursor back over it, or `vim` with the cursor on an emoji): KNOWN — the block
+ covers only the LEFT half-cell of the glyph instead of both columns (L13). Confirm that is
+ what you see, and judge how visible it is at normal zoom.
## 3. Interactions
@@ -109,6 +121,10 @@ Branch: `feat/glyphgrid-engine`. Setting: **Settings → Terminal → Terminal r
text lands with the node — no frame where glyphs sit at the old position or at the origin.
- [ ] **3.13 Stacking.** The canvas is ABOVE the dot grid and BELOW node chrome; the bottom-left
Controls, the minimap and the drawers are all still clickable over a terminal's body.
+- [ ] **3.14 ⌘F in a busy terminal.** Open the find bar and search for a word well up in the
+ scrollback: matches are found and scrolled to, and the counter (`n of m`) is right;
+ KNOWN — the match HIGHLIGHTS are not visible (L12). Navigating next/previous still moves the
+ viewport to each hit, so judge whether searching is usable without the highlight.
## 4. Lifecycle
@@ -171,6 +187,13 @@ Branch: `feat/glyphgrid-engine`. Setting: **Settings → Terminal → Terminal r
assumptions broke on this xterm version.
- [ ] **5.5 No console noise.** Over a full session in shared mode, the console shows no repeated
glyphgrid warnings (each warn is once-per-node-per-reason by design).
+- [ ] **5.6 Soak — the macOS compositor.** Run shared mode **≥30 minutes** on the Mac with several
+ busy terminals: watch for whole-window flicker or black-composited nodes (the exact macOS
+ compositor failure class that motivated `WEBGL_BUDGET_DESKTOP_MAC=10` and the `'auto'`→DOM
+ rule — this run is what tests the branch's central platform hypothesis that ONE context
+ avoids it). Any occurrence = **do not promote beyond experimental**. Note the elapsed time,
+ the terminal count, and whether the machine was on an external display, since the earlier
+ reports had no console error to correlate against.
## 6. Regressions (the modes everyone else is on)
@@ -199,9 +222,14 @@ Branch: `feat/glyphgrid-engine`. Setting: **Settings → Terminal → Terminal r
- **L4 — Square plate corners.** The grid's plate is a rectangle; the node has `border-radius: 10px`
and cannot clip the canvas (it is not a DOM child), so the body's corners read square in shared
mode. Phase 2: rounded/stencilled plate.
-- **L5 — Fit slack at the right/bottom edge.** The plate covers the grid plus the host padding; a
- fit can leave up to one cell of slack, which shows the canvas instead of the terminal background.
- Same Phase-2 fix as L4 (plate sized to the body rect rather than the grid rect).
+- **L5 — The plate is sized to the GRID, so any band wider than the padding shows canvas.** The
+ plate covers the grid plus one scalar of host padding (`padPx`, the 6px max of
+ `.term-node__xterm`'s asymmetric CSS padding), so every band of body that the cell fit does not
+ fill shows the canvas/dot grid through the transparent node body instead of the terminal
+ background. Two shapes of the same defect: (a) up to one cell of **fit slack** at the right/bottom
+ edge; (b) the **letterbox** bands of a node whose aspect leaves more than 6px unfilled — most
+ visible on co-attach/letterboxed nodes, where the band can be tens of pixels. Same Phase-2 fix as
+ L4: size the plate to the BODY rect rather than the grid rect.
- **L6 — Adopting a parked terminal after a font change may keep a stale cell size.** The grid is
registered from the cell xterm reports at adopt time; a font change applied in the same commit
can land after it. Refreshing the node re-registers at the correct size.
@@ -221,6 +249,17 @@ Branch: `feat/glyphgrid-engine`. Setting: **Settings → Terminal → Terminal r
- **L11 — Grids keep drawing while the kanban board covers the canvas.** The board overlay is
opaque, so nothing is visible; it is wasted work, measured by item 4.16 and closed in Phase 2 if
it shows up.
+- **L12 — Terminal search (⌘F) finds, counts and scrolls, but the match HIGHLIGHTS are invisible.**
+ xterm's search addon marks hits as *decorations*, which are painted by the active renderer at
+ cell level; the shared feed carries cells and theme lanes only, with no decoration input, so the
+ engine has nothing to draw. Search itself is unaffected — the addon still walks the buffer, the
+ `n of m` counter is correct, and each hit is scrolled into view — you simply cannot see which
+ cells matched. Phase 2 (a decoration lane in the feed).
+- **L13 — The block cursor on a double-width glyph paints only the left half-cell.** The cursor rect
+ is emitted at one cell's width, while a CJK/emoji cell occupies two columns, so the block covers
+ the left column and the right half of the glyph stays uncovered. Cosmetic and position-correct
+ (the cursor is on the right cell); Phase 2, with the same wide-cell geometry work as the rest of
+ the plate/rect family.
---
diff --git a/src/renderer/canvas/SharedGlyphLayer.test.ts b/src/renderer/canvas/SharedGlyphLayer.test.ts
index f4ae95a88..cf68a3cf4 100644
--- a/src/renderer/canvas/SharedGlyphLayer.test.ts
+++ b/src/renderer/canvas/SharedGlyphLayer.test.ts
@@ -282,4 +282,49 @@ describe('graceful degrade without a GPU', () => {
it('setSharedGlyphCamera is inert without a context', () => {
expect(() => setSharedGlyphCamera({ x: 10, y: 20, zoom: 2 })).not.toThrow()
})
+
+ // The absence paths above are the easy half: every guard inside `createContext` RETURNS null.
+ // A constructor that THROWS instead (a wedged/lost GPU process, a hardened environment that
+ // raises on canvas construction) took a different route out of `ensureLiveContext` — up through
+ // whichever node happened to ask for the context first. It must degrade identically.
+ it('returns null (not a throw) when the OffscreenCanvas constructor THROWS rather than being absent', () => {
+ const g = globalThis as unknown as Record<string, unknown>
+ const hadDocument = 'document' in g
+ const hadOffscreen = 'OffscreenCanvas' in g
+ const prevDocument = g.document
+ const prevOffscreen = g.OffscreenCanvas
+ try {
+ // `creationAttempted` latches after the first attempt so a machine without a GPU is never
+ // asked twice; the teardown `markFailed()` runs is the only thing that clears it, and it is
+ // the supported way to get a fresh attempt out of this module singleton.
+ useSharedGlyph.getState().setEnabled(true)
+ useSharedGlyph.getState().markFailed()
+ useSharedGlyph.setState({ enabled: true, failed: false })
+ warn.mockClear()
+
+ // Past the `typeof document === 'undefined'` guard, so construction is actually attempted.
+ g.document = { createElement: () => ({ style: {}, className: '' }) }
+ g.OffscreenCanvas = class {
+ constructor() {
+ throw new Error('canvas construction refused')
+ }
+ }
+
+ expect(getSharedGlyphContext()).toBeNull()
+ expect(warn).toHaveBeenCalled()
+ expect(String(warn.mock.calls[0]?.[0])).toContain('[glyphgrid]')
+ // A construction throw is "not available here", NOT a session failure: flipping `failed`
+ // would bump the generation and re-notify every registrant from inside the very call one of
+ // them is making, and would additionally kill the mode for the rest of the app run.
+ expect(useSharedGlyph.getState().failed).toBe(false)
+ } finally {
+ if (hadDocument) g.document = prevDocument
+ else delete g.document
+ if (hadOffscreen) g.OffscreenCanvas = prevOffscreen
+ else delete g.OffscreenCanvas
+ // Leave the latch clear so a later test is not silently short-circuited by this one.
+ useSharedGlyph.getState().markFailed()
+ useSharedGlyph.setState({ enabled: false, failed: false })
+ }
+ })
})
diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsx
index 17750c171..e6b2c4aa3 100644
--- a/src/renderer/canvas/SharedGlyphLayer.tsx
+++ b/src/renderer/canvas/SharedGlyphLayer.tsx
@@ -383,7 +383,20 @@ function ensureLiveContext(): LiveContext | null {
if (creationAttempted) return null
creationAttempted = true
ensureSettingsSubscription()
- live = createContext()
+ // Construction is guarded, and deliberately does NOT go through `failSharedGlyph`: a THROW here
+ // (an OffscreenCanvas/2d-context/WebGL constructor that raises instead of returning null on a
+ // hostile or exhausted GPU stack) must degrade EXACTLY like the null-returning paths inside
+ // `createContext` — return null, the caller stays on the DOM renderer. Setting `failed` would
+ // additionally bump the generation and re-notify every registrant from inside a call one of
+ // them is already making, and it would mark the whole session dead for a condition the
+ // null paths treat as "not available here". `creationAttempted` is already true, so the throw
+ // is never retried in a loop.
+ try {
+ live = createContext()
+ } catch (err) {
+ console.warn('[glyphgrid] shared context construction threw; staying on the DOM renderer', err)
+ live = null
+ }
return live
}
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index b20adc396..b89b18acc 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -1147,7 +1147,7 @@ export function TerminalNode({
// grid's own background matches the terminal it belongs to.
bgColor: packThemeBg(term.options.theme?.background),
// The host's CSS padding (`.term-node__xterm`, `4px 2px 2px 6px`) reduced to the one
- // scalar the engine takes; see `platePadPx` for why it is the MINIMUM side.
+ // scalar the engine takes; see `platePadPx` for why it is the MAXIMUM side.
padPx: platePadPx(hostPadding(container))
})
} catch (err) {
@@ -1833,29 +1833,40 @@ export function TerminalNode({
glyphGenUnsub = useSharedGlyph.subscribe((s) => {
if (disposed || s.generation === lastGen) return
lastGen = s.generation
- if (!teardownGlyph()) {
- escalateRespawn('glyphgrid could not restore the DOM renderer')
- return
- }
- // The budget client follows the mode, so this terminal never holds both renderers (the
- // hazard spelled out above). Order matters in both directions and is already right: xterm
- // is back on its own renderer by the line above before a budget client may grant it a
- // context, and the grid is only (re-)registered by the participation effect the epoch bump
- // below schedules — after this. `setVisible` re-states what the IntersectionObserver last
- // reported, because it will not fire again until visibility actually changes and a fresh
- // client starts out believing it is hidden.
- // The SAME test the mount above makes — mode AND a context that exists — so a machine
- // without WebGL2 (where `getSharedGlyphContext()` is null however the setting reads) keeps
- // its budget client instead of ending up with neither renderer coordinated.
- const shared = sharedGlyphActive() && getSharedGlyphContext() !== null
- if (shared && webglHandle) {
- webglHandle.dispose()
- webglHandle = null
- } else if (!shared && !webglHandle) {
- webglHandle = registerWebglClient(id, { acquire: acquireWebgl, release: releaseWebgl })
- webglHandle.setVisible(wasVisible)
+ // EVERY node on the canvas subscribes to this one store, and zustand notifies its listeners
+ // by iterating a Set — a listener that THROWS aborts that loop, so every node registered
+ // after the thrower never hears the bump at all and is stranded holding handles into a
+ // context that has just been disposed. One node's bad luck must not become the canvas's.
+ // Hence: contain the failure here, warn, and let the fan-out continue. This node then sits
+ // on whatever renderer the failed teardown left it with (a manual Refresh recovers it),
+ // which is strictly better than silently poisoning its neighbours.
+ try {
+ if (!teardownGlyph()) {
+ escalateRespawn('glyphgrid could not restore the DOM renderer')
+ return
+ }
+ // The budget client follows the mode, so this terminal never holds both renderers (the
+ // hazard spelled out above). Order matters in both directions and is already right: xterm
+ // is back on its own renderer by the line above before a budget client may grant it a
+ // context, and the grid is only (re-)registered by the participation effect the epoch bump
+ // below schedules — after this. `setVisible` re-states what the IntersectionObserver last
+ // reported, because it will not fire again until visibility actually changes and a fresh
+ // client starts out believing it is hidden.
+ // The SAME test the mount above makes — mode AND a context that exists — so a machine
+ // without WebGL2 (where `getSharedGlyphContext()` is null however the setting reads) keeps
+ // its budget client instead of ending up with neither renderer coordinated.
+ const shared = sharedGlyphActive() && getSharedGlyphContext() !== null
+ if (shared && webglHandle) {
+ webglHandle.dispose()
+ webglHandle = null
+ } else if (!shared && !webglHandle) {
+ webglHandle = registerWebglClient(id, { acquire: acquireWebgl, release: releaseWebgl })
+ webglHandle.setVisible(wasVisible)
+ }
+ setGlyphEpoch((n) => n + 1)
+ } catch (err) {
+ console.warn(`[glyphgrid] generation handler failed for ${id} (continuing)`, err)
}
- setGlyphEpoch((n) => n + 1)
})
const visibilityObserver = new IntersectionObserver(
(entries) => {