Skip to content

Commit d76e129

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 d76e129

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

‎src/node/services/agentSession.ts‎

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

273+
274+
273275
if (options?.editMessageId) {
276+
// Interrupt an existing stream or compaction, if active
277+
if (this.aiService.isStreaming(this.workspaceId)) {
278+
//
279+
const stopResult = await this.interruptStream(/* abandonPartial */ true);
280+
if (!stopResult.success) {
281+
return Err(createUnknownSendMessageError(stopResult.error));
282+
}
283+
}
274284
const truncateResult = await this.historyService.truncateAfterMessage(
275285
this.workspaceId,
276286
options.editMessageId

0 commit comments

Comments
 (0)