@livekit/agents 1.0.49 → 1.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livekit/agents",
3
- "version": "1.0.49",
3
+ "version": "1.0.50",
4
4
  "description": "LiveKit Agents - Node.js",
5
5
  "main": "dist/index.js",
6
6
  "require": "dist/index.cjs",
@@ -16,11 +16,22 @@ import type { IPCMessage } from './message.js';
16
16
  const ORPHANED_TIMEOUT = 15 * 1000;
17
17
 
18
18
  const safeSend = (msg: IPCMessage): boolean => {
19
- if (process.connected && process.send) {
20
- process.send(msg);
21
- return true;
19
+ try {
20
+ if (process.connected && process.send) {
21
+ process.send(msg);
22
+ return true;
23
+ }
24
+ return false;
25
+ } catch (error) {
26
+ // Channel closed is expected during graceful shutdown
27
+ // Log at debug level to avoid noise in production logs
28
+ if (error instanceof Error && error.message.includes('Channel closed')) {
29
+ log().debug({ msgCase: msg.case }, 'IPC channel closed, message not sent');
30
+ } else {
31
+ log().error({ error, msgCase: msg.case }, 'IPC send failed unexpectedly');
32
+ }
33
+ return false;
22
34
  }
23
- return false;
24
35
  };
25
36
 
26
37
  type JobTask = {
@@ -1040,6 +1040,16 @@ export class AgentActivity implements RecognitionHooks {
1040
1040
  throw new Error('Speech queue is empty');
1041
1041
  }
1042
1042
  const speechHandle = heapItem[2];
1043
+
1044
+ // Skip speech handles that were already interrupted/done before being
1045
+ // picked up from the queue (e.g. interrupted during shutdown before the
1046
+ // main loop had a chance to process them). Calling _authorizeGeneration
1047
+ // on a done handle would create a generation Future that nobody resolves,
1048
+ // causing the main loop to hang forever.
1049
+ if (speechHandle.interrupted || speechHandle.done()) {
1050
+ continue;
1051
+ }
1052
+
1043
1053
  this._currentSpeech = speechHandle;
1044
1054
  speechHandle._authorizeGeneration();
1045
1055
  await speechHandle._waitForGeneration();