Skip to content

Commit 257b36e

Browse files
committed
fix: emit abort event and cancel existing mock streams
- Emit stream-abort event when stopping mock streams to mirror real streaming behavior - Cancel any existing stream before starting a new one to prevent timer corruption - Addresses Codex review comments about mock stream lifecycle management Change-Id: I0a95493aa15dc0eda71a5c31b09b3844eeaf8187 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 3825a2a commit 257b36e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/services/mock/mockScenarioPlayer.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,20 @@ export class MockScenarioPlayer {
4040
stop(workspaceId: string): void {
4141
const active = this.activeStreams.get(workspaceId);
4242
if (!active) return;
43+
44+
// Clear all pending timers
4345
for (const timer of active.timers) {
4446
clearTimeout(timer);
4547
}
48+
49+
// Emit stream-abort event to mirror real streaming behavior
50+
this.deps.aiService.emit("stream-abort", {
51+
type: "stream-abort",
52+
workspaceId,
53+
messageId: active.messageId,
54+
reason: "user_cancelled",
55+
});
56+
4657
this.activeStreams.delete(workspaceId);
4758
}
4859

@@ -91,6 +102,11 @@ export class MockScenarioPlayer {
91102
}
92103
historySequence = assistantMessage.metadata?.historySequence ?? historySequence;
93104

105+
// Cancel any existing stream before starting a new one
106+
if (this.isStreaming(workspaceId)) {
107+
this.stop(workspaceId);
108+
}
109+
94110
this.scheduleEvents(workspaceId, turn, historySequence);
95111
this.turnIndex += 1;
96112
return Ok(undefined);

0 commit comments

Comments
 (0)