Repository navigation
Match main terminal mirror character widths to the renderer - #7148
Conversation
The renderer's xterm measures with Unicode 11 widths plus ZWJ emoji joining (orca-11-zwj); the daemon's headless mirror parsed the same PTY bytes with xterm's default v6 tables. Emoji advance one cell there instead of two, so every positioned write after an emoji lands shifted in the mirror — emoji-dense rows (agent status lines, usage bars) accumulate interleaved cell tears that are stable across snapshots and identical for every PTY. Snapshot restores then paint those torn rows back into the pane, which is the residual bottom-of-terminal garbage reported after the alt-screen restore clear shipped in v1.4.118 (the ASCII body restores clean; only emoji rows diverge). The same tear also reaches anything else that reads the mirror: terminal read previews, reattach and mobile snapshots. Fix: load Unicode 11 tables in the headless emulator and activate the same shared provider the renderer uses. The provider moves to src/shared/ so both parsers stay pinned to identical width semantics. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThis change applies Orca's Unicode 11 cursor/width provider to the headless terminal emulator so its buffer measurement matches the renderer's cell-width model, preventing snapshot/rehydration drift for wide characters like emoji and ZWJ sequences. A new test suite validates this behavior. Additionally, the import path for the shared unicode provider utility used in the renderer's pane lifecycle was updated to a new shared module location, with a corresponding comment update in pane terminal options. Changes
Sequence Diagram(s)sequenceDiagram
participant HeadlessEmulator
participant Terminal
participant Unicode11Addon
participant activateOrcaTerminalUnicodeProvider
HeadlessEmulator->>Terminal: create instance
HeadlessEmulator->>Unicode11Addon: loadAddon(terminal)
HeadlessEmulator->>activateOrcaTerminalUnicodeProvider: activate(terminal)
Estimated code review effort: 2 (~30 minutes) Related PRs: None identified. Suggested labels: terminal, unicode, bugfix Suggested reviewers: None identified. Poem A rabbit hops through cells of text, 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/daemon/headless-emulator.ts (1)
57-64: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueActivation ordering is correct.
Loading
Unicode11Addonthen callingactivateOrcaTerminalUnicodeProviderimmediately in the constructor, before anywrite()/writeSync()call is reachable, mirrors the same ordering rationale used in the renderer'sopenTerminal(activate before any caller-driven write so widths are baked correctly). This closes the root-cause gap described in the PR.One minor nit: the comment at Lines 57-61 spans 5 lines. As per path instructions,
**/*.{ts,tsx,js,jsx}guidelines state to "Keep comments short — one or two lines, capturing only the non-obvious reason". Consider trimming this to the single non-obvious fact (mismatch causes cell-shifted tears) rather than restating the full bug narrative already covered in the PR description.Source: Path instructions
src/main/daemon/headless-emulator-unicode-width.test.ts (1)
1-28: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTests correctly validate positioned-overwrite and ZWJ-joining behavior.
Column arithmetic in both tests is internally consistent with the described Unicode 11 + ZWJ semantics, and both clean up via
emulator.dispose().Minor nit: the header comment at Lines 4-7 spans 4 lines. As per path instructions,
**/*.{ts,tsx,js,jsx}guidelines call for comments explaining non-obvious behavior to "Keep comments short — one or two lines, capturing only the non-obvious reason".Source: Path instructions
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6a257151-d9d5-4b23-bf3a-8b6abe27cd31
📒 Files selected for processing (5)
src/main/daemon/headless-emulator-unicode-width.test.tssrc/main/daemon/headless-emulator.tssrc/renderer/src/lib/pane-manager/pane-lifecycle.tssrc/renderer/src/lib/pane-manager/pane-terminal-options.tssrc/shared/terminal-unicode-provider.ts
|
Parse-throughput measurement (the emulator parses every PTY byte synchronously in the daemon, so this is the hot path this PR touches). A/B/C benchmark on the real
Run-to-run noise is ±5% (a second run showed 5.6%/14.7%/6.9%), so the honest summary is: single-digit-percent parse-cost increase, worst observed ~8–15% on synthetic emoji floods. Why this is acceptable in absolute terms:
Memory: the v11 BMP width table is a module-level singleton (verified in the addon source: If we ever want the last few points back, the v11-plain→Orca-wrapper gap on emoji content (~5pts) could be shaved with a fast-path reorder in the shared provider's |
Symptom
Follow-up to #7133 (shipped in v1.4.118). User feedback: "a lot better, but have some left at the bottom" — residual garbage confined to the bottom rows of restored agent terminals: a merged status line, a wrapped text fragment on the next row, and a fossil usage-bar row. @brennanb2025 saw the same residue when reproducing.
Root cause
The renderer's xterm measures character widths with Unicode 11 + ZWJ emoji joining (the
orca-11-zwjprovider activated inpane-lifecycle.ts). The daemon's headless mirror (headless-emulator.ts) parsed the same PTY byte stream with xterm's default v6 width tables — no unicode provider at all.Emoji advance one cell there instead of two, so every cursor-positioned write after an emoji lands shifted in the mirror. Emoji-dense rows — exactly the agent TUI's bottom region (
🤖 📁 🌿 ⚡status line, usage bars, spinners) — accumulate interleaved cell tears. This matches the anomaly captured in the first live investigation, where the main-process buffer itself held a torn status line (FSonn t 5,wolfl el— one-cell mid-string shifts), stable across snapshots and identical on every PTY: deterministic parse divergence, not a race.#7133's alt-screen clear made restores paint exactly what the mirror holds — the ASCII body restores clean, and only the emoji rows still tear. The tear also reaches everything else that reads the mirror:
orca terminal readpreviews, reattach snapshots, and mobile snapshots.Fix
Load Unicode 11 tables in the headless emulator and activate the same shared provider the renderer uses. The provider moves from
pane-manager/pane-terminal-unicode-provider.tstosrc/shared/terminal-unicode-provider.tsso both parsers stay pinned to identical width semantics.Tests
headless-emulator-unicode-width.test.tswith positioned-overwrite oracles through the public emulator API. Red on the old code with exactly the observed tear shape ('🤖AB Z'vs'🤖ABZ'— the same one-cell shift aswolfl el); green with the fix. A second oracle pins ZWJ joining against a bare-Unicode-11 regression.src/main/daemon+pane-managersuites: 947 passing (the onepty-subprocessWSL failure is pre-existing on main, verified against a pristine checkout). Typecheck clean.Made with Orca 🐋