CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

BUG: TUI rendering glitch — missing / extra spaces in text, recovers on mouse selection

Open SparkofSpike opened this issue 4 months ago • 9 comments

Description

Intermittent rendering glitches in the TUI: text occasionally loses characters or gains extra spaces. Selecting the affected text with the mouse immediately restores correct rendering.

Environment

  • OS: Windows 10/11
  • Terminal: Windows Terminal
  • codewhale version: v0.9.0 (commit d167c07c9628)
  • Settings: composer_vim_mode = "normal", bracketed_paste = false

Steps to Reproduce

  1. Use codewhale normally for ~15-30 minutes
  2. At some point text in the transcript area will render incorrectly — missing characters or extra stray spaces between words
  3. Click and drag to select the garbled text with the mouse → text immediately snaps back to correct rendering

Expected Behavior

TUI rendering remains correct at all times.

Actual Behavior

Occasional rendering artifacts (dropped glyphs, phantom spaces). The underlying data is intact — text recovers on any repaint trigger (e.g. mouse selection, resize). This suggests a terminal diff/buffer synchronization issue rather than data corruption.

Possible Root Cause

The ratatui diff-based incremental rendering may produce an incorrect diff in some edge case, leaving stale cells in the terminal buffer. Mouse selection forces a full repaint that flushes the buffer.

SparkofSpike avatar Jul 17 '26 18:07 SparkofSpike

Thanks @SparkofSpike for the report.

This issue is staying open for maintainer triage. CodeWhale gets better because people bring us real edge cases from real machines, providers, regions, and workflows.

If you can add a reproduction, logs, version output, screenshots, or the provider/model involved, that makes it much easier for us to verify and harvest the fix. Maintainers may comment /lgtmi to mark recurring issue reporters as approved so this intake note is skipped next time.

github-actions[bot] avatar Jul 17 '26 18:07 github-actions[bot]

Thanks, @SparkofSpike. The fact that mouse selection or resize repairs the text is useful evidence that this is repaint/diff state rather than transcript corruption. I’ve added it to the v0.9.1 Windows/TUI workdown; we’ll first audit existing invalidation/full-redraw paths and add the narrowest defensible fix and verification. We’ll preserve your report credit if it lands.

Hmbown avatar Jul 17 '26 20:07 Hmbown

We audited the current repaint paths and do not yet have evidence for a safe code change; a timer/full-clear workaround would mask the fault and cause flicker. Could you capture one more A/B on the affected Windows machine?

  1. Post Windows Terminal’s exact version (Settings → About) and whether hardware acceleration/software rendering is changed from default.
  2. Run /set synchronized_output off, restart CodeWhale, and note whether the corruption still appears during another 15–30 minute session. This isolates DEC 2026 synchronized output from ratatui diff/cache behavior.
  3. If it appears, press Ctrl+L once and confirm whether that repairs it exactly like selection/resize.
  4. If practical, attach a short screen recording showing the glitch before and after selection, plus whether the affected row was streaming, a completed message, or a tool card. No transcript secrets are needed.

I’m keeping #4479 open in v0.9.1 and preserving @SparkofSpike credit. With that A/B we can choose a narrow terminal-sync or invalidation fix instead of adding speculative periodic repaints.

Hmbown avatar Jul 17 '26 22:07 Hmbown

@Hmbown thanks for the detailed guidance. Here are the test results:

① Windows Terminal version & hardware acceleration

(Tested at ~03:00 CST (UTC+8), 2026-07-18 / 2026-07-17 19:00 UTC — issue was reproducing at this time)

Item Value
WT version 1.24.11911.0
Hardware acceleration Default (no override)
settings.json Not present at user profile path (all defaults)

No useAcrylic, useSoftwareGPU, forceFullRepaintRendering, or any experimental rendering overrides found.


② synchronized_output test

(Tested at ~02:00 CST (UTC+8), 2026-07-18 / 2026-07-17 18:00 UTC — issue was reproducing at this time)

Set synchronized_output = "off" in settings.toml, restarted CodeWhale, and used for ~30 minutes. The rendering glitch still appeared intermittently.

Conclusion: This is not related to the DEC 2026 synchronized output protocol. I guess.


③ Ctrl+L test

(Attempted at ~08:00 CST (UTC+8), 2026-07-18 / 2026-07-18 00:00 UTC — issue could NOT be reproduced despite deliberate effort)

Haven't been able to reproduce the issue today (7/18 08:00 CST (UTC+8) onward), so Ctrl+L is still pending. See the reproduction clues section below for what I tried.


Possible reproduction clue (tentative)

⚠️ Caveat: I had severe insomnia last night — only slept about 2 hours and now (at 08:00) I have a splitting headache and can barely remember what I did. That said, at ~03:00 when the glitch was happening, I was still in reasonably good shape mentally — I was alert enough to file the issue and run the tests. So the glitch itself was real. But the exact sequence of what was on screen and what I did at that time is now fuzzy in my memory due to sleep deprivation. Take this reconstruction with a grain of salt; here's what I think I remember:

After recounting the experience and attempting to reproduce across two sessions (~03:00 and ~08:00 CST (UTC+8)), I have a hunch about the scene that may have triggered the glitch:

Possible trigger = dynamic animation (top) + static table (bottom) coexisting on screen.

The glitch may have appeared when sub-agents were spawned — the TUI shows their running status spinners/animations refreshing on the upper portion of the screen, while a rendered static table sits below. I recall that text in the table area showed missing characters or extra whitespace, and mouse-selecting the affected area immediately restored correct rendering.

But honestly:

  • It's highly intermittent — at ~03:00 CST (UTC+8) I believed the glitch was active, but by ~08:00 I tried to reproduce the exact same scenario (spawned 3 sub-agents + output a table) and it rendered perfectly fine
  • May require longer cumulative usage (like the original 15-30 minute window mentioned in the report) to reach some trigger state — at 08:00 it was a fresh session
  • If the memory is correct, mouse selection restoring rendering would point to a terminal buffer/dirty-rect computation issue rather than data corruption

Speculative root cause (if the clue holds)

If the reproduction clue turns out to be real, my suspicion would be a dirty-rect boundary computation bug in Windows Terminal's AtlasEngine (GPU rendering backend) when it has to handle high-frequency dynamic regions (sub-agent animations) and static regions (tables) simultaneously. The dynamic region's frequent redraw may cause the engine to incorrectly skip or partially cover the static region. Mouse selection (or presumably Ctrl+L) would then trigger a full-screen repaint.

But again — this is just speculation. The fact that it refused to reproduce at 08:00 makes me doubt my own recollection.


Full system environment

Item Value
OS Windows 11 Home China 25H2 (build 26200.8875, 64-bit)
Windows Terminal 1.24.11911.0 (default GPU acceleration)
CodeWhale v0.9.0 (commit d167c07c9628)
synchronized_output off
bracketed_paste false
composer_vim_mode normal
locale zh-Hans

My physical condition has impacted the bug-fixing process, and I'm really sorry about that.

SparkofSpike avatar Jul 18 '26 01:07 SparkofSpike

Thank you, @SparkofSpike — and please do not apologize. Your health comes first; there is no need to keep reproducing this while you have a headache or are sleep-deprived.

This A/B is useful: it rules out synchronized output as the direct cause on Windows Terminal 1.24.11911.0, and the possible animated-subagent/static-table interaction gives us a narrower redraw path to audit. We are checking that path now, including whether animation invalidation can leave stale cells outside its intended region. We will not add a periodic full-screen clear or merge a width change without a reproduction that supports it.

No further action is needed from you now. If the glitch happens naturally later, a single Ctrl+L result and whether the damaged row was a table/tool card/completed message would be enough; otherwise we will keep the issue open, preserve your credit, and build a targeted Windows repro/instrumentation path.

Hmbown avatar Jul 18 '26 02:07 Hmbown

@Hmbown quick update: we narrowed the root cause down to a specific, deterministically reproducible case. See #4510 for details.

Summary: Keycap digit sequences (1️⃣ = U+0031 U+FE0F U+20E3) are 3 codepoints that char_display_width measures as 1 column (1+0+0), but Windows Terminal renders as 2 columns. Unlike single-codepoint circled digits (①②③) which only cause visual overlap, the 3-codepoint keycap sequence gets packed into a single Ratatui cell (width=1), shifting all downstream cell indices by 1 column. This corrupts the diff engine's cell buffer — characters disappear or become spaces, Ctrl+L cannot recover, only mouse selection does.

Reproduction is deterministic: paste 1️⃣ anywhere in a chat message in CodeWhale TUI, and characters after it will disappear every time. We confirmed this across multiple sessions. The simple fix I attempted is a minimal 1-branch addition in char_display_width that gives U+20E3 a width of 1, no dependency changes needed.

If this aligns with what you're seeing in the animation-invalidation audit path, we'd love your review. If not, happy to iterate.

SparkofSpike avatar Jul 18 '26 02:07 SparkofSpike

I'm not sure if it work, sorry to bother. orz.

SparkofSpike avatar Jul 18 '26 02:07 SparkofSpike

The deterministic keycap reproduction was valid and materially changed the release decision. Thank you, @SparkofSpike.

PR #4510 now preserves your authored fix and adds a maintainer follow-up at exact head eec1a0061db95027d8eed22877a6f1c937ffd2d7: whole-grapheme width accounting now covers transcript wrapping, selection, slicing, and truncation, while text-form and isolated combining marks retain their normal semantics. The unrelated CI workflow deletion from the amended branch was restored byte-for-byte.

Local results are green (24 shared-text tests, 40 Markdown rendering tests, the keycap-selection regression, formatting/diff checks, and TUI all-target Clippy). Fresh Windows and macOS CI are running. I moved #4479 back to v0.9.1 and removed needs-info; no more reporter work is needed. We will keep your issue/PR credit in the release notes and record physical Windows confirmation honestly.

Hmbown avatar Jul 18 '26 03:07 Hmbown

Hi @Hmbown , seems v0.9.1 didn't fix the circled digits and keycap rendering. Was this intentional for a later release, or did the code miss the branch? If it's a different issue, I'll open a new one with a full GIF.

SparkofSpike avatar Jul 25 '26 02:07 SparkofSpike