Skip to content

fix(tui): avoid leaking footer when resuming a missing session - #202

Merged
liruifengv merged 5 commits into
mainfrom
fix/resume-missing-session-footer-leak
May 29, 2026
Merged

fix(tui): avoid leaking footer when resuming a missing session#202
liruifengv merged 5 commits into
mainfrom
fix/resume-missing-session-footer-leak

Conversation

@liruifengv

@liruifengv liruifengv commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No issue — problem described below.

Problem

Resuming a non-existent session correctly errors out, but the footer (including the context: … statusline below it) is painted to the terminal before the error, leaving stray chrome stranded above the error message.

Root cause: the footer is mounted into the render tree at construction. Early in init(), refreshAvailableModels() calls setAppState()ui.requestRender(), which schedules a render that flushes during a later await. pi-tui's TUI.stopped defaults to false, so doRender() runs even though ui.start() was never called, painting the footer. init() then throws Session "..." not found, so the stray render is left above the error. On a successful startup this premature render is overwritten by the full UI, so it only shows on failure. The footer is the only content-bearing chrome during startup (transcript/editor are still empty), which is why only it leaks.

What changed

Treat the footer as ready-state chrome: remove it from buildLayout() and mount it via mountFooter() in initMainTui() only after init() succeeds. A fatal startup error throws before mounting, so the footer never enters the render tree and the premature render paints an empty tree, leaving the error on a clean line. The migration / picker / OAuth-login / normal startup paths all still reach mountFooter(), so behavior is unchanged.

Added regression tests: footer is not mounted when a missing-session resume fails, and is mounted once startup reaches the main TUI.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

启动期间 footer 在构造时就被挂入渲染树,而 init() 早期的 setAppState
会排出一次渲染,在 await 时真正执行(pi-tui 的 stopped 默认为 false,
未 start 也会 doRender),把 footer 画到终端。resume 不存在的 session
时,init() 随后抛错,这次过早渲染就残留在错误信息上方。

将 footer 改为就绪态 chrome:从 buildLayout 移除挂载,改在 initMainTui
中 init() 成功之后再 mountFooter。致命启动错误会在挂载前抛出,footer
不进渲染树,过早渲染只画空树,错误信息落在干净的行上。
@changeset-bot

changeset-bot Bot commented May 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 24c0c36

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@liruifengv liruifengv changed the title fix(tui): 避免 resume 不存在的 session 时泄漏 footer fix(tui): avoid leaking footer when resuming a missing session May 29, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 29, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@24c0c36
npx https://pkg.pr.new/@moonshot-ai/kimi-code@24c0c36

commit: 24c0c36

@liruifengv
liruifengv merged commit 14a0348 into main May 29, 2026
6 checks passed
@liruifengv
liruifengv deleted the fix/resume-missing-session-footer-leak branch May 29, 2026 07:38
@github-actions github-actions Bot mentioned this pull request May 29, 2026
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