Skip to content

fix(terminal): size icons and Hangul from late faces however they arrive - #2074

Merged
devswha merged 2 commits into
mainfrom
fix/terminal-late-font-faces
Oct 27, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/terminal-late-font-faces

Conversation

@devswha

@devswha devswha commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

What it fixes

The MEDIUM items of #2064, the follow-up of #2062's bundled Hangul face. Icons and Korean are now sized from the faces that draw them, however the late font loads interleave:

  • Two faces arriving together kept stale widths. Each arrival swapped the icon family's quotes so xterm would measure again. xterm clears its rows synchronously on that change, so the glyph fit caught each swap, except when two arrivals ran in the same task. Both Hangul weights coming from WebKit's cache, or an icon arriving with Korean, are such cases. The second swap then undid the first before the fit looked, and the widths measured with the stand-in stayed. In Ovis for Mac's window, Korean stayed enlarged for Apple SD Gothic Neo's 11.24 px and pushed the rest of its row 1.75 px right. An icon stayed its full em across the next cell.
  • The bundled face was fetched when nothing needed it. Each family was loaded on its own, so Ovis Hangul Mono (265 KB / 277 KB) loaded even when an installed D2Coding or Noto Sans Mono CJK KR drew the Hangul. A font typed in Settings also fetched it through loadFontStack's Mg가 before any Korean was printed.
  • From the re-review of c7fa52e:
    • One fonts.load for several characters tied an arrived chunk to a failed or stalled one.
    • A character drawn while its family was loading was dropped from asked.
    • Each redraw built one string per character.

The change (src/lib/terminalGlyphs.ts, src/lib/fontFamily.ts)

  • Each face is followed by its own loaded promise (followLateFaces, with coversAny from the fix(terminal): draw Hangul in a bundled coding face that matches the Latin #2062 lane's draft patch). A character drawn while a face of its stack covers it and has not loaded follows that face, whatever its weight.
    • A chunk that fails or stalls holds back none of the others.
    • A character drawn while another face of its family loads is followed too.
    • A face that failed is not followed or asked for again.
    • fonts.check is no longer called once per family and glyph.
  • No load is started. The page fetches only the faces its text reaches, so a face behind an installed font that draws the glyph stays unfetched. On eamac, a WKWebView with the app's configuration showed that FontFace.loaded resolves for a load layout started, and that no loadingdone ever fires. A face behind an installed Korean font was never requested, by layout or by a canvas measure.
  • Arrivals are coalesced into one frame per terminal. In that frame the widths are cleared explicitly (not inferred from the family string), the family is set once, and every row is redrawn once. This also covers terminal: late font faces after #2062 (stale widths, split-face loads, redraw cost) #2064's LOW item "a full redraw for each arriving face".
  • Family names are compared the way CSS compares them: unquoted, and without regard to case. A face is still followed when its family was typed in another case ("pretendard variable" draws with the "Pretendard Variable" chunks), and "ovis hangul mono" typed in Settings is left out of the preload too. This was found in the merge-pass review (Codex), fixed in 0706143.
  • A face that never loads holds only a small relay, not the terminal: a stopped terminal's relay is emptied.
  • asked is one Set lookup per drawn character.
  • loadFontStack leaves the bundled Hangul face out of the preload that sizes the grid: it holds no Latin.

Before and after

Ovis for Mac's window (the real app, app/mac built ad hoc on the test MacBook Air, macOS 27.0.1, against isolated test servers from fresh clones of main and this branch). A QA-only script served from each build released both Hangul weights' arrival promises in the same task, as a cache does:

Ovis for Mac: main draws the Korean bars 1.75 px right of the Latin bar, this branch aligns them

Ovis for Mac, Regular + Bold in one task closing bars (Latin, Korean, bold Korean, mixed) Hangul size
main 188, 189.75, 189.75, 189.25 14.46 px (1.11x, fit to the stand-in)
this branch 188, 187.97, 187.97, 188.05 14.09 px (1.084x)

With natural loads (a cold load and two reloads from the cache, in a WKWebView with the app's configuration), main and this branch draw the same: icons 7.83 px in 7.83 px cells, bars aligned. On this branch the cold load ends at the 1.084x fit of the 13 px face, not the 1.2x that the 11.24 px stand-in gives, so WebKit heard the late face with no fonts.load call.

Chrome (scripts/terminal-late-faces-regression.ts, new in the browser lane). Chromium on Linux stands in with fonts as wide as the faces, so the script gives the page WebKit's narrower stand-ins: the same two files drawn smaller with size-adjust. It then delivers the icon and Hangul arrivals in one task. It fails on main (icons drawn at 13 px across the next cell, Korean bar +1.47 px) and passes here (icons 7.8 px, bar +0.11 px):

Chrome regression: main leaves icons at the stand-in's size, this branch fits them

Fetches (Chrome on Linux, Noto Sans Mono CJK KR installed ahead of the bundled face, network log):

main this branch
Terminal font typed in Settings, before any Korean OvisHangulMono-Regular fetched nothing
Regular and bold Korean printed both weights fetched (never drawn) nothing

Where nothing ahead of it draws the Hangul (the Mac app, Safari, the regression's typed stack), both weights still load and are measured again.

#2064 items

  • MEDIUM, stale widths when two faces arrive together: fixed.
  • MEDIUM, the bundled face fetched when it is not needed: fixed (both parts). PaneTerminal.css and DESIGN.md describe the new rule.
  • MEDIUM (re-review), 14x work per redraw: fixed (one Set lookup per character).
  • MEDIUM (Codex), one load ties arrived chunks to a failed or stalled one: fixed.
  • MEDIUM (Codex), asked keeps characters whose request was skipped: fixed (nothing is skipped).
  • LOW items fixed along the way:
    • one full redraw per face;
    • failed faces asked for again;
    • 12 fonts.check calls per glyph;
    • one failed face hiding those that loaded;
    • no unit test for the re-measure path.
  • LOW items left as they are:
    • the exact-range assertion in fontFamily.test.ts;
    • Powerline separators fetching the icon font: not changed here.

Design reference

The design stays #2062's: Zed and Warp size a cell with the font that draws it, which in a browser means measuring again when a late face arrives. This PR only changes how arrivals are heard (each face by its own promise, as lib/fontFaces.ts already does for the chrome) and batched (one layout per frame, however many faces arrive). No external code was adapted.

Checks

  • bun test src/lib/terminalGlyphs.test.ts src/lib/fontFamily.test.ts src/lib/fontFaces.test.ts: 49 pass. New cases:

    • same-task arrivals measure again once;
    • a failed chunk beside an arrived one;
    • a character drawn while its family loads;
    • faces that loaded, failed, sit outside the stack or cover none of the text are not followed;
    • a stopped terminal;
    • a face whose family was typed in another case;
    • coversAny;
    • the preload without the bundled face, in any case;
    • through adjustTerminalGlyphs on a stand-in page: two arrivals in separate frames set the family back before the rows are drawn again, and the icon is still measured from its loaded face (fails without the explicit width clear).

    Each case was checked against a mutation of the code it covers (15 mutations, each caught).

  • Case-insensitive match in Chrome (a QA-only variant of the regression script): a late face declared "Late Hangul", typed as late hangul, arriving after the first drawing. At 9947418 the Korean bar stays 15.41 px right of the Latin one (Hangul fitted for the stand-in); at 0706143 it is 0.11 px off.

  • bun run check fast: pass at 0706143 (typecheck, build, 7684 unit tests, 0 fail).

  • scripts/terminal-late-faces-regression.ts: fails on main 42bd1ef, passes on this branch. It is added to scripts/ci-browser.sh.

  • Mac checks ran in fresh clones in /tmp on the test MacBook Air, with an isolated herdr session and test servers. They were removed afterwards, along with the QA-only gate script.

Follow-up of #2062 for the MEDIUM items of #2064.

- Two arrivals heard in the same task (both Hangul weights from WebKit's
  cache, or an icon with Korean) swapped the family's quotes back before
  the glyph fit looked, so the widths measured with the stand-in stayed.
  Arrivals now coalesce into one frame per terminal: the widths are
  cleared there, the family is set once and every row redrawn once.
- Each face is followed by its own loaded promise (followLateFaces,
  coversAny from the #2062 lane's draft): a chunk that fails or stalls
  holds back none that loaded, a character drawn while another face of
  its family loads is not dropped, and a failed face is not asked again.
- No load is started for a face: the page fetches only the faces its
  text reaches, so Ovis Hangul Mono stays unfetched behind an installed
  Korean font, and loadFontStack leaves it out of the Latin preload.
- The per-redraw ask is one Set lookup per character.

scripts/terminal-late-faces-regression.ts fails on main and passes here.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between dcb0aa9 and 0706143.

Files selected for processing: 9
  • DESIGN.md
  • changelog.d/terminal-late-font-faces.md
  • scripts/ci-browser.sh
  • scripts/terminal-late-faces-regression.ts
  • src/components/PaneTerminal.css
  • src/lib/fontFamily.test.ts
  • src/lib/fontFamily.ts
  • src/lib/terminalGlyphs.test.ts
  • src/lib/terminalGlyphs.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

CSS matches font family names without regard to case, so "pretendard
variable" typed in Settings draws with the "Pretendard Variable" faces.
The late-face follower and the preload's Hangul exclusion compared the
names literally: such a face was never followed, and the widths measured
with the stand-in stayed once it arrived. Both now compare unquoted,
lower-cased names.

A test through adjustTerminalGlyphs also covers the explicit width clear
on arrival: two arrivals in separate frames set the family back before
the rows are drawn again.
@devswha

devswha commented Oct 27, 2026

Copy link
Copy Markdown
Owner Author

Merge-pass review verdicts:

  • 9947418, omo code reviewer: PASS, no HIGH. Its MEDIUM (WebKit) is covered by the eamac WKWebView run and the Ovis for Mac captures in the PR body. Its LOW was the case-sensitive family match.
  • 9947418, Codex Sol: BLOCK on one MEDIUM, a regression from main: face families were matched case-sensitively. It also found a LOW, that widths.clear() was untested.
  • 0706143: both findings are fixed by the lane. The omo and Codex re-reviews of just this commit are running, and their verdicts follow here as soon as they land.

@devswha

devswha commented Oct 27, 2026

Copy link
Copy Markdown
Owner Author

0706143, omo code reviewer: PASS (LOW only).

  • The two case-matching tests fail on 9947418: "pretendard variable" got 0 arrivals instead of 1, and "ovis hangul mono" stayed in the preload. Both pass here: 42/42, and tsc is clean.
  • The new adjustTerminalGlyphs test fails when widths.clear() is removed, so it protects the clear.
  • Quotes, whitespace, single quotes, Korean and full-width names, generic families and the default stack were all tried. The default stack follows the same faces as before.
  • LOW (optional): fontFamily.ts:174 repeats the family match inline instead of reusing familyKey. The iconSize and glyphPage test helpers are brittle.

The Codex re-review of this commit is still running.

@devswha

devswha commented Oct 27, 2026

Copy link
Copy Markdown
Owner Author

0706143, Codex Sol (xhigh): PASS, with no findings in this delta.

  • familyKey is applied to both operands in followLateFaces. The Hangul preload exclusion handles case and quote variants.
  • 42/42 targeted unit tests pass. Run against 9947418's code, exactly the two case-regression tests fail.
  • The redraw test fails when widths.clear() is removed.
  • 30/30 adversarial probes pass, covering quotes, whitespace, Korean and Japanese names, the Turkish i, distinct-name controls and the default stack.

Both reviewers have passed 0706143. #2074 now waits on CI, then merges right after #2070.

@devswha
devswha merged commit b631702 into main Oct 27, 2026
18 of 21 checks passed
@devswha
devswha deleted the fix/terminal-late-font-faces branch October 27, 2026 18:17
@devswha

devswha commented Oct 27, 2026

Copy link
Copy Markdown
Owner Author

Merged at 0706143 by the merge pass.

  • Reviews: omo code reviewer and Codex Sol, both PASS on the fix commit.
  • CI: green after one rerun of chat-virtual-browser-qa.ts. Its scrollbar case is the known load-sensitive flake, and this PR does not touch chat.

CodeRabbit did not review this PR: its review limit was reached. The merge relied on the two reviewers, CI, and the lane's eamac WKWebView and Ovis for Mac captures.

devswha added a commit that referenced this pull request Oct 28, 2026
…when the icon font arrives (#2158)

## What it fixes

The last two items of #2064 that #2074 left open. #2074 fixed every
MEDIUM and most LOWs; its body lists these two as left as they are.

- **Powerline separators redrew every row when the icon font arrived.**
Separators U+E0B0-E0B7 are painted as boxes (`terminalBoxGlyphs.ts`),
not taken from a font. Every drawn character still asked for its late
faces, though, so a prompt whose only private-use characters are
separators followed `Symbols Nerd Font Mono`'s face. When it arrived,
the terminal measured again and drew every row again for nothing.
- **The Hangul face's range test missed a broken range.** It checked
only that the range held no Latin and covered the syllables, so dropping
the compatibility jamo or adding `U+E000-F8FF` still passed.

## The change

- `src/lib/terminalGlyphs.ts`: faces are asked for after the span is
rebuilt. Characters painted as boxes (`isBoxGlyph`) in a span drawn as
boxes ask *quietly* (`followLateFaces(...).ask(families, text, true)`):
their faces are still followed, but an arrival that only they waited for
measures and draws nothing again. xterm measured those characters with
the stand-in too, though, so the first time one is drawn from the font
instead (under the cursor, or with a joiner), the terminal measures
again in the next frame. A single box under the cursor also gets its
cell's spacing from the face at once, so even that first frame is not
drawn at the stand-in's width. A character the font draws keeps asking
as before: the cursor cell, a span with a joiner, Powerline's other
shapes U+E0B8-E0D7 (drawn from the icon font), and the box-drawing
diagonals U+2571-2573, which `BOX_GLYPHS` matches but `boxDrawing`
leaves to the font.
- `src/lib/fontFamily.test.ts`: asserts the exact `U+3131-318E,
U+AC00-D7A3` for both weights. It also reads each woff2's cmap (a small
brotli + format 4 reader in the test) and checks that it maps exactly
those code points. Both files map 11,266 code points: 3131-318E and
AC00-D7A3.

## Before and after

Chrome (headless, the lockfile's build path) on an isolated test herdr
session and a port-0 server. The pane prints `\ue0b0 main \ue0b1 abc
\ue0b2\ue0b3`, the icon font's response is held until the first drawing,
and the script counts how often xterm draws that row again after the
face arrives. The script was QA-only and is not committed.

| | separator row drawn again after the icon face arrived | icon font
fetched |
|---|---|---|
| before #2062 (7eeb7d4) | 2 | yes |
| main 38f0989 | 2 | yes |
| this branch | 0 | yes |

The icon font is still fetched: the page's own layout of the row text
reaches it (it did before #2062 too), and this module starts no load
since #2074. Skipping that fetch would mean taking the separators out of
the text the browser lays out, which this PR does not do.

## #2064 items

With #2074 this closes the issue:
- Powerline separators fetching the icon font and redrawing every row:
the redraw is fixed. The fetch comes from layout and predates #2062 (see
above).
- The exact-range assertion and the cmap check: done.

## Design reference

No UI change. The rule follows #2062/#2074 (Zed and Warp size a cell
from the font that draws it): a character that no font draws needs no
late face.

## Checks

- `bun test src/lib/terminalGlyphs.test.ts`: the new case "follows no
face for Powerline's separators" **fails on main** (1 refresh instead of
0) and passes here. New cases also check:
- an icon beside a separator and a box-drawing diagonal still follow
their faces (the diagonal case fails if the skip uses `BOX_GLYPHS`
instead of `isBoxGlyph`);
- a box painted while its face loads, then drawn under the cursor or
with a joiner after the face arrived, measures again once, and under the
cursor takes its one cell at once. This is the merge pass's MEDIUM at
d92c3a6. Its own reproduction with xterm's real `WidthCache` (13 cases)
passes here.
- `followLateFaces`: a quiet arrival measures nothing until a character
it covers is drawn from it, then once; a face asked for by painted and
font-drawn text measures again when it arrives.

Each was checked against a mutation of the code it covers: dropping the
rebuilt guard, the quiet re-measure, the quiet ask, the
quiet-to-followed upgrade, or the cursor spacing each fails at least one
case.
- `src/lib/fontFamily.test.ts` fails under each mutation of the CSS:
dropping `U+3131-318E`, or adding `U+E000-F8FF`. The cmap reader's
output matches an independent scratch parser for both files. It also
fails on Codex's malformed copies of both fonts, where U+3131's
glyph-array entry plus `idDelta` is glyph 0; a reader that ignored the
delta passed them.
- `bun run check fast`: 7396ca78 passed in full (7912 unit tests, 0
fail). On a384522 (the same code minus one removed test, on newer main)
and on 92e8cc3a the only local failure on 92e8cc3a was
`server/codex.test.ts` "reads short answers in bounded time however many
unclosed links" (11.8 against < 8), the ratio flake after #2150 that
another lane is fixing; this PR does not touch that file. It also failed
this PR's first CI run.
- On the merge pass's fix: the Chrome QA above still draws the separator
row 0 times after the icon arrives, and
`scripts/terminal-late-faces-regression.ts` passes.

## Reviews

- omo-native-code-reviewer: **PASS** (two LOW). LOW 1, diagonals skipped
through `BOX_GLYPHS`, is fixed. LOW 2 was the cmap reader's glyph-0
reading: Codex found the concrete case, and it is fixed.
- Merge pass at d92c3a6: one MEDIUM (a box painted while its face
loaded kept xterm's stand-in width once drawn from the font under the
cursor). Fixed as described above.
- CodeRabbit: one comment on the changelog wording, applied.
- Codex Sol on 92e8cc3a (the merge pass's fix): BLOCK on one MEDIUM. The
quiet flag was read through a closure, which kept a stopped terminal
alive through a face that never loads. Fixed: the arrival handler takes
a plain entry. Codex's probes show the leak on 92e8cc3a and not on the
fix. A WeakRef/`Bun.gc` unit test for it failed every run against the
closure, but also failed 2 to 3 runs in 1000 on the fix (conservative
stack scanning), so it was left out; the comment on `whenLoaded` states
the rule.
- Codex Sol re-review of that fix: the MEDIUM is fixed, no production
finding; its only other finding was that flaky test, now removed.
- Codex Sol 6.1 Fast xhigh, on fd6094f1: BLOCK on one MEDIUM (font-drawn
diagonals lost late-face tracking) and one LOW (cmap `idDelta` on
glyph-array entries). Both are fixed in this head. Its re-review of only
the fix delta: **PASS**, no new findings.

Closes #2064
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant