Skip to content

Commit 95330d5

Browse files
committed
🤖 fix: cancel active stream on message edit to prevent history corruption
When editing a compacting message to change parameters (e.g., token count) while the first compaction is still streaming, the old stream would continue and corrupt the chat history by replacing everything with [truncated]. Root cause: handleCompletion would find the NEW compaction request in history and proceed to perform compaction with the OLD stream's partial summary. Fix: Cancel any active stream before processing edits. This ensures only one stream runs at a time and aligns with user intent (edit = discard old). Impact: 9 lines added to agentSession.ts sendMessage method
1 parent d307930 commit 95330d5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

‎src/node/services/agentSession.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ export class AgentSession {
270270
);
271271
}
272272

273+
if (options?.editMessageId && this.aiService.isStreaming(this.workspaceId)) {
274+
const stopResult = await this.interruptStream(/* abandonPartial */ true);
275+
if (!stopResult.success) {
276+
return Err(createUnknownSendMessageError(stopResult.error));
277+
}
278+
}
279+
273280
if (options?.editMessageId) {
274281
const truncateResult = await this.historyService.truncateAfterMessage(
275282
this.workspaceId,

0 commit comments

Comments
 (0)