Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/types/TalkMessageStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class TalkMessageStream {
public async streamMessageChunk(
partialMessage: string,
endOfSpeech: boolean,
utteranceId?: string,
): Promise<void> {
if (
this.state !== TalkMessageStreamState.STREAMING &&
Expand All @@ -86,6 +87,7 @@ export class TalkMessageStream {
startOfSpeech: this.state === TalkMessageStreamState.UNSTARTED,
endOfSpeech: endOfSpeech,
correlationId: this.correlationId,
...(utteranceId ? { utteranceId } : {}),
};
this.state = endOfSpeech
? TalkMessageStreamState.ENDED
Expand Down
4 changes: 4 additions & 0 deletions src/types/signalling/TalkMessageStreamPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ export interface TalkMessageStreamPayload {
startOfSpeech: boolean;
endOfSpeech: boolean;
correlationId: string;
// Optional client-scoped utterance key. Chunks sharing a key form one utterance;
// changing it starts a new one. Omitted means "same utterance as before".
// A canonical UUIDv4 is echoed back as MessageStreamEvent.utteranceId.
utteranceId?: string;
}
26 changes: 25 additions & 1 deletion test/utteranceIdHarness.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
InternalEventEmitter,
} = require('../dist/main/modules/InternalEventEmitter');
const { AnamEvent, InternalEvent } = require('../dist/main/types');
const { TalkMessageStream } = require('../dist/main/types/TalkMessageStream');

function setup() {
const publicEmitter = new PublicEventEmitter();
Expand Down Expand Up @@ -150,14 +151,37 @@ function testHistoryShapeUnchangedWithoutUtteranceIds() {
assert.ok(!('utterances' in history[0]));
}

function testTalkStreamChunkCarriesUtteranceId() {
const sent = [];
const stream = new TalkMessageStream(
'corr-1',
new InternalEventEmitter(),
{ sendTalkMessage: async (payload) => sent.push(payload) },
);

return Promise.resolve()
.then(() => stream.streamMessageChunk('Hello', false, 'uuid-a'))
.then(() => stream.streamMessageChunk(' again', false))
.then(() => stream.streamMessageChunk(' bye', true, 'uuid-b'))
.then(() => {
assert.equal(sent[0].utteranceId, 'uuid-a');
assert.ok(!('utteranceId' in sent[1]));
assert.equal(sent[2].utteranceId, 'uuid-b');
assert.equal(sent[0].startOfSpeech, true);
assert.equal(sent[2].endOfSpeech, true);
});
}

function main() {
testUtteranceIdExposedOnStreamEvents();
testMissingOrEmptyUtteranceIdOmitted();
testHistorySplitsUtterancesKeepsTurnShape();
testHistoryPreservesNonSeparatorWhitespace();
testPublishedMessageIsNotMutatedByLaterChunks();
testHistoryShapeUnchangedWithoutUtteranceIds();
console.log('utteranceIdHarness: all tests passed');
return testTalkStreamChunkCarriesUtteranceId().then(() =>
console.log('utteranceIdHarness: all tests passed'),
);
Comment on lines +182 to +184

@cubic-dev-ai cubic-dev-ai Bot Aug 19, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Handle the promise returned by main() so assertion failures cannot be treated as unhandled rejections. Under Node's warn or none modes, the harness can otherwise finish with a successful exit status after this test rejects.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/utteranceIdHarness.js, line 182:

<comment>Handle the promise returned by `main()` so assertion failures cannot be treated as unhandled rejections. Under Node's `warn` or `none` modes, the harness can otherwise finish with a successful exit status after this test rejects.</comment>

<file context>
@@ -150,14 +151,37 @@ function testHistoryShapeUnchangedWithoutUtteranceIds() {
   testPublishedMessageIsNotMutatedByLaterChunks();
   testHistoryShapeUnchangedWithoutUtteranceIds();
-  console.log('utteranceIdHarness: all tests passed');
+  return testTalkStreamChunkCarriesUtteranceId().then(() =>
+    console.log('utteranceIdHarness: all tests passed'),
+  );
</file context>
Suggested change
return testTalkStreamChunkCarriesUtteranceId().then(() =>
console.log('utteranceIdHarness: all tests passed'),
);
return testTalkStreamChunkCarriesUtteranceId()
.then(() => console.log('utteranceIdHarness: all tests passed'))
.catch((error) => {
console.error(error);
process.exitCode = 1;
});
Fix with cubic

}

main();
Comment on lines +182 to 187