Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/__tests__/query-loop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@ describe('runQueryLoop', () => {
});

expect(userMsgEvents[0].seq).toEqual(expect.any(Number));

// Must NOT be sent to WS — the live client already rendered it
// optimistically via USER_SEND; emitting would cause a duplicate bubble.
const wsMsgs = ws.sent.filter((m) => m.type === 'user_message');
expect(wsMsgs).toHaveLength(0);
});

it('persists follow-up user_message from sendToChat in the event store', async () => {
Expand Down
10 changes: 7 additions & 3 deletions server/query-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,14 @@ export async function runQueryLoop(
cwd: currentSession.cwd,
mode: currentSession.mode,
});
// Persist the initial user prompt now that we have a sessionId
// Persist the initial user prompt now that we have a sessionId.
// Store only — do NOT emit to WS. The live client already rendered
// this message optimistically via USER_SEND; emitting it would
// cause a duplicate bubble (mismatched messageId defeats dedup).
if (initialPrompt) {
emit(
currentWs,
store.append(
resolvedSessionId,
'user_message',
v2('user_message', {
messageId: `umsg-${Date.now()}-${userMsgCounter++}`,
text: initialPrompt,
Expand Down
Loading