Skip to content

fix: force render refresh on foreground return after background rewrite (U3) - #6758

Open
branben wants to merge 2 commits into
stablyai:mainfrom
branben:fix/tui-artifacts-u3-background-rewrite-refresh
Open

branben wants to merge 2 commits into
stablyai:mainfrom
branben:fix/tui-artifacts-u3-background-rewrite-refresh

Conversation

@branben

@branben branben commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Display artifacts appear in agent TUIs (Codex, Claude Code, OpenCode) left open over SSH for extended periods. Resizing clears them. Issue #5969 originally scoped this to Codex, but it affects any agent whose output goes through Orca's renderer — Claude Code and OpenCode reproduce it identically.

This PR implements U3 of the fix plan (docs/plans/2026-06-28-001-fix-tui-display-artifacts-ssh-idle-plan.md): detect in-place rewrites on background-queued output and force a viewport refresh on the first foreground chunk after idle.

Units U1+U4 (atlas reset on visibility-resume) and U2 (SSH replay dedup) already landed. This closes the remaining trigger gap: background rewrites during idle that would otherwise leave stale cells until resize.

Root cause

writePtyOutputToXterm in pty-connection.ts gates the render refresh decision on foregroundOutput. Background writes during idle carry in-place rewrites (\r, \b, erase sequences) that the gate ignores entirely. U1+U4 wired atlas reset on lifecycle events, but per-chunk rewrites still needed detection.

Changes

  • pty-connection.ts: Added background rewrite detection using existing terminalRewriteOutputRenderRefreshDecision with separate tracking state. On first foreground chunk after a flagged background rewrite, force refresh: true, inPlaceRewrite: true. Flag auto-clears on PTY change (reuses existing lifecycle).
  • replay-guard.ts: Fixed broken @/ alias import → relative path. This was blocking pty-connection.test.ts from loading under vitest.
  • pty-connection.test.ts: 2 new tests:
    • Background CR rewrite → foreground chunk triggers refresh
    • Background normal output → foreground chunk does not trigger refresh (perf guard preserved)

Scope

  • Agent-agnostic: any CLI agent rendering through Orca's xterm.js renderer
  • Cross-platform: macOS, Linux, Windows (string analysis, no OS-specific APIs)
  • The foreground-only gate is preserved — background writes don't trigger per-chunk refreshes, only the lifecycle-anchored refresh on foreground return

Verification

  • tsc --noEmit → clean
  • pnpm vitest run src/renderer/src/components/terminal-pane/ → 1258 tests pass across 105 files
  • Manual: confirmed no per-chunk refresh regression on active terminals

Fixes #5969

Made with Orca 🐋

ELI5

Long-lived SSH agent terminals could show visual garbage until you resized. Orca detects background in-place screen rewrites and forces a refresh so the TUI paints correctly again.

…te (U3)

Background-queued output during idle over SSH can carry in-place rewrites
that leave stale renderer cells. Detect rewrites on the background path and
force a viewport refresh on the first foreground chunk after the violation.

Also fixes a broken @/ alias import in replay-guard.ts (changed to relative
path) that was blocking pty-connection.test.ts from loading under vitest.

Fixes part of stablyai#5969.

Co-Authored-By: Claude <[email protected]>

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

pty-connection.ts adds three new state variables to track in-place rewrite patterns in hidden output chunks. writePtyOutputToXterm now records background rewrite decisions and forces a refresh on the next foreground chunk when needed. clearHiddenOutputRestoreState resets the new state. Two new tests cover the refresh and non-refresh paths. replay-guard.ts switches one import to a relative path.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is detailed, but it does not follow the repository template and omits required sections like Screenshots, Testing, AI Review Report, Security Audit, and Notes. Reformat the description to the repo template and add the missing required sections, including testing checklist, screenshots or no visual change, review, security, and notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: forcing a refresh after a background rewrite when output returns to the foreground.
Linked Issues check ✅ Passed The changes implement the linked bug by forcing a refresh after background rewrites and add tests covering the refresh and no-refresh cases.
Out of Scope Changes check ✅ Passed The replay-guard import path tweak is incidental and supports the new tests; no unrelated functional changes stand out.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1b6b9584-9860-4b66-b3fe-900be704478d

📥 Commits

Reviewing files that changed from the base of the PR and between 5dd58d0 and ecaf51a.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/replay-guard.ts

CR feedback: pendingBackgroundRewriteRefresh was only set on !foreground
chunks, so a CR-boundary rewrite straddling the background→foreground
transition missed the refresh trigger. Now run the rewrite decision
on the first foreground chunk that completes the pending CSI/CR state,
and only consume the flag on genuine foreground writes (not hidden
startup queries).

Also hardens new tests with a null-callback guard per review.

Fixes part of stablyai#5969.

Co-Authored-By: Claude <[email protected]>

Co-authored-by: Orca <[email protected]>
@AmethystLiang
AmethystLiang requested a review from Jinwoo-H June 29, 2026 16:48
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:42
@nwparker nwparker added the bug Something isn't working label Jul 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Remote over ssh codex often has these display artifacts

4 participants