pipecat-facemode 0.2.0__tar.gz → 0.2.1__tar.gz

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.
Files changed (19) hide show
  1. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/PKG-INFO +2 -2
  2. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/README.md +1 -1
  3. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode/service.py +99 -13
  4. pipecat_facemode-0.2.1/pipecat_facemode/version.py +3 -0
  5. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode.egg-info/PKG-INFO +2 -2
  6. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pyproject.toml +1 -1
  7. pipecat_facemode-0.2.0/pipecat_facemode/version.py +0 -3
  8. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/LICENSE +0 -0
  9. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode/__init__.py +0 -0
  10. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode/exceptions.py +0 -0
  11. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode/models.py +0 -0
  12. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode.egg-info/SOURCES.txt +0 -0
  13. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode.egg-info/dependency_links.txt +0 -0
  14. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode.egg-info/requires.txt +0 -0
  15. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/pipecat_facemode.egg-info/top_level.txt +0 -0
  16. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/setup.cfg +0 -0
  17. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/test/test_contract.py +0 -0
  18. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/test/test_ingestion.py +0 -0
  19. {pipecat_facemode-0.2.0 → pipecat_facemode-0.2.1}/test/test_reconnect.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pipecat-facemode
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: FaceMode avatar integration for Pipecat
5
5
  Author: FaceMode
6
6
  License-Expression: Apache-2.0
@@ -23,7 +23,7 @@ Dynamic: license-file
23
23
 
24
24
  # pipecat-facemode
25
25
 
26
- FaceMode avatar output for Pipecat pipelines. The integration taps
26
+ [FaceMode](https://facemode.io) avatar output for Pipecat pipelines. The integration taps
27
27
  `TTSAudioRawFrame`, sends canonical 16-bit PCM to FaceMode, and converts the
28
28
  avatar's LiveKit audio and video tracks back into Pipecat output frames.
29
29
 
@@ -1,6 +1,6 @@
1
1
  # pipecat-facemode
2
2
 
3
- FaceMode avatar output for Pipecat pipelines. The integration taps
3
+ [FaceMode](https://facemode.io) avatar output for Pipecat pipelines. The integration taps
4
4
  `TTSAudioRawFrame`, sends canonical 16-bit PCM to FaceMode, and converts the
5
5
  avatar's LiveKit audio and video tracks back into Pipecat output frames.
6
6
 
@@ -66,6 +66,13 @@ _INGESTION_MAX_RETRY_SECONDS = 2.0
66
66
  _END_ACK_TIMEOUT_SECONDS = 3.0
67
67
  _WS_OPEN_TIMEOUT_SECONDS = 240.0
68
68
  _WS_CLOSE_TIMEOUT = 2.0
69
+ # Teardown must always complete: every shutdown wait is bounded so a wedged
70
+ # LiveKit stream, send lock, or room disconnect cannot stall the EndFrame path.
71
+ _SHUTDOWN_LOCK_TIMEOUT_SECONDS = 10.0
72
+ _END_SIGNAL_TIMEOUT_SECONDS = 5.0
73
+ _TASK_JOIN_TIMEOUT_SECONDS = 3.0
74
+ _STREAM_CLOSE_TIMEOUT_SECONDS = 2.0
75
+ _ROOM_DISCONNECT_TIMEOUT_SECONDS = 3.0
69
76
  _RECONNECT_MAX_ATTEMPTS = 2
70
77
  _RECONNECT_INITIAL_BACKOFF_SECONDS = 0.5
71
78
  _RECONNECT_MAX_BACKOFF_SECONDS = 2.0
@@ -273,7 +280,9 @@ class FaceModeVideoService(FrameProcessor):
273
280
  return
274
281
 
275
282
  if isinstance(frame, EndFrame):
283
+ logger.info("FaceMode teardown starting on EndFrame")
276
284
  await self._shutdown(send_end_session=True)
285
+ logger.info("FaceMode teardown complete; forwarding EndFrame")
277
286
  await self.push_frame(frame, direction)
278
287
  return
279
288
 
@@ -1214,8 +1223,29 @@ class FaceModeVideoService(FrameProcessor):
1214
1223
  task.cancel()
1215
1224
 
1216
1225
  async def _shutdown(self, *, send_end_session: bool) -> None:
1217
- async with self._lifecycle_lock:
1226
+ # Trip the bail flags before taking the lock so a startup or reconnect
1227
+ # sequence holding it exits at its next check, and bound the acquire
1228
+ # itself for the same reason.
1229
+ self._stopping = True
1230
+ self._transport_terminal = True
1231
+ self._transport_ready_event.set()
1232
+ try:
1233
+ await asyncio.wait_for(
1234
+ self._lifecycle_lock.acquire(),
1235
+ timeout=_SHUTDOWN_LOCK_TIMEOUT_SECONDS,
1236
+ )
1237
+ except asyncio.TimeoutError:
1238
+ logger.warning(
1239
+ "FaceMode shutdown: lifecycle lock held over %.1fs; "
1240
+ "tearing down without it",
1241
+ _SHUTDOWN_LOCK_TIMEOUT_SECONDS,
1242
+ )
1218
1243
  await self._shutdown_locked(send_end_session=send_end_session)
1244
+ return
1245
+ try:
1246
+ await self._shutdown_locked(send_end_session=send_end_session)
1247
+ finally:
1248
+ self._lifecycle_lock.release()
1219
1249
 
1220
1250
  async def _shutdown_locked(self, *, send_end_session: bool) -> None:
1221
1251
  """Tear down session resources; caller must hold ``_lifecycle_lock``."""
@@ -1226,12 +1256,15 @@ class FaceModeVideoService(FrameProcessor):
1226
1256
  self._transport_ready_event.set()
1227
1257
  self._accept_tracks = False
1228
1258
  self._cancel_utterance_timer()
1259
+ logger.info("FaceMode shutdown: signaling end session")
1229
1260
 
1230
1261
  websocket = self.websocket
1231
1262
  if send_end_session and websocket is not None and self._protocol_started:
1232
1263
  # wait_for raises builtin TimeoutError when the server never sends
1233
- # "ended"; it must not escape or the teardown below is skipped.
1234
- with contextlib.suppress(FaceModeError, asyncio.TimeoutError):
1264
+ # "ended"; it must not escape or the teardown below is skipped. The
1265
+ # outer bound also covers a wedged send or a send-lock holder that
1266
+ # never releases.
1267
+ async def _signal_end() -> None:
1235
1268
  if self._utterance_active:
1236
1269
  await self._send_control("end_utterance")
1237
1270
  await self._send_control("end_session")
@@ -1239,8 +1272,16 @@ class FaceModeVideoService(FrameProcessor):
1239
1272
  self._session_ended_event.wait(),
1240
1273
  timeout=_END_ACK_TIMEOUT_SECONDS,
1241
1274
  )
1275
+
1276
+ with contextlib.suppress(
1277
+ FaceModeError, asyncio.TimeoutError, asyncio.CancelledError
1278
+ ):
1279
+ await asyncio.wait_for(
1280
+ _signal_end(), timeout=_END_SIGNAL_TIMEOUT_SECONDS
1281
+ )
1242
1282
  self._utterance_active = False
1243
1283
  self._utterance_context_id = None
1284
+ logger.info("FaceMode shutdown: cancelling background tasks")
1244
1285
 
1245
1286
  current = asyncio.current_task()
1246
1287
  tasks = [
@@ -1252,27 +1293,66 @@ class FaceModeVideoService(FrameProcessor):
1252
1293
  self._receiver_task = None
1253
1294
  self._track_tasks.clear()
1254
1295
  self._track_kinds.clear()
1255
- for task in tasks:
1256
- if task is not None and task is not current and not task.done():
1296
+ pending = [
1297
+ task for task in tasks if task is not None and task is not current
1298
+ ]
1299
+ for task in pending:
1300
+ if not task.done():
1257
1301
  task.cancel()
1258
- for task in tasks:
1259
- if task is not None and task is not current:
1302
+ abandoned: set[asyncio.Task[Any]] = set()
1303
+ if pending:
1304
+ # A task blocked in a LiveKit FFI read or a wedged stream close can
1305
+ # ignore cancellation; bound the join so it cannot hold EndFrame.
1306
+ try:
1307
+ done, abandoned = await asyncio.wait(
1308
+ pending, timeout=_TASK_JOIN_TIMEOUT_SECONDS
1309
+ )
1310
+ except asyncio.CancelledError:
1311
+ done, abandoned = set(), set(pending)
1312
+ for finished in done:
1260
1313
  with contextlib.suppress(asyncio.CancelledError, Exception):
1261
- await task
1314
+ finished.exception()
1315
+ if abandoned:
1316
+ logger.warning(
1317
+ "FaceMode shutdown abandoned %s unfinished task(s) after %.1fs",
1318
+ len(abandoned),
1319
+ _TASK_JOIN_TIMEOUT_SECONDS,
1320
+ )
1262
1321
 
1322
+ logger.info("FaceMode shutdown: closing track streams")
1263
1323
  for stream in list(self._track_streams.values()):
1264
1324
  await _close_async_resource(stream)
1265
1325
  self._track_streams.clear()
1266
1326
 
1267
1327
  self.websocket = None
1268
1328
  if websocket is not None:
1269
- with contextlib.suppress(Exception):
1329
+ with contextlib.suppress(asyncio.CancelledError, Exception):
1270
1330
  await asyncio.wait_for(websocket.close(), timeout=_WS_CLOSE_TIMEOUT)
1271
1331
 
1272
1332
  room = self.room
1273
1333
  self.room = None
1334
+ logger.info("FaceMode shutdown: disconnecting room")
1274
1335
  await _disconnect_room(room)
1275
1336
 
1337
+ if abandoned:
1338
+ # Room disconnect and stream closes usually unblock tasks that were
1339
+ # stuck in LiveKit reads; give them one last short window so the
1340
+ # event loop can shut down without stragglers.
1341
+ try:
1342
+ drained, still_pending = await asyncio.wait(
1343
+ list(abandoned), timeout=_TASK_JOIN_TIMEOUT_SECONDS
1344
+ )
1345
+ except asyncio.CancelledError:
1346
+ drained, still_pending = set(), abandoned
1347
+ for finished in drained:
1348
+ with contextlib.suppress(asyncio.CancelledError, Exception):
1349
+ finished.exception()
1350
+ if still_pending:
1351
+ logger.warning(
1352
+ "FaceMode shutdown leaving %s task(s) pending after teardown",
1353
+ len(still_pending),
1354
+ )
1355
+
1276
1356
  self.session = None
1277
1357
  self._session_log_marker = None
1278
1358
  self._protocol_started = False
@@ -1381,8 +1461,12 @@ async def _disconnect_room(room: Any) -> None:
1381
1461
  except Exception:
1382
1462
  return
1383
1463
  if hasattr(result, "__await__"):
1384
- with contextlib.suppress(Exception):
1385
- await result
1464
+ # Bound the wait: rtc.Room.disconnect() is an FFI call that can stall
1465
+ # teardown if it never resolves.
1466
+ with contextlib.suppress(asyncio.CancelledError, Exception):
1467
+ await asyncio.wait_for(
1468
+ result, timeout=_ROOM_DISCONNECT_TIMEOUT_SECONDS
1469
+ )
1386
1470
 
1387
1471
 
1388
1472
  async def _close_async_resource(resource: Any) -> None:
@@ -1398,8 +1482,10 @@ async def _close_async_resource(resource: Any) -> None:
1398
1482
  except Exception:
1399
1483
  return
1400
1484
  if hasattr(result, "__await__"):
1401
- with contextlib.suppress(Exception):
1402
- await result
1485
+ with contextlib.suppress(asyncio.CancelledError, Exception):
1486
+ await asyncio.wait_for(
1487
+ result, timeout=_STREAM_CLOSE_TIMEOUT_SECONDS
1488
+ )
1403
1489
 
1404
1490
 
1405
1491
  def _frame_types(*candidates: Any) -> tuple[type, ...]:
@@ -0,0 +1,3 @@
1
+ """Package version."""
2
+
3
+ __version__ = "0.2.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pipecat-facemode
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: FaceMode avatar integration for Pipecat
5
5
  Author: FaceMode
6
6
  License-Expression: Apache-2.0
@@ -23,7 +23,7 @@ Dynamic: license-file
23
23
 
24
24
  # pipecat-facemode
25
25
 
26
- FaceMode avatar output for Pipecat pipelines. The integration taps
26
+ [FaceMode](https://facemode.io) avatar output for Pipecat pipelines. The integration taps
27
27
  `TTSAudioRawFrame`, sends canonical 16-bit PCM to FaceMode, and converts the
28
28
  avatar's LiveKit audio and video tracks back into Pipecat output frames.
29
29
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pipecat-facemode"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  license = "Apache-2.0"
9
9
  license-files = ["LICENSE"]
10
10
  authors = [{name = "FaceMode"}]
@@ -1,3 +0,0 @@
1
- """Package version."""
2
-
3
- __version__ = "0.2.0"