Repository navigation
perf(tui): batch and cache agent swarm progress rendering - #3777
Conversation
commit: |
ed08fd5 to
c384ef0
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c384ef0204
ℹ️ 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".
| const cached = member.cellCache; | ||
| if (cached !== undefined && cellCacheKeyEquals(cached.key, key)) return cached.value; |
There was a problem hiding this comment.
Honor the render-cache escape hatch for cell memoization
When KIMI_TUI_NO_RENDER_CACHE=1 disables caching, this path still returns member.cellCache hits and repopulates that cache unconditionally below. Consequently, the documented escape hatch in tui/utils/render-cache.ts cannot produce an uncached Agent Swarm render, which also invalidates cached-versus-uncached benchmarks and prevents users from bypassing this cache while diagnosing stale rendering. Gate both the cell-cache lookup and write on isRenderCacheEnabled().
Useful? React with 👍 / 👎.
🦋 Changeset detectedLatest commit: 81cc139 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0234ac8b1
ℹ️ 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".
| return ( | ||
| this.progressEstimator.hasPendingCatchup() || | ||
| this.members.some((member) => | ||
| member.phase === 'running' || |
There was a problem hiding this comment.
Stop frame ticks after the tool call has ended
When a successful AgentSwarm result cannot be parsed, handleAgentSwarmToolResult() calls markToolCallEnded() but ignores the false return from applyResult(), leaving previously running members in that phase. Because this new condition treats every running member as permanently animated, the interval continues requesting whole-tree renders at 12.5 fps until the component is explicitly cleared, defeating the performance fix; restrict this condition to an active tool call or transition unparsed results out of running.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| function capFinalOutputLabel(text: string): string { | ||
| return truncateToWidth(text, MAX_FINAL_OUTPUT_LABEL_CHARS, ''); |
There was a problem hiding this comment.
Enforce the retained label's character bound
When a completion or failure contains ANSI escape sequences or long zero-width graphemes, truncateToWidth() limits visible terminal columns rather than the stored string length, so a value with at most 400 display columns can still retain an arbitrarily large number of code units. This undermines the terminal-state memory bound introduced by this change; apply a storage-length cap in addition to the display-width truncation.
Useful? React with 👍 / 👎.
… label code units
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc3a7fe757
ℹ️ 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".
| const MAX_FINAL_OUTPUT_LABEL_CHARS = 400; | ||
| const MAX_FINAL_OUTPUT_LABEL_CODE_UNITS = 2_000; |
There was a problem hiding this comment.
Move the new limits into the TUI constants directory
These newly added limits are declared directly in a presentation component, contrary to the package rule that constants live in the corresponding constant directory. Move them under src/tui/constant/ and import them here so these rendering limits remain discoverable and centrally maintained.
AGENTS.md reference: apps/kimi-code/AGENTS.md:L51-L51
Useful? React with 👍 / 👎.
| const code = text.codePointAt(end - 1); | ||
| if (code >= 0xd800 && code <= 0xdbff) end -= 1; | ||
| return text.slice(0, end); |
There was a problem hiding this comment.
Avoid splitting surrogate pairs at the storage limit
When ANSI or zero-width content makes this cap land between an emoji's two UTF-16 code units, codePointAt(end - 1) returns the combined scalar value rather than the high-surrogate value, so this condition does not decrement end. The resulting slice() retains a lone high surrogate and can render a replacement character in the final status label; inspect the individual code unit with charCodeAt(end - 1) instead.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e62c436ceb
ℹ️ 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".
| // off so the retained label never ends in an unpaired surrogate. | ||
| const codePoint = text.codePointAt(end - 1); | ||
| if (codePoint !== undefined && codePoint > 0xffff) end -= 1; | ||
| return text.slice(0, end); |
There was a problem hiding this comment.
Close OSC hyperlinks after slicing retained labels
When a valid OSC 8 hyperlink opens before the 2,000-code-unit boundary and closes after it—for example, when its linked text contains enough zero-width combining characters to remain within the 400-column limit—capCodeUnits() retains the opener but removes the closer with this slice. The subsequent SGR styling does not close OSC hyperlinks, so later padding and agent cells on the same grid row inherit the link until the renderer's end-of-line reset; preserve an active OSC close sequence or strip OSC hyperlinks when applying the storage cap.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ 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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c9229a5c7
ℹ️ 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".
| // off so the retained label never ends in an unpaired surrogate. | ||
| const codePoint = text.codePointAt(end - 1); | ||
| if (codePoint !== undefined && codePoint > 0xffff) end -= 1; | ||
| return text.slice(0, end) + osc8CloseSuffix; |
There was a problem hiding this comment.
Reset SGR styles after slicing retained labels
When a final label contains an SGR opener such as bold before the 2,000-code-unit boundary and its reset after that boundary, this slice drops the reset while synthesizing a close only for OSC 8 hyperlinks. If the content remains within 400 display columns because it contains ANSI sequences or zero-width marks, downstream width truncation need not append its own reset, so the active SGR style leaks into padding and subsequent swarm cells. Close active SGR state or append a full reset whenever this storage cap slices the label.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e25df3b3de
ℹ️ 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".
| function membersOf(component: AgentSwarmProgressComponent): SwarmMemberInternals[] { | ||
| return (component as unknown as { members: SwarmMemberInternals[] }).members; |
There was a problem hiding this comment.
Test retention through a public seam
This helper bypasses TypeScript privacy to inspect members, and the entire terminal-memory suite consequently depends on the component's internal array and cache representation. Renaming these fields or replacing the storage strategy would break the tests even when observable rendering and retention behavior remain correct, contrary to the required TDD guidance that tests target public seams rather than internals; verify the bound through a supported diagnostic/behavioral seam instead.
AGENTS.md reference: AGENTS.md:L61-L61
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
Related Issue
No tracking issue — internal performance work.
Problem
On large AgentSwarm runs the TUI saturates a core (~100% CPU) and each round renders slower than the last: 130s → 513s per round for identical work. CPU profile of the main thread shows ~94% of time in rendering:
requestRender(), so the whole tree re-renders at ~60fps;truncateToWidth33.7%,extractAnsiCode18%,collapseWhitespace11.2%) for every swarm component in the transcript — including long-finished ones, which have no cache;What changed
requestRender()in the swarm branch; the component's 80ms frame timer (kept alive while members run) batches updates at ~12.5fps. Lifecycle events still render immediately.findMemberByAgentIdis a Map lookup; dock grid-height measurement is cached per frame.completedText/failureText) and releaselatestModelText/cell cache — previously each member's full output stayed resident (≈8MB/round in the load test).Load test after the fix: round times flat at ~127s (was 130→513s), process ~68% idle (was ~100% CPU), render share ~14% (was ~94%).
Checklist
gen-changesetsskill (.changeset/fix-swarm-rendering-slowdown.md, patch).gen-docsskill, or this PR needs no doc update (no user-facing doc change).