From 988bd6bddbdc172fd39c42b07bbc58d229d431ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Monnom?= Date: Thu, 12 Nov 2026 14:12:54 -0800 Subject: [PATCH] console: --record keeps the report and the audio in .livekit/sessions/ --- .gitignore | 3 +++ docs/voice-session.md | 3 ++- python/livekit-agents/livekit/agents/job.py | 27 ++++++++++++------- .../smoke/test_session_regressions.py | 1 + 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 76a1d90f89..94ed0e33bc 100644 --- a/.gitignore +++ b/.gitignore @@ -183,3 +183,6 @@ examples/dev/* # Generated from installed external SDK schemas for strict type checking. .type_stubs/ target-*/ + +# `lk agent console --record` keeps each session here +.livekit/ diff --git a/docs/voice-session.md b/docs/voice-session.md index a9d89d142c..d74c961804 100644 --- a/docs/voice-session.md +++ b/docs/voice-session.md @@ -280,7 +280,8 @@ the job reports, and ends the job when it closes. A later session of the job records nothing, serves no remote session and does not end the job; the console's call serves the remote session either way, and `--record` records its audio. The audio recording is `audio.ogg` in the job's session directory, -the report's `audio_recording_path`. Every session of the job closes as the +the report's `audio_recording_path`. With `console --record`, the report and the +audio are kept in `.livekit/sessions//` in the working directory. Every session of the job closes as the job shuts down, with `CloseReason.JOB_SHUTDOWN`, in the shutdown's span. A session's report belongs to the job the session first started in; another diff --git a/python/livekit-agents/livekit/agents/job.py b/python/livekit-agents/livekit/agents/job.py index 09123b0ba4..af9a9b003c 100644 --- a/python/livekit-agents/livekit/agents/job.py +++ b/python/livekit-agents/livekit/agents/job.py @@ -22,6 +22,7 @@ import inspect import logging import multiprocessing as mp import os +import shutil import tempfile from collections.abc import Awaitable, Callable, Coroutine from pathlib import Path @@ -203,15 +204,19 @@ class JobContext: from .voice._session_bindings import ConsoleCall if ConsoleCall.record: - path = Path( - "console-recordings", - f"session-{datetime.datetime.now().strftime('%m-%d-%H%M%S')}", - "session_report.json", + directory = Path( + ".livekit", "sessions", datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S") ) try: - await asyncio.to_thread(_write_console_report, self.make_session_report(), path) + await asyncio.to_thread( + _keep_console_recording, + self.make_session_report(), + self.session_directory, + directory, + ) + logger.info(f"session recording saved to {directory.resolve()}") except Exception: - logger.exception("failed to save session report") + logger.exception("failed to save the session recording") async def _on_cleanup(self) -> None: await asyncio.to_thread(self._tempdir.cleanup) @@ -702,6 +707,10 @@ class JobProcess: return self._http_proxy -def _write_console_report(report: SessionReport, path: Path) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(_core.session_report_json(report)) +def _keep_console_recording(report: SessionReport, session: Path, directory: Path) -> None: + """`console --record`: the report and the call's audio outlive the job's temporary directory.""" + directory.mkdir(parents=True, exist_ok=True) + (directory / "session_report.json").write_text(_core.session_report_json(report)) + audio = session / "audio.ogg" + if audio.is_file(): + shutil.copyfile(audio, directory / "audio.ogg") diff --git a/python/tests_new/smoke/test_session_regressions.py b/python/tests_new/smoke/test_session_regressions.py index f522ff3cb0..ad3d477f0f 100644 --- a/python/tests_new/smoke/test_session_regressions.py +++ b/python/tests_new/smoke/test_session_regressions.py @@ -82,6 +82,7 @@ async def test_a_recorded_console_call_writes_its_audio_without_a_room( "--connect-addr", console.addr, env={**agent_env, "RECORDING": str(recording)}, + cwd=tmp_path, ) assert await console_call.wait() == 0