Repository navigation
fix(tui): stop backgrounded shell cards from forcing a full-screen redraw every second - #3751
kimi-agent-bot wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 0881616 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6c81c0418
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45beb19463
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
…w every frame When the first changed line sat above the previous viewport, the differential renderer fell back to a clear-full-redraw (ESC[2J/H/3J plus the whole transcript), so any card ticking above the viewport reprinted and wiped scrollback on every tick. - adopt in-place edits confined above the viewport without redrawing and clamp spanning in-place edits to the visible range instead of full-redrawing the transcript - split scrollback clearing (ESC[3J) out of the automatic fallback redraw; it now only runs for explicit actions like terminal resize - rate-limit automatic clear-full-redraws to one per 2s on a monotonic performance.now() clock (a wall-clock rollback must not stretch the window), merging requests inside the window into a single trailing redraw - let input-driven frames bypass the rate limit: deferring them leaves previousLines stale and swallows typed text until the trailing timer fires; an interactive frame renders immediately, cancels the pending trailing redraw, and leaves the rate-limit clock untouched Registers the divergence as an intent card in packages/pi-tui/UPSTREAM.md.
…nds a command A `!` command auto-backgrounded by the engine's foreground timeout left its card's 1s tick timer running forever: finishShellOutput returned early on the backgrounded resolution, so the card never finalized. In long sessions every tick landed above the viewport and forced a clear-full-redraw of the transcript each second. Mirror the manual ctrl+b detach path: finish the card as backgrounded, set the transcript entry to 'Moved to background.', and drop the stream so the tick stops. The engine's notification turn owns the model notification and the streaming phase from there.
a3f19bf to
1afad5b
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1afad5b883
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…option The guardrails landed unconditionally on TuiMainScreen, changing the published renderer's default behavior for every consumer: automatic fallback redraws could be deferred by up to 2s and no longer cleared the scrollback, and above-viewport edits were adopted without redrawing, even when the host never asked for the Kimi-specific mitigation. The scoped fork rules (packages/pi-tui/AGENTS.md) require local library patches to be additive and default-off with defaults matching upstream. Add TuiMainScreenOptions.guardedAutomaticFullRedraws (default false). Off matches upstream exactly: every fallback is an immediate clear-full-redraw including the scrollback (ESC[2J/H/3J), no rate limit, no above-viewport adoption. On enables the full bundle: above-viewport in-place edit adoption/clamping, scrollback-preserving automatic redraws, the 2s monotonic rate limit with a merged trailing redraw, and the input-driven bypass. apps/kimi-code opts in for its main screen; the single-shot exit-path renderer keeps the default (first paint never reaches the fallback). Tests assert both the default upstream behavior and the opted-in guardrails.
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Problem
In a long TUI session, any card that updates once per second (a running background task card, or a zombie card left behind after a
!command is auto-backgrounded at 120s) forces a clear-screen full redraw on every tick once it scrolls above the visible viewport:ESC[2J ESC[H ESC[3Jfollowed by re-printing the entire transcript from line 0 (~51KB per redraw, ~1Hz, ~3MB/min). The terminal visibly scrolls through history every second, flickers constantly, andESC[3Jdestroys scrollback every second.Root cause
ShellRunComponentruns a 1ssetInterval(apps/kimi-code/src/tui/components/messages/shell-run.ts) →requestRender→TuiMainScreen.doRenderline-diffs tofirstChanged= the card's row →firstChanged < prevViewportTop→fullRender(true)which emits the clear-screen + clear-scrollback sequence plus the full text. This path had no rate limit and no "don't redraw invisible lines" protection.finishShellOutputinkimi-tui.tsreturned early whenbackgrounded === true, sofinish()was never called on the shell-run component after the engine auto-backgrounds a foreground shell command at the 120s timeout (shellCommandService.tsresolves{backgrounded: true}without going through the manual ctrl+b detach path). The card's 1s timer therefore ran forever.Fixes
finishShellOutputnow mirrors the manual detach path —finishBackgrounded()stops the timer and renders the backgrounded view.ESC[3Jon automatic redraws:fullRender(clear, clearScrollback)splits the two semantics; scrollback clearing is kept only for explicit user actions (terminal resize). All automatic fallback full redraws no longer destroy scrollback.firstChangedto the viewport top and takes the normal diff path so visible rows update immediately. Line-count changes or image changes still take the (now rate-limited) full redraw. Trade-off, documented in code andpi-tui/AGENTS.md: a card entirely above the viewport keeps its stale text in scrollback until the next explicit full redraw.Regression tests
packages/pi-tui/test/tui-render.test.ts: new describe block covering confined-above-viewport skip, spanning-boundary clamp, rate limiting, and absence ofESC[3Jon automatic redraws / presence on resize. Verified failing before the fix, passing after.apps/kimi-code/test/tui/kimi-tui-message-flow.test.ts: auto-backgrounded shell command no longer leaves a ticking zombie card.pi-tui 978/978 pass; kimi-code
test/tui2680/2681 pass (the one failure,commands/registry.test.ts~/completion, also fails on a clean base in this container — empty$HOME, unrelated).typecheck(pi-tui, kimi-code) andpnpm lintgreen.Notes for reviewers
This intentionally takes a conservative approach in the core render path: the above-viewport optimization only applies when the line mapping cannot shift (equal line count, no images), and everything else degrades to a rate-limited full redraw rather than being skipped.