Skip to content

fix(terminal): Codex redraws corrupt the viewport when scrolling during streaming #358

Description

@DodgyBadger

Problem

While Codex is streaming a response, scrolling upward can make terminal content overlap or appear out of order: newer content is hidden by stale rows and the browser-side view remains corrupted. A full browser refresh reconstructs a correct view from tmux.

This still reproduces after the scroll-intent fix in #259.

Confirmed timing gap

flushPendingWrites() captures preserveViewportY, calls terminal.write(writeChunk, callback), then restores the viewport outside the callback. Real xterm parsing is asynchronous, so the restore runs before the redraw changes the buffer.

The existing regression uses a synchronous terminal.write mock and passes. A delayed-callback smoke probe fails:

  • Saved history position: viewportY = 40
  • Codex redraw parses later and moves it to live baseY = 100
  • Final position: 100; expected 40

Baseline: the three targeted terminal suites pass (39 tests), so this timing is not currently covered.

Expected behavior

Scrolling through history while Codex streams should keep the visible content coherent and anchored. Live redraws should continue at the bottom without repainting, overlapping, or reordering the history being viewed.

Acceptance criteria

  • Restore the history anchor only after xterm has parsed the write.
  • Preserve the anchor across consecutive and chunked Codex redraws.
  • Add an asynchronous write-callback regression test.
  • Add a browser smoke test using synchronized, cursor-addressed Codex-style redraws while scrolled up.
  • Refresh is unnecessary to recover a coherent view.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions