From 6b174a6451d510d1da08a7c3d054d0ce60615d8e Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Wed, 5 Aug 2026 11:44:16 +0700 Subject: [PATCH] feat(video): fall back to SE_NODE_CONTAINER_NAME for the per-session subfolder When SE_VIDEO_SESSION_SUBFOLDER=true, the recorder groups each video under its session id. If the session id is empty for any reason, fall back to SE_NODE_CONTAINER_NAME (the Node container / Pod name) as the subfolder key in both the shell (video.sh) and the event-driven (video_service.py) backends, so a recording never lands flat and collides on the shared Kubernetes assets volume. Co-Authored-By: Claude Opus 4.8 --- Video/video.sh | 16 +++++++++++++--- Video/video_service.py | 13 +++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Video/video.sh b/Video/video.sh index 5772a216f..65613760f 100755 --- a/Video/video.sh +++ b/Video/video.sh @@ -273,9 +273,19 @@ else echo "$(date -u +"${ts_format}") [${process_name}] - Start recording: $caps_se_video_record, video file name: $video_file_name" log_node_response if [[ "${SE_VIDEO_SESSION_SUBFOLDER}" = "true" ]]; then - video_dir="${VIDEO_FOLDER}/${session_id}" - mkdir -p "${video_dir}" - echo "$(date -u +"${ts_format}") [${process_name}] - Created session subfolder: ${video_dir}" + # Group each recording under its session id. If the session id is empty for any reason, + # fall back to the Node container/Pod name so the video still lands in a unique subfolder. + subfolder_key="${session_id}" + if [ -z "${subfolder_key}" ] || [ "${subfolder_key}" = "null" ]; then + subfolder_key="${SE_NODE_CONTAINER_NAME}" + fi + if [ -n "${subfolder_key}" ]; then + video_dir="${VIDEO_FOLDER}/${subfolder_key}" + mkdir -p "${video_dir}" + echo "$(date -u +"${ts_format}") [${process_name}] - Created session subfolder: ${video_dir}" + else + video_dir="${VIDEO_FOLDER}" + fi else video_dir="${VIDEO_FOLDER}" fi diff --git a/Video/video_service.py b/Video/video_service.py index 2240510bb..f99febd86 100755 --- a/Video/video_service.py +++ b/Video/video_service.py @@ -768,10 +768,15 @@ async def handle_session_created(self, data: dict) -> None: record_video, video_filename = self.get_video_filename(session_id, capabilities) if record_video and self.session_subfolder: - session_subdir = Path(self.video_folder) / session_id - session_subdir.mkdir(parents=True, exist_ok=True) - video_filename = f"{session_id}/{video_filename}" - logger.info(f"Created session subfolder: {session_subdir}") + # Group each recording under its session id. If the session id is empty for any reason, + # fall back to the Node container/Pod name so the video still lands in a unique subfolder + # (important on Kubernetes where the assets volume is shared across Pods). + subfolder_key = session_id or os.environ.get("SE_NODE_CONTAINER_NAME", "").strip() + if subfolder_key: + session_subdir = Path(self.video_folder) / subfolder_key + session_subdir.mkdir(parents=True, exist_ok=True) + video_filename = f"{subfolder_key}/{video_filename}" + logger.info(f"Created session subfolder: {session_subdir}") retain_on_failure_cap = capabilities.get("se:retainOnFailure", None) if retain_on_failure_cap is None: