fix(sdk): count cron turns as replay turn boundaries - #3605
Merged
RealKai42 merged 1 commit intoSep 7, 2026
Conversation
🦋 Changeset detectedLatest commit: b3d610c 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 |
commit: |
Resuming a session dominated by cron-fired turns mounted an unbounded transcript: limitAgentReplayByTurns only counted human-typed prompts as turn boundaries, so the replay limit never engaged (10,478 records for 11 'turns' on an affected session). The mounted transcript made every render frame O(total lines), starving the event loop during streaming and collapsing client-side drain throughput. Treat cron_job and cron_missed replay records as turn boundaries, matching the TUI transcript window's own boundary rule.
huangzheng2016
force-pushed
the
fix/replay-cron-turn-boundary
branch
from
September 7, 2026 07:26
7ed3350 to
b3d610c
Compare
5 tasks
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
No linked issue — reported via internal user feedback and root-caused from the affected session data.
Problem
After resuming a session whose history is dominated by cron-fired turns, response streaming collapses to 30–50 tok/s in the TUI even though the server streams at ~200 tok/s, and it reproduces on every resume of that session (a fresh session on the same machine streams at full speed).
Root cause:
limitAgentReplayByTurnsonly counted human-typed prompts as turn boundaries —cron_job/cron_missedrecords were not turns. On the affected session (4,280 cron turns vs 63 real user turns) the "last 11 turns" replay fetch therefore returned 10,478 records (~9 MB, ~45% of the whole history), all of which the TUI mounts and keeps mounted for the process lifetime. Every render frame then walks ~100k mounted transcript lines; during streaming (20 fps flush) that saturates the event loop on modest hardware, so the client cannot drain the socket and the measured server-decode window stretches (the debug split attributes this starvation to "server", which is misleading).Verified against the real session data: print mode (no TUI) streams at full speed; the mock-server drain of 4,000 tokens takes 10 ms once the transcript is bounded.
What changed
packages/node-sdk/src/replay.ts: treatcron_jobandcron_missedreplay records as turn boundaries. This mirrors the TUI transcript window's own boundary rule (CronMessageComponentis already a fold-segment boundary there). The resumed replay on the affected session drops from 10,478 to 137 records; end-to-end resume output shrinks from 31 MB to 351 KB.packages/node-sdk/test/replay.test.ts(new): bounds replay volume when cron turns dominate (failed before the fix), treatscron_missedas a boundary, verifies injection bursts do not shrink the window, and pins the existing user-turn semantics.Validation: node-sdk 138 tests, apps/kimi-code 2452 TUI tests, typecheck, oxlint — all green.
Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.