perf: yield between replayed history messages

A session/load of a long history sent every update from one macrotask when
the client read fast enough, starving other sessions and incoming requests.
The replay now shares the consumer's 8 ms budget and yields between
messages. The updates and their order are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nikita Ashikhmin
2026-10-07 23:02:24 +04:00
parent b26586b385
commit 738ddea06f

View File

@@ -7992,6 +7992,10 @@ export class ClaudeAcpAgent {
};
const replayMessage = async (message: SessionMessage): Promise<void> => {
// A long history is sent in order, but with event-loop turns in between,
// so other sessions and incoming requests are not starved meanwhile.
const pause = messageLoopYielder.maybeYield();
if (pause) await pause;
if (pending?.stopped || isReplayHiddenMetaMessage(message)) {
return;
}