Skip to content

fix: create workspace directory at startup and default execution dir to workspace#274

Open
sicaario wants to merge 3 commits intovolcano-sh:mainfrom
sicaario:fix/workspace-dir-creation
Open

fix: create workspace directory at startup and default execution dir to workspace#274
sicaario wants to merge 3 commits intovolcano-sh:mainfrom
sicaario:fix/workspace-dir-creation

Conversation

@sicaario
Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

When picod is started with --workspace set to a directory other than /root (e.g. --workspace=/workspace), two problems occur:

  1. The workspace directory is never created — setWorkspace only resolves the path but never calls os.MkdirAll, so if the directory doesn't exist the container starts but all file and execution operations fail immediately.

  2. When a client sends an execute request without an explicit working_dir, the command runs in the picod process's current working directory instead of the configured workspace, causing unexpected behavior depending on how the container is launched.

Changes:

  • setWorkspace (files.go) now calls os.MkdirAll to create the workspace directory (including any parent directories) if it does not already exist, and returns an error on failure
  • NewServer (server.go) handles the error from setWorkspace and calls klog.Fatalf if workspace initialization fails
  • ExecuteHandler (execute.go) defaults cmd.Dir to s.workspaceDir when no working_dir is provided in the request; also auto-creates the requested subdirectory with os.MkdirAll so users do not need to pre-create subdirectories before executing inside them

Which issue(s) this PR fixes:
Fixes #154

Special notes for your reviewer:

The TestSanitizePath failure visible in local macOS runs is a pre-existing issue (present on main before this PR) caused by macOS /tmp/private/tmp symlink resolution. It does not affect Linux CI and is unrelated to these changes.

Does this PR introduce a user-facing change?:

Fixed picod failing to execute code when `--workspace` is set to a directory other than `/root`. The workspace directory is now created automatically at startup, and commands default to running inside the workspace when no working directory is specified in the request.

Copilot AI review requested due to automatic review settings April 13, 2026 21:43
@volcano-sh-bot volcano-sh-bot added the kind/bug Something isn't working label Apr 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes PicoD workspace initialization and execution defaults so containers started with a non-/root --workspace behave correctly and consistently.

Changes:

  • Ensure the configured workspace directory is created at server startup and fail fast if initialization fails.
  • Default command execution working directory to the workspace when working_dir is omitted; auto-create requested subdirectories.
  • Improve Router upstream URL construction by validating/parsing sandbox endpoints and distinguishing “no entrypoint” from invalid endpoint configuration.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/router/handlers.go Make upstream URL building return/propagate parse errors; refine error handling for missing entrypoints vs invalid endpoint URLs.
pkg/picod/server.go Handle setWorkspace errors and ensure workspace is initialized before serving.
pkg/picod/files.go Change setWorkspace to return an error and create the workspace directory via os.MkdirAll.
pkg/picod/execute.go Default execution directory to workspace; create working_dir if provided.
pkg/picod/server_test.go Add coverage that non-existent workspace paths are created during NewServer.
pkg/picod/execute_test.go Add coverage for defaulting execution to workspace and auto-creating subdirectories.

Comment thread pkg/picod/files.go
Comment thread pkg/picod/execute.go
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements automatic directory creation for workspaces and execution working directories, and refactors URL construction in the router to improve error handling. Feedback was provided regarding potential resource exhaustion and performance overhead caused by calling os.MkdirAll on every execution request.

Comment thread pkg/picod/execute.go Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 13, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 72.50000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.66%. Comparing base (845b798) to head (4eaa2d2).
⚠️ Report is 164 commits behind head on main.

Files with missing lines Patch % Lines
pkg/picod/files.go 66.66% 5 Missing and 4 partials ⚠️
pkg/picod/server.go 60.00% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #274      +/-   ##
==========================================
+ Coverage   35.60%   43.66%   +8.05%     
==========================================
  Files          29       30       +1     
  Lines        2533     2638     +105     
==========================================
+ Hits          902     1152     +250     
+ Misses       1505     1359     -146     
- Partials      126      127       +1     
Flag Coverage Δ
unittests 43.66% <72.50%> (+8.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…kspace

Signed-off-by: sicaario <hrmnp8@gmail.com>
…rrors in tests

Signed-off-by: sicaario <hrmnp8@gmail.com>
Copilot AI review requested due to automatic review settings April 13, 2026 22:08
@sicaario sicaario force-pushed the fix/workspace-dir-creation branch from 52629d3 to 184469b Compare April 13, 2026 22:08
@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign acsoto for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread pkg/picod/files.go
Comment on lines 428 to 437
@@ -397,6 +435,11 @@ func (s *Server) setWorkspace(dir string) {
s.workspaceDir = absDir
klog.Infof("Resolved workspace to absolute path: %q", s.workspaceDir)
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

setWorkspace now returns an error, but if filepath.Abs(dir) fails it only logs a warning and falls back to using the provided (potentially relative) path. This can lead to creating the workspace relative to the process CWD and can break the workspace-jail assumptions in sanitizePath/mkdirSafe. Consider returning the Abs error instead of continuing with a fallback path.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a problem
This should return the Abs error instead of continuing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@acsoto fixed

Comment thread pkg/picod/files.go
Comment on lines 428 to 437
@@ -397,6 +435,11 @@ func (s *Server) setWorkspace(dir string) {
s.workspaceDir = absDir
klog.Infof("Resolved workspace to absolute path: %q", s.workspaceDir)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is a problem
This should return the Abs error instead of continuing.

… exists

Signed-off-by: sicaario <hrmnp8@gmail.com>
@hzxuzhonghu hzxuzhonghu requested a review from acsoto April 16, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Code Execution Fails When Workspace is Not Set to /root

5 participants