Skip to content

Comments

fix: validate volume mount source paths before spawning detached process#3932

Open
stakeswky wants to merge 1 commit intostacklok:mainfrom
stakeswky:fix/2485-volume-mount-path-validation
Open

fix: validate volume mount source paths before spawning detached process#3932
stakeswky wants to merge 1 commit intostacklok:mainfrom
stakeswky:fix/2485-volume-mount-path-validation

Conversation

@stakeswky
Copy link

Summary

Fixes #2485

When running thv run --volume <source>:<target> with a non-existent source path, the command previously appeared to succeed but the workload would silently enter an error state. The actual error was only visible in the proxy log file.

Changes

pkg/runner/config_builder.go — Added pre-flight validation in processVolumeMounts():

  • Checks that source paths exist on the host filesystem using os.Stat() (follows symlinks)
  • Resolves relative paths to absolute before checking
  • Skips validation for Kubernetes operator context (paths are container-relative)
  • Skips validation for resource:// URIs
  • Returns a clear, actionable error message: volume mount source path does not exist: /path

pkg/runner/config_builder_test.go — Updated existing tests and added coverage:

  • Existing volume mount tests now use t.TempDir() for real source paths instead of hardcoded /host paths
  • Added test case for non-existent source path (expects error)

Approach

Implemented Option 1 from the issue (validate in processVolumeMounts()) because:

  1. It fails at the earliest possible point (during config building)
  2. It prevents invalid configs from being created
  3. It's context-aware (skips for K8s operator)
  4. It aligns with the existing validation pattern in config_builder.go

Before / After

Before:

$ thv run --volume /nonexistent/path:/app playwright
MCP server is running in the background (PID: 12345)
# Silently fails — error only in log file

After:

$ thv run --volume /nonexistent/path:/app playwright
Error: volume mount source path does not exist: /nonexistent/path

Add pre-flight validation in processVolumeMounts() to check that source
paths exist on the host filesystem before proceeding. This catches
invalid volume mounts early with a clear error message, instead of
silently failing in the detached process where the error is only visible
in log files.

The validation:
- Uses os.Stat() (follows symlinks) to check path existence
- Resolves relative paths to absolute before checking
- Skips validation for Kubernetes operator context (paths are
  container-relative)
- Skips validation for resource:// URIs

Fixes stacklok#2485
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Volume mount errors not reported when source path doesn't exist

1 participant