MoonshotAI / MoonshotAI/kimi-code

perf(tui): avoid redundant rebuilds in Agent and Read groups

Open
#1,511 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

What version of Kimi Code is running?

0.23.3 on main at b89fc1a4

Which open platform/subscription were you using?

Not applicable. This was found during AI-assisted TUI rendering code review, not from a live model session.

Which model were you using?

Not applicable.

What platform is your computer?

Darwin 25.0.0 arm64 arm

What issue are you seeing?

AgentGroupComponent and ReadGroupComponent appear to do redundant rebuild/render-request work when a grouped tool call is attached.

This was found by AI-assisted code review / perf audit rather than by a visible UI regression. I do not have evidence of terminal flicker or user-visible lag, because TUI.requestRender() coalesces actual render scheduling when renderRequested is already set. The issue is that the grouped components still do extra component-level refresh work.

The relevant path is:

  • AgentGroupComponent.attach() calls tc.setSnapshotListener(...), and ToolCallComponent.setSnapshotListener() immediately invokes the callback.
  • That callback enters scheduleRender() / flushRender().
  • attach() then calls flushRender() again directly.
  • flushRender() calls this.invalidate().
  • The overridden invalidate() calls this.flushRender() again.

The same pattern exists in ReadGroupComponent.

What steps can reproduce the bug?

From the repo root, run this instrumentation repro for AgentGroupComponent:

pnpm exec tsx --tsconfig ./apps/kimi-code/tsconfig.dev.json --import ./build/register-raw-text-loader.mjs -e "import { AgentGroupComponent } from './apps/kimi-code/src/tui/components/messages/agent-group.ts'; import { ToolCallComponent } from './apps/kimi-code/src/tui/components/messages/tool-call.ts'; let renders = 0; const ui = { terminal: { rows: 40 }, requestRender() { renders += 1; } }; const group = new AgentGroupComponent(ui); const tc = new ToolCallComponent({ id: 'call_agent_1', name: 'Agent', args: { description: 'inspect project' } }, undefined, ui); tc.onSubagentSpawned({ agentId: 'sub_call_agent_1', agentName: 'reviewer', runInBackground: false }); renders = 0; group.attach('call_agent_1', tc); console.log(JSON.stringify({ rendersAfterAttach: renders })); group.dispose(); tc.dispose();"

Actual output:

{"rendersAfterAttach":4}

The same repro shape for ReadGroupComponent also reports 4 render requests after a single attach().

What is the expected behavior?

A single group attach/status refresh should rebuild the grouped component once and issue at most one render request from the component-level refresh path.

Actual terminal rendering may still be coalesced by TUI.requestRender(), but the grouped component should avoid the redundant flushRender -> invalidate -> flushRender path and the immediate listener callback plus explicit attach flush duplication.

Additional information

This is a low-severity performance/cleanup issue, not a confirmed user-visible rendering bug.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with apps/kimi-code/src/tui/components/messages/agent-group.ts and tool-call.ts, then trace the matching ReadGroupComponent path and run the instrumentation repro from the issue. Compare attach-time render requests with the expected single group refresh, and confirm both grouped components avoid duplicate flush/invalidate work.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.