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): BLEND_GAMMA 1.45, and instrument the blank-glyph bug

enes3e84bf66737e
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 9ddeea586..7afeb128d 100644
--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
@@ -104,6 +104,37 @@ Auto after you switched builds, that is why: re-select Shared and carry on.
keyed by `(code, style, fg, bg)` with per-glyph ink-box cropping — which reworks `atlas.ts`,
`raster.ts` and the cell/uv contract together and is therefore a **Phase 2** item, not a
round-7 patch. Report it as "2.7 raster gap → Phase 2 color atlas".
+ **Round 7b re-tuned the blend, not the raster.** The device read round 7's full 2.2 decode as
+ slightly TOO THICK, which brackets the answer (1.0 = sRGB-space mix read thin, 2.2 read
+ thick). The compositing gamma is now the single named constant `BLEND_GAMMA = 1.45` in
+ `gl-webgl2.ts` — the text-AA blend gamma Skia and FreeType use, and the right family of number
+ because the coverage in our atlas is CoreText's own rasterization, which already carries its
+ light-on-dark compensation. **If weight is still off, report only WHICH WAY** (thick or thin):
+ the fix is that one constant, down toward 1.0 or up toward 2.2. Do not report "not identical"
+ — that is the one answer nothing can be done with.
+- [ ] **2.7b One letter renders BLANK (open bug — this round collects EVIDENCE, not a fix).**
+ Reported twice: `ç` in round 5 (which "went away" with no root cause found) and lowercase `x`
+ in round 7 — one letter blank all session while its neighbours, including uppercase `X`,
+ render fine. Every headless-auditable path has been audited and is clean: `boxGlyphOps`
+ claims no code point below U+0300 and never returns an empty op list (so the
+ "claimed-but-drew-nothing" blank is ruled out); `raster.draw` clips, re-blacks and inks in
+ that order on BOTH branches; `cellXY` is the single copy of the layout math and the vertex
+ shader recomputes it identically; `strideX = ceil(cellW) >= cellW` always, and the
+ rasterizer's cell is captured at construction and never re-adopted, so ink can never overflow
+ into a neighbour's slot; and the rAF driver calls `frame()` every frame, so a newly
+ rasterized glyph cannot miss its upload. Reproducing needs a real font on a real device.
+ **How to run this item:**
+ 1. In DevTools: `localStorage.setItem('nodeterm.glyphgridDebug','1')`, then reload.
+ 2. Use the app until a letter goes blank. Note **which** letter, and whether its
+ uppercase/lowercase/bold/italic variants also fail.
+ 3. Run `await window.__glyphgridDump()` and open the returned `page` data URL in a new tab —
+ that is a PNG of the whole atlas. **Find the reported letter in it.**
+ - **Not in the atlas (its cell is black)** → the RASTERIZER is the suspect (font, baseline,
+ clip). Report the letter plus the `[glyphgrid] slot … code … at x,y` warn line for it.
+ - **In the atlas, correctly drawn** → the slot→uv mapping or the texture upload is. Report
+ its slot number and the `geometry` block from the dump alongside the PNG.
+ 4. Paste the console's `[glyphgrid]` lines for the letter and its working neighbours.
+ This instrumentation is temporary and comes out when the bug closes.
- [ ] **2.8 Selection visual.** Drag-select inside a terminal: the selection band covers exactly
the selected cells, with correct fg/bg inversion, and matches what the DOM renderer draws.
- [ ] **2.9 Cursor.** A focused terminal shows a solid block cursor at the right cell. It is
diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsx
index 1183e4d9b..25a048327 100644
--- a/src/renderer/canvas/SharedGlyphLayer.tsx
+++ b/src/renderer/canvas/SharedGlyphLayer.tsx
@@ -30,7 +30,7 @@
import { useEffect, useRef, useState } from 'react'
import { create } from 'zustand'
-import { GlyphAtlas } from '../glyphgrid/atlas'
+import { GlyphAtlas, type GlyphSlotAllocation } from '../glyphgrid/atlas'
import type { Camera } from '../glyphgrid/camera'
import { GlyphGridEngine } from '../glyphgrid/engine'
import type { GlyphGL } from '../glyphgrid/gl'
@@ -659,6 +659,73 @@ function usableCell(cell: DeviceCell | undefined): DeviceCell | null {
return { cellW: Math.min(cellW, MAX_CELL_PX), cellH: Math.min(cellH, MAX_CELL_PX) }
}
+/**
+ * TEMPORARY device-debug instrumentation for the blank-single-glyph bug (round 5's `ç`, round 7's
+ * lowercase `x`: one letter renders blank while its neighbours are fine, reproducibly, for the
+ * whole session). It is OFF unless `localStorage['nodeterm.glyphgridDebug'] === '1'`.
+ *
+ * Why instrumentation instead of a fix: every path that can blank ONE slot was audited headlessly
+ * and is clean (see `GlyphSlotAllocation`). Reproducing needs a real font on a real device, so
+ * rather than guess at a fifth candidate, one device round is spent turning the report into a
+ * measurement. Remove this once the bug is closed.
+ *
+ * The dump is the load-bearing half. It answers the one question that halves the search space:
+ * **is the letter missing from the ATLAS, or present in the atlas but blank on screen?**
+ * - missing in the atlas → the rasterizer (font/baseline/clip) is the suspect;
+ * - present in the atlas → the slot→uv mapping or the texture upload is.
+ * Everything else is downstream of that answer, which is why the tester is asked for the PNG and
+ * not for a longer log.
+ */
+function glyphDebugOn(): boolean {
+ try {
+ return typeof localStorage !== 'undefined' && localStorage.getItem('nodeterm.glyphgridDebug') === '1'
+ } catch {
+ // Storage can throw outright (Safari private mode, a locked-down embedder). Debug off is
+ // always a safe answer.
+ return false
+ }
+}
+
+function glyphDebugTap(): ((info: GlyphSlotAllocation) => void) | undefined {
+ if (!glyphDebugOn()) return undefined
+ return ({ slot, code, bold, italic, x, y }): void => {
+ console.warn(
+ `[glyphgrid] slot ${slot} code 0x${code.toString(16)} ${JSON.stringify(
+ String.fromCodePoint(code)
+ )}${bold ? ' bold' : ''}${italic ? ' italic' : ''} at ${x},${y}`
+ )
+ }
+}
+
+/** Exposes `window.__glyphgridDump()` → `{ page, ...geometry }`, where `page` is a PNG data URL of
+ * the whole atlas. Installed only under the debug flag; the tester opens the data URL in a tab and
+ * looks for the reported letter. */
+function installGlyphDump(atlas: GlyphAtlas, raster: { cellW: number; cellH: number }): void {
+ if (!glyphDebugOn() || typeof window === 'undefined') return
+ ;(window as unknown as Record<string, unknown>).__glyphgridDump = async (): Promise<unknown> => {
+ const source = atlas.source
+ const geometry = {
+ pageSizePx: atlas.sizePx,
+ cellW: raster.cellW,
+ cellH: raster.cellH,
+ strideX: atlas.strideX,
+ strideY: atlas.strideY,
+ cols: Math.floor(atlas.sizePx / atlas.strideX),
+ capacity: atlas.capacity
+ }
+ // `source` is the rasterizer's OffscreenCanvas; convertToBlob is the only way to read it back.
+ if (!source || typeof (source as OffscreenCanvas).convertToBlob !== 'function')
+ return { ...geometry, page: null }
+ const blob = await (source as OffscreenCanvas).convertToBlob({ type: 'image/png' })
+ const page = await new Promise<string>((resolve) => {
+ const fr = new FileReader()
+ fr.onload = (): void => resolve(String(fr.result))
+ fr.readAsDataURL(blob)
+ })
+ return { ...geometry, page }
+ }
+}
+
function createContext(cell: DeviceCell): LiveContext | null {
if (typeof document === 'undefined' || typeof OffscreenCanvas === 'undefined') return null
const { fontFamily, fontSize } = useSettings.getState().settings
@@ -687,7 +754,8 @@ function createContext(cell: DeviceCell): LiveContext | null {
'position:absolute;inset:0;width:100%;height:100%;display:block;pointer-events:none'
const gl = createWebgl2GL(canvas)
if (!gl) return null
- const atlas = new GlyphAtlas(raster, ATLAS_PAGE_PX)
+ const atlas = new GlyphAtlas(raster, ATLAS_PAGE_PX, glyphDebugTap())
+ installGlyphDump(atlas, raster)
const engine = new GlyphGridEngine(gl, atlas)
engine.setCamera(lastCamera)
return { engine, atlas, canvas, gl, fontKey: fontKeyOf(fontFamily, fontSize), disposed: false }
diff --git a/src/renderer/glyphgrid/atlas.test.ts b/src/renderer/glyphgrid/atlas.test.ts
index b7c194f30..810c6b056 100644
--- a/src/renderer/glyphgrid/atlas.test.ts
+++ b/src/renderer/glyphgrid/atlas.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { GlyphAtlas, type GlyphRasterizer } from './atlas'
+import { GlyphAtlas, type GlyphRasterizer, type GlyphSlotAllocation } from './atlas'
function fakeRasterizer(cellW = 10, cellH = 20): GlyphRasterizer & { calls: string[] } {
const calls: string[] = []
@@ -151,4 +151,29 @@ describe('GlyphAtlas', () => {
expect(atlas.glyphFor(0x41, false, false)).toBe(1)
expect(atlas.glyphFor(0x42, false, false)).toBe(0) // full → blank, never throws
})
+ describe('debug allocation tap (device instrumentation for the blank-glyph bug)', () => {
+ it('reports each NEW slot with the origin the ink was drawn at, and never on a cache hit', () => {
+ const seen: GlyphSlotAllocation[] = []
+ const atlas = new GlyphAtlas(fakeRasterizer(10, 20), 100, (i) => seen.push(i))
+ atlas.glyphFor(0x78, false, false)
+ atlas.glyphFor(0x78, false, false) // cache hit — must NOT re-report
+ atlas.glyphFor(0x78, true, false) // a different style IS a different slot
+ atlas.glyphFor(0x20, false, false) // the blank slot is never an allocation
+ expect(seen).toEqual([
+ { slot: 1, code: 0x78, bold: false, italic: false, x: 10, y: 0 },
+ { slot: 2, code: 0x78, bold: true, italic: false, x: 20, y: 0 }
+ ])
+ })
+
+ it('a throwing tap costs the log line, not the glyph', () => {
+ const r = fakeRasterizer(10, 20)
+ const atlas = new GlyphAtlas(r, 100, () => {
+ throw new Error('debug tap blew up')
+ })
+ expect(() => atlas.glyphFor(0x78, false, false)).not.toThrow()
+ expect(atlas.glyphFor(0x78, false, false)).toBe(1) // still cached and usable
+ expect(r.calls).toEqual(['120|@10,0']) // ...and rasterized exactly once
+ expect(atlas.dirty).toBe(true)
+ })
+ })
})
diff --git a/src/renderer/glyphgrid/atlas.ts b/src/renderer/glyphgrid/atlas.ts
index b50892ea2..6e19b392b 100644
--- a/src/renderer/glyphgrid/atlas.ts
+++ b/src/renderer/glyphgrid/atlas.ts
@@ -9,6 +9,27 @@ export interface GlyphRasterizer {
readonly source: TexImageSource | null
}
+/** One slot allocation, reported to an optional debug tap. See `GlyphAtlas`'s constructor.
+ *
+ * This exists for ONE open device bug: a single letter (`ç` in round 5, lowercase `x` in round 7)
+ * renders BLANK while its neighbours are fine. Every headless-auditable path was audited and is
+ * clean — box-glyphs claims nothing below U+0300 and never returns an empty op list, the raster
+ * re-blacks under the clip before it inks on BOTH branches, `cellXY` is the single copy of the
+ * layout math and the shader recomputes it identically, `strideX = ceil(cellW) >= cellW` always
+ * (the rasterizer's cell is captured at construction and never re-adopted), and the atlas's dirty
+ * flag is polled by the rAF driver every frame, so no wake-up can be missed. What is left needs a
+ * real font on a real device, which no test here can produce — so the next round collects
+ * evidence instead of guessing. */
+export interface GlyphSlotAllocation {
+ slot: number
+ code: number
+ bold: boolean
+ italic: boolean
+ /** Page-pixel origin the ink was drawn at — `cellXY(slot)`. */
+ x: number
+ y: number
+}
+
export class GlyphAtlas {
private slots = new Map<string, number>()
/** Slot 0 is permanently blank and is never handed to the rasterizer: every space, every
@@ -22,7 +43,12 @@ export class GlyphAtlas {
constructor(
private rasterizer: GlyphRasterizer,
- private pageSizePx = 1024
+ private pageSizePx = 1024,
+ /** Optional DEBUG tap, called once per slot allocation (never on a cache hit, never for the
+ * blank slot). Off in production — the shell only passes one when the device-debug flag is
+ * set. It must never be able to break rendering, so it is called inside a try/catch AFTER the
+ * ink and the bookkeeping are already committed. */
+ private onAllocate?: (info: GlyphSlotAllocation) => void
) {}
/** The metrics `GlyphGL.uploadAtlas` needs to map a slot index to texels. They are
@@ -102,6 +128,15 @@ export class GlyphAtlas {
this.rasterizer.draw(code, bold, italic, x, y)
this.slots.set(key, slot)
this.dirtyFlag = true
+ // LAST, and guarded: the tap is a debug aid, so a throwing callback must cost a log line, not
+ // the glyph — everything above is already committed by the time it runs.
+ if (this.onAllocate) {
+ try {
+ this.onAllocate({ slot, code, bold, italic, x, y })
+ } catch {
+ /* a debug tap never breaks a frame */
+ }
+ }
return slot
}
diff --git a/src/renderer/glyphgrid/gl-webgl2.ts b/src/renderer/glyphgrid/gl-webgl2.ts
index 52316b390..eafdf0af3 100644
--- a/src/renderer/glyphgrid/gl-webgl2.ts
+++ b/src/renderer/glyphgrid/gl-webgl2.ts
@@ -39,6 +39,11 @@ uniform sampler2D uAtlas;
in vec2 vUv;
flat in uvec4 vCell;
out vec4 outColor;
+// The exponent the fg/bg coverage mix is performed under (see main()). NOT 2.2: this is a TEXT-AA
+// blend gamma, not a display EOTF, and the device bracketed it — 1.0 (a plain sRGB-space mix) read
+// thin, 2.2 (the full physical decode) read thick. One named constant so the next nudge, if the
+// reference device still reads a hair off in either direction, is a one-token change.
+const float BLEND_GAMMA = 1.45;
vec4 rgba8(uint c) {
return vec4(float(c & 255u), float((c >> 8) & 255u), float((c >> 16) & 255u),
float((c >> 24) & 255u)) / 255.0;
@@ -65,19 +70,27 @@ void main() {
// NON-LINEAR quantity: at coverage 0.5 it emits 0.5, which the display shows at ~0.5^2.2 = 22%
// of full light instead of 50%. Every mid-coverage edge pixel is under-weighted, and the sum of
// that over a glyph's outline is exactly the "WebGL text looks thinner/softer" defect the device
- // rounds keep reporting.
+ // rounds kept reporting. Decoding, mixing in linear light and re-encoding is what fixes it.
//
- // Decoding to linear, mixing there, and re-encoding puts that same edge pixel at ~0.73 encoded —
- // i.e. it weights the AA edge the way CoreText's own blending does, which is what we are trying
- // to match. pow(2.2) is the shader-standard APPROXIMATION of the sRGB EOTF, not the piecewise
- // curve (which has a linear toe below 0.04045); the two differ only in the near-black range,
- // well under a code point of visible difference here, and the approximation costs two pow()s.
+ // BUT THE EXPONENT IS BLEND_GAMMA (1.45), NOT THE PHYSICAL 2.2 — and that is the whole point of
+ // this paragraph. The coverage in our atlas is not an abstract geometric coverage: it is
+ // CoreText's OWN rasterization of white-on-black, which already carries its font-smoothing
+ // compensation for light-on-dark. Compositing that with the full 2.2 decode applies the
+ // compensation TWICE, and the device duly reported the result as slightly too thick. Text
+ // rasterization stacks land in the same place for the same reason — Skia and FreeType's LCD-filter
+ // era blend AA coverage at a gamma around 1.4-1.5, not at the display's 2.2 — because the value
+ // being blended came out of a text rasterizer, not out of a photograph.
+ //
+ // The answer is BRACKETED by device reports, which is why this number is trustworthy rather than
+ // picked: 1.0 (a plain sRGB-space mix, rounds 1-6) read THIN, 2.2 (round 7) read THICK, 1.45 sits
+ // between them. If the reference device still reads a hair off, move BLEND_GAMMA alone — down
+ // toward 1.0 if it looks thick, up toward 2.2 if it looks thin. Nothing else in this shader is a
+ // weight knob.
//
// Deliberately NOT stacked on top of this: the extra directional coverage boost some GPU text
// stacks use (cov = pow(cov, 1.0/1.2) when fg is brighter than bg). It pulls in the same
- // direction as this fix with a hand-picked exponent, and with one device signal per round we
- // could not tell which of the two overshot if round 8 comes back "too heavy". Gamma is a model;
- // the boost is a knob. Model first.
+ // direction as BLEND_GAMMA, so two knobs would fight over one device signal — and the bracket
+ // above shows a single exponent already spans thin-to-thick. One knob, moved on evidence.
//
// If a gap STILL survives this, stop tuning the compositing: the remaining structural difference
// is that xterm rasterizes in colour at all. Checklist §2.7 already routes that (colour atlas
@@ -86,8 +99,8 @@ void main() {
// Alpha is NOT gamma-encoded and stays a straight lerp, bit-for-bit what the old
// mix(bg, vec4(fg.rgb, 1.0), cov) produced in that lane — the frame's alpha feeds the
// SRC_ALPHA/ONE_MINUS_SRC_ALPHA blend and the page composite below it.
- vec3 lin = mix(pow(bg.rgb, vec3(2.2)), pow(fg.rgb, vec3(2.2)), cov);
- outColor = vec4(pow(lin, vec3(1.0 / 2.2)), mix(bg.a, 1.0, cov));
+ vec3 lin = mix(pow(bg.rgb, vec3(BLEND_GAMMA)), pow(fg.rgb, vec3(BLEND_GAMMA)), cov);
+ outColor = vec4(pow(lin, vec3(1.0 / BLEND_GAMMA)), mix(bg.a, 1.0, cov));
}`
export function createWebgl2GL(canvas: HTMLCanvasElement): GlyphGL | null {