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): drop the deviceCellOf tie-break — xterm's device cell is already current

enesec2fae572a4a
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 82d577e15..e5b52bc15 100644
--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
@@ -390,16 +390,19 @@ Auto after you switched builds, that is why: re-select Shared and carry on.
- [ ] **4.15 dpr change — the atlas is now REBUILT.** Drag the window between the retina display
and an external 1x monitor, **both directions, and then back again**. Expected: geometry
stays correct (the drawing buffer follows), and the text on the new display is as sharp as a
- terminal opened there fresh. Soft or over-sharp text after the move is now a FAILURE, not the
- documented behaviour — that was L10, and this item is what closes it.
+ terminal opened there fresh. Soft or over-sharp text after the move is now a FAILURE. It used
+ to be documented behaviour — through Phase 1c the atlas was never rebuilt on a display change
+ — and this item is what replaced that limitation.
**What the rebuild costs, so it is not mis-filed as a bug.** It is the font-change path: the
shared context is disposed and every terminal re-registers its grid. One repaint of the whole
canvas at the moment of the move is expected, and a brief flash of DOM-rendered text is fine.
A terminal left blank, transparent-but-empty, or stuck on the DOM renderer is not.
**Report specifically:** any `[glyphgrid] atlas cell … does not match …` line in the console
- after a move — that is a grid registering against a measurement taken on the display we left
- (see `deviceCellOf`), and it means the rebuild adopted the OLD cell — and whether the SECOND
- move rebuilds again or the fix latches after the first one.
+ after a move. The re-registration is expected to read the NEW display's cell (the epoch bump
+ tears the grid down first, which restores a DomRenderer that recomputes its dimensions against
+ the live dpr), so that line means the rebuild adopted the OLD one and the sharpness is only
+ half fixed. Also report whether the SECOND move rebuilds again or the fix latches after the
+ first.
- [ ] **4.16 Kanban board — no frames are drawn under it.** Open the board over a shared-mode
project: it is fully opaque (no glyphs showing through). Then the part this item exists for,
which needs BUSY terminals, not idle ones — the idle park already covered idle.
diff --git a/src/renderer/canvas/SharedGlyphLayer.test.ts b/src/renderer/canvas/SharedGlyphLayer.test.ts
index 12983d521..5aebc8445 100644
--- a/src/renderer/canvas/SharedGlyphLayer.test.ts
+++ b/src/renderer/canvas/SharedGlyphLayer.test.ts
@@ -1032,13 +1032,25 @@ describe('syncAtlasPixelRatio', () => {
})
it('is inert on a context that is already disposed — the re-entry guard', () => {
- // `pushViewport` runs from the ResizeObserver AND the window `resize` listener, and a display
- // change fires both. The first disposes; the rest must not bump the epoch again before the
- // effect has re-run with the fresh context.
expect(syncAtlasPixelRatio(1, ctx(2, true))).toBe(false)
expect(useSharedGlyph.getState().generation).toBe(0)
})
+ it('a SECOND observer firing on the same display change does not bump again', () => {
+ // The guard above only means something because of two facts this asserts together, and which a
+ // pre-disposed literal cannot show. (1) `pushViewport` runs from the ResizeObserver AND the
+ // window `resize` listener, and both close over the SAME context object — so the second call
+ // sees what the first one did. (2) `disposeContext()` flips `disposed` on that live object,
+ // which is what the guard reads; here that write is stood in for explicitly, since this
+ // environment can build no real context to dispose.
+ const same = ctx(2)
+ expect(syncAtlasPixelRatio(1, same)).toBe(true)
+ same.disposed = true // ← what `disposeContext()` does to the live context, inside that call
+ expect(syncAtlasPixelRatio(1, same)).toBe(false)
+ // One display change, ONE re-registration of every grid on the canvas.
+ expect(useSharedGlyph.getState().generation).toBe(1)
+ })
+
it('does not rebuild on an unreadable ratio', () => {
expect(syncAtlasPixelRatio(0, ctx(2))).toBe(false)
expect(useSharedGlyph.getState().generation).toBe(0)
diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsx
index 655792df6..c812f100c 100644
--- a/src/renderer/canvas/SharedGlyphLayer.tsx
+++ b/src/renderer/canvas/SharedGlyphLayer.tsx
@@ -1101,9 +1101,18 @@ export function setSharedGlyphCamera(cam: Camera): void {
* view, so switching to a project that is on the board changes it with no view change at all
* (`TerminalNode` gets away with reading the project id once because a project switch remounts it;
* this layer stays mounted across switches).
+ *
+ * The `activeProjectId` check is not redundant with `viewFor`, which falls through to the GLOBAL
+ * default view for an id it does not know: with "Default view = kanban" and no active project (at
+ * boot, or after the last project is closed and the WelcomeScreen covers a still-mounted Canvas),
+ * an empty id would report "covered" and stop the loop with no board up. This is the same
+ * predicate Canvas derives `kanbanOpen` from, and it has to stay literally the same one — two
+ * answers to "is the board up" that can disagree is how a canvas ends up not drawing for a reason
+ * nobody can find.
*/
export function boardCoversCanvas(): boolean {
- return viewFor(useViewMode.getState(), useProjects.getState().activeProjectId ?? '') === 'kanban'
+ const { activeProjectId } = useProjects.getState()
+ return !!activeProjectId && viewFor(useViewMode.getState(), activeProjectId) === 'kanban'
}
export interface BoardFrameGate {
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 6c7048b5c..ea1aa5daf 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -368,34 +368,27 @@ function cssCellOf(term: Terminal): { cellW: number; cellH: number } | null {
* (`charWidth * dpr`) and deliberately handed over UNROUNDED — the atlas rounds only its slot
* PITCH, never the sampled extent.
*
- * **Why this is not simply `dimensions.device.cell`.** The one moment this number is asked for is
- * the moment it is hardest to read: the shared layer rebuilds its atlas when the window moves to a
- * display with a different pixel ratio (`syncAtlasPixelRatio`), and the epoch bump that makes this
- * node re-register rides the window `resize` — while xterm re-measures off its OWN `matchMedia`
- * dpr listener. Nothing orders those two, so `dimensions.device.cell` can still be the cell of the
- * display we just LEFT, and an atlas built from it would be rebuilt at the old resolution: the very
- * defect the rebuild exists to fix, reintroduced one layer down and invisible except as a
- * `warnOnCellDrift` line.
- *
- * The CSS cell is the one that can be trusted across that window, because xterm derives it BY
- * DIVIDING the device cell by the same dpr (`css.cell.width = device.cell.width / dpr`) — so it is
- * dpr-invariant, `css × dpr` reproduces the device cell exactly whenever xterm is up to date, and
- * it is the CORRECT cell when xterm is not. Hence: prefer xterm's own number, and fall back to the
- * scaled CSS cell only when the two disagree, which is exactly the stale-measurement window.
+ * **It is read RAW, and the dpr rebuild does not change that.** A tie-break against the CSS cell
+ * scaled by `window.devicePixelRatio` was tried here (to guard the re-register that follows a
+ * display change against a measurement taken on the display we left) and reverted, for reasons
+ * worth keeping so it is not tried a third time:
+ * - There is no staleness window to guard. `CoreBrowserService.dpr` is a live getter over
+ * `window.devicePixelRatio` — nothing is cached — and the generation bump runs `teardownGlyph()`
+ * BEFORE it raises the epoch, which restores a fresh `DomRenderer` whose constructor recomputes
+ * the dimensions against that live dpr. By the time `setupGlyph` reads it, `device.cell` is the
+ * NEW display's.
+ * - `css × dpr` does not reproduce it anyway. xterm rounds the CSS canvas
+ * (`css.canvas.width = round(device.cell.width * cols / dpr)`) and divides that by `cols`, so
+ * the CSS cell carries a per-terminal residual — the same rounding `addon.ts` documents and
+ * reproduces.
+ * - Which made the reading GEOMETRY-dependent: two terminals with the same font on one retina
+ * display returned different "device cells", tripping `warnOnCellDrift`'s 0.01 threshold on an
+ * ordinary multi-terminal canvas. That is the line the device checklist arms the tester with,
+ * so the guard's only lasting effect would have been false positives on the platform being
+ * promoted.
*/
function deviceCellOf(term: Terminal): { cellW: number; cellH: number } | null {
- const device = cellOf(term, 'device')
- const css = cellOf(term, 'css')
- if (!css) return device
- const dpr = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1
- const scaled = validCellSize(css.cellW * dpr, css.cellH * dpr)
- if (!device || !scaled) return device ?? scaled
- // The slack is a CSS-pixel epsilon carried into device space, so the comparison means the same
- // thing at every ratio: below it the two readings are the same measurement.
- const eps = CELL_SIZE_EPS * dpr
- const agree =
- Math.abs(device.cellW - scaled.cellW) <= eps && Math.abs(device.cellH - scaled.cellH) <= eps
- return agree ? device : scaled
+ return cellOf(term, 'device')
}
/** The guarded read behind both cell accessors. Private API, fully guarded: null simply means