Skip to content

fix(tui): reset SGR state after row clears#87

Open
code-yeongyu wants to merge 1 commit into
mainfrom
code-yeongyu/tui-render-sgr-fragment-fix
Open

fix(tui): reset SGR state after row clears#87
code-yeongyu wants to merge 1 commit into
mainfrom
code-yeongyu/tui-render-sgr-fragment-fix

Conversation

@code-yeongyu

@code-yeongyu code-yeongyu commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes TUI rendering corruption where raw ANSI SGR fragments such as 9;131;232m could appear after differential row clears. The local fork has row-clear/repaint optimization paths that are not present upstream; those paths now reset terminal style state immediately after CSI 2K before writing colored content.

Before: changed-row repaint could clear a row and continue in the terminal's previous style state, allowing truecolor SGR tails or colored artifacts to leak into the display.

After: every repaint/replay row clear emits the existing TUI.SEGMENT_RESET before row content, preserving the low-flicker path while avoiding stale style state.

Changes

  • Add reset-aware row clears in TUI repaint, viewport replay, scrollback replay, deleted-line clearing, inserted-row repaint, extra-line clearing, and Kitty image reserved-row pre-clear paths.
  • Add a focused failing-first regression for truecolor changed-row repaint.
  • Update the existing Kitty image cleanup assertion for the reset-aware clear sequence.

QA / Evidence

  • Focused regression RED: packages/tui command node --test --import tsx test/tui-render-sgr-reset.test.ts; captured the missing reset failure in local-ignore/qa-evidence/20260626-tui-render-sgr/tui-render-red.txt.
  • Focused regression GREEN: same command passed after the fix; artifact local-ignore/qa-evidence/20260626-tui-render-sgr/tui-render-green.txt.
  • Existing TUI render suite: node --test --import tsx test/tui-render.test.ts passed 36/36; artifact local-ignore/qa-evidence/20260626-tui-render-sgr/tui-render-suite-green.txt.
  • Required project check: npm run check passed; artifact local-ignore/qa-evidence/20260626-tui-render-sgr/npm-check.txt.
  • Mandatory TUI QA: node .agents/skills/senpi-qa/scripts/tui-smoke.mjs --self-test --driver tmux --evidence tui-render-sgr passed 5/5, confirmed auth unchanged and no raw SGR fragments in the captured TUI transcript; artifacts local-ignore/qa-evidence/20260626-tui-render-sgr/senpi-tui-smoke.txt and local-ignore/qa-evidence/20260626-tui-render-sgr/tui-smoke-tmux.txt.
  • Commit hook reran npm run check successfully before commit.

Risks

The main risk is extra reset bytes in repaint paths affecting terminal styling or Kitty image cleanup. This is covered by the focused SGR repaint regression, the existing TUI render suite including Kitty cleanup, and the tmux smoke test against the real TUI harness.

Secret safety

No raw secret-bearing logs, env dumps, tokens, auth headers, cookies, or credentials are included. The senpi QA script verified the real auth file was unchanged.


Summary by cubic

Reset terminal style after each row clear in the TUI to prevent leaked ANSI SGR state and color artifacts. Keeps low-flicker repaints while ensuring cleared rows start from a neutral style.

  • Bug Fixes
    • Emit a reset immediately after CSI 2K across repaint paths: viewport/scrollback replay, inserted/deleted/extra line clears, and Kitty image reserved-row clears.
    • Added a focused regression test for truecolor changed-row repaint and updated the Kitty image cleanup test to assert the clear+reset sequence.

Written for commit 58339e2. Summary will update on new commits.

Review in cubic

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