[video] Fall back to SE_NODE_CONTAINER_NAME for the per-session subfolder - #3194
Conversation
…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 <noreply@anthropic.com>
PR Summary by QodoVideo: fall back to SE_NODE_CONTAINER_NAME for session subfolder key
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Python fallback unreachable
|
| 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}" |
There was a problem hiding this comment.
1. Python fallback unreachable 🐞 Bug ≡ Correctness
In video_service.py, handle_session_created returns early when sessionId is falsy, so `subfolder_key = session_id or SE_NODE_CONTAINER_NAME` can never select the container name for empty/missing session ids. Additionally, because the code doesn’t normalize the common sentinel string "null" for sessionId, the fallback also won’t trigger for that case (it will still use "null" as the folder).
Agent Prompt
## Issue description
`handle_session_created()` aims to fall back to `SE_NODE_CONTAINER_NAME` when the session id is missing/empty, but the current control flow returns early for falsy `sessionId`, making the fallback unreachable for the primary “empty session id” case. It also does not treat the sentinel string `"null"` (used elsewhere in this file for capability fields) as missing.
## Issue Context
- `handle_session_created()` currently does `if not session_id: ... return`, so `session_id or ...` cannot ever use the env var for empty/None.
- Other parts of the service already treat `"null"` as a sentinel string (e.g., capability-derived names), so normalizing `sessionId` similarly keeps behavior consistent.
- If you decide to use a fallback-derived key for state tracking, you must apply the same normalization in `handle_session_closed()` (and any other handler indexing `self.sessions`) so stop/cleanup can find the correct entry.
## Fix Focus Areas
- Video/video_service.py[755-780]
- Video/video_service.py[806-833]
- Video/video_service.py[296-312]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| 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}" |
There was a problem hiding this comment.
2. Shell fallback unreachable 🐞 Bug ⚙ Maintainability
In video.sh, the recording block is only entered when session_id is already non-empty and not "null", so the new fallback check for empty/"null" will never be true in that code path. This makes the added fallback logic dead code and may give a false sense that empty session ids are handled.
Agent Prompt
## Issue description
The new `SE_NODE_CONTAINER_NAME` fallback logic inside the recording-start block is unreachable because the surrounding condition already guarantees `session_id` is neither empty nor `"null"`. This adds complexity without changing behavior.
## Issue Context
The outer condition checks:
- `session_id != "null"`
- `session_id != ""`
so `subfolder_key="${session_id}"` cannot be empty/"null" when the fallback `if` runs.
## Fix Focus Areas
- Video/video.sh[263-291]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Description
When
SE_VIDEO_SESSION_SUBFOLDER=true, the recorder groups each video under its session id (<video_folder>/<sessionId>/<name>.mp4). This adds a fallback: if the session id is empty for any reason, the recorder usesSE_NODE_CONTAINER_NAME(the Node container / Pod name) as the subfolder key instead. Applied to both recorder backends:Video/video.sh(shell / polling)Video/video_service.py(event-driven)If neither a session id nor
SE_NODE_CONTAINER_NAMEis available, it records flat as before.Motivation and Context
Pairs with the Grid core change in SeleniumHQ/selenium#17876, which makes the Kubernetes Dynamic Grid always use the per-session subfolder approach and removes the Node-side pod-wait + video relocation. With relocation gone, the recorder owns the final path — so it must always produce a per-session folder. On Kubernetes the assets volume is shared (ReadWriteMany) across Pods, so a flat recording would collide; falling back to the Pod name (passed by the Grid as
SE_NODE_CONTAINER_NAMEvia the downward API) guarantees a unique folder even if a session id is ever missing.Types of changes
Checklist
🤖 Generated with Claude Code