Skip to content

Commit f6f2b8f

Browse files
committed
fix: persist mock stream messages to history on completion
- Call HistoryService.updateHistory when stream-end fires in mock mode - Mirrors real StreamManager behavior to persist completed messages - Prevents empty assistant entries in chat.jsonl after mock runs - Addresses Codex review comment about mock persistence Change-Id: I4f4cd7fe27355a561cd4e2193a4045424918dd1e Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 257b36e commit f6f2b8f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/services/mock/mockScenarioPlayer.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ export class MockScenarioPlayer {
125125

126126
for (const event of turn.assistant.events) {
127127
const timer = setTimeout(() => {
128-
this.dispatchEvent(workspaceId, event, turn.assistant.messageId, historySequence);
128+
void this.dispatchEvent(workspaceId, event, turn.assistant.messageId, historySequence);
129129
}, event.delay);
130130
timers.push(timer);
131131
}
132132
}
133133

134-
private dispatchEvent(
134+
private async dispatchEvent(
135135
workspaceId: string,
136136
event: MockAssistantEvent,
137137
messageId: string,
138138
historySequence: number
139-
): void {
139+
): Promise<void> {
140140
switch (event.kind) {
141141
case "stream-start": {
142142
const payload: StreamStartEvent = {
@@ -216,6 +216,22 @@ export class MockScenarioPlayer {
216216
},
217217
parts: event.parts,
218218
};
219+
220+
// Update history with completed message (mirrors real StreamManager behavior)
221+
const updateResult = await this.deps.historyService.updateHistory(
222+
workspaceId,
223+
messageId,
224+
event.parts,
225+
{
226+
model: event.metadata.model,
227+
systemMessageTokens: event.metadata.systemMessageTokens,
228+
}
229+
);
230+
231+
if (!updateResult.success) {
232+
console.error(`Failed to update history for ${messageId}: ${updateResult.error}`);
233+
}
234+
219235
this.deps.aiService.emit("stream-end", payload);
220236
this.cleanup(workspaceId);
221237
break;

0 commit comments

Comments
 (0)