Skip to content

fix(tui): reclaim transcript entries when turns fold - #2603

Open
he-yufeng wants to merge 1 commit into
MoonshotAI:mainfrom
he-yufeng:fix/tui-fold-entry-reclaim
Open

fix(tui): reclaim transcript entries when turns fold#2603
he-yufeng wants to merge 1 commit into
MoonshotAI:mainfrom
he-yufeng:fix/tui-fold-entry-reclaim

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Refs #2556.

One of the two reclaim paths in that issue: both fold paths (foldCurrentTurnContent on turn completion, mergeAllTurnSteps for replayed sessions) dispose the merged components and splice the transcript child list, but the matching entries stay in state.transcriptEntries forever. Components shrink to a summary while the entry list keeps every thinking/tool/assistant record underneath, so memory keeps growing in exactly the sessions folding was meant to bound.

The Component ↔ TranscriptEntry WeakMap already exists for this mapping. Both fold paths now route their merged children through a small helper that drops the matching entries along with the components.

Scope note: this is the unambiguous half of #2556. The other half (pure ! sessions pinning every entry in the untrimmable tail turn) is a trim-policy question, deliberately left out here.

Verification

New transcript-fold-reclaim.test.ts builds a real KimiTUI against a mock harness, appends a turn with four assistant entries, folds on completion, and asserts the two folded entries are gone from transcriptEntries (the tail and the summary stay), plus the no-op case under the caps. The fold test fails without the change (entries survive the fold) and passes with it. Full apps/kimi-code TUI suite: 127 files, 1718 tests pass. oxlint/tsc clean.

foldCurrentTurnContent and mergeAllTurnSteps dispose the merged
components and splice the child list, but the matching entries stayed
in state.transcriptEntries forever, so the entry list grew underneath
the folded component tree. The Component-to-entry WeakMap already
existed for exactly this mapping; use it to drop folded entries along
with their components.

Refs MoonshotAI#2556
@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 1dee7cf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

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

commit: 1dee7cf

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1dee7cfbc9

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2516 to +2517
const entry = getTranscriptComponentEntry(component);
if (entry !== undefined) dropped.add(entry);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reclaim entries created by the streaming controller

When assistant blocks are created through the normal live or replay path, StreamingUIController.onStreamingTextStart() pushes the entry and component separately without calling markTranscriptComponent (streaming-ui.ts:593-608), so this lookup returns undefined for the assistant components being folded. Once a turn exceeds the assistant cap, the components disappear but their potentially large text entries remain in transcriptEntries; the new test misses this because it uses appendTranscriptEntry(), which does establish the mapping. Associate the entry when the streaming controller creates the component, or reclaim it through another reliable association.

AGENTS.md reference: apps/kimi-code/AGENTS.md:L38-L39

Useful? React with 👍 / 👎.

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