Skip to content

[video] Fall back to SE_NODE_CONTAINER_NAME for the per-session subfolder - #3194

Merged
VietND96 merged 1 commit into
trunkfrom
k8s-video-subfolder-container-name-fallback
Aug 5, 2026
Merged

[video] Fall back to SE_NODE_CONTAINER_NAME for the per-session subfolder#3194
VietND96 merged 1 commit into
trunkfrom
k8s-video-subfolder-container-name-fallback

Conversation

@VietND96

@VietND96 VietND96 commented Aug 5, 2026

Copy link
Copy Markdown
Member

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 uses SE_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_NAME is 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_NAME via the downward API) guarantees a unique folder even if a session id is ever missing.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

🤖 Generated with Claude Code

…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>
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Video: fall back to SE_NODE_CONTAINER_NAME for session subfolder key

🐞 Bug fix ✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Ensure per-session video subfolders remain unique when sessionId is missing/empty.
• Fall back to SE_NODE_CONTAINER_NAME on Kubernetes to prevent shared-volume filename collisions.
• Apply identical subfolder-resolution behavior to both shell and event-driven recorders.
Diagram

graph TD
  A["Node session source"] --> B["Recorder: video.sh"] --> D["Resolve subfolder key"]
  A --> C["Recorder: video_service.py"] --> D
  D --> E["sessionId"] --> G["VIDEO_FOLDER/<key>/name.mp4"]
  D --> F["SE_NODE_CONTAINER_NAME"] --> G
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Generate a random/hashed fallback key
  • ➕ Does not depend on environment wiring (works even if SE_NODE_CONTAINER_NAME is absent).
  • ➕ Guaranteed uniqueness even in pathological cases.
  • ➖ Harder to correlate recordings back to the producing Pod/Node for debugging.
  • ➖ Can break expectations where consumers rely on stable/identifiable subfolder names.
2. Fail closed when sessionId is missing (don’t record)
  • ➕ Avoids producing ambiguous output paths.
  • ➖ Drops recordings in exactly the scenarios where reliability is needed most.
  • ➖ Doesn’t address shared-volume collision risk; it just avoids output.

Recommendation: Keep the PR’s approach: use sessionId when present and fall back to SE_NODE_CONTAINER_NAME. It preserves the intended per-session folder structure, prevents shared-volume collisions on Kubernetes, and leverages an already-documented/standard Node identity signal without introducing opaque or unstable directory names.

Files changed (2) +22 / -7

Enhancement (1) +9 / -4
video_service.pyUse container/pod name fallback for event-driven per-session subfolders +9/-4

Use container/pod name fallback for event-driven per-session subfolders

• When session subfoldering is enabled, prefixes the video output path using session_id or (if empty) SE_NODE_CONTAINER_NAME. Creates the resolved subfolder and logs its creation, ensuring unique paths on Kubernetes shared volumes.

Video/video_service.py

Bug fix (1) +13 / -3
video.shFallback to SE_NODE_CONTAINER_NAME for per-session subfolder creation +13/-3

Fallback to SE_NODE_CONTAINER_NAME for per-session subfolder creation

• When SE_VIDEO_SESSION_SUBFOLDER=true, derives a subfolder key from session_id and falls back to SE_NODE_CONTAINER_NAME when session_id is empty or "null". If neither is available, it records directly under VIDEO_FOLDER as before.

Video/video.sh

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Python fallback unreachable 🐞 Bug ≡ Correctness
Description
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).
Code

Video/video_service.py[R774-778]

+            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}"
Evidence
The session-created handler exits before the new fallback assignment when sessionId is falsy, which
prevents the fallback from ever being chosen for empty/missing ids. The file also demonstrates that
the system expects sentinel "null" strings in event/capability payloads, but the new fallback logic
does not normalize sessionId accordingly, so it will still use "null" rather than the container
name.

Video/video_service.py[755-760]
Video/video_service.py[770-779]
Video/video_service.py[296-303]
Video/video_service.py[806-812]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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



Informational

2. Shell fallback unreachable 🐞 Bug ⚙ Maintainability
Description
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.
Code

Video/video.sh[R278-283]

+          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}"
Evidence
The loop only starts recording when session_id is neither "null" nor empty. Inside that same block,
the new code checks whether the derived key is empty/"null" to decide whether to fall back to
SE_NODE_CONTAINER_NAME, but that condition cannot occur given the earlier guard.

Video/video.sh[265-267]
Video/video.sh[275-289]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

Comment thread Video/video_service.py
Comment on lines +774 to +778
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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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

Comment thread Video/video.sh
Comment on lines +278 to +283
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}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Informational

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

@VietND96
VietND96 merged commit e80c78c into trunk Aug 5, 2026
85 of 91 checks passed
@VietND96
VietND96 deleted the k8s-video-subfolder-container-name-fallback branch August 5, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant