Skip to content

fix(sandboxes): forward working_dir to the background-job launcher exec - #892

Open
atirna wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
atirna:fix/background-job-launcher-working-dir
Open

fix(sandboxes): forward working_dir to the background-job launcher exec#892
atirna wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
atirna:fix/background-job-launcher-working-dir

Conversation

@atirna

@atirna atirna commented Sep 3, 2026

Copy link
Copy Markdown

Description

start_background_job() accepts a working_dir but only used it as a cd prefix inside the eventual background command. The internal launcher exec (the nohup submission) called execute_command() without forwarding working_dir, so the gateway launched from the image's default cwd. When that directory no longer exists (e.g. a VM image whose /app was removed/replaced), the launch itself fails with cwd '/app' does not exist before the requested cd can ever run.

This forwards working_dir to the internal launcher execute_command() call in both the sync and async implementations. Foreground execute_command() already accepts and honors working_dir on both transports (Connect-RPC command_spec.cwd, REST payload), so the launcher now starts in the requested directory too.

Fixes #890

Why

Any consumer that removes or replaces the image-default working directory and then starts a background job with an explicit working_dir currently gets a hard launch failure even though the requested directory exists. The working_dir parameter was effectively dead for the launch step.

Verification

  • before, on current main: uv run pytest tests/test_background_job_working_dir.py in packages/prime-sandboxes: both tests fail, launcher execute_command receives no working_dir kwarg (matches the issue's reproduction: launch from missing image-default cwd)
  • after: same command, 2 passed; launcher exec carries working_dir='/' and defaults to None when unset, on both SandboxClient and AsyncSandboxClient
  • uv run pytest tests/test_background_job_working_dir.py tests/test_background_job_launch_retry.py tests/test_background_job_timeout.py tests/test_command_transport_selection.py tests/test_batch_status.py tests/test_client_retry.py tests/test_gateway_error_mapping.py: 123 passed (hermetic unit tests; the live-API suites in this package need PRIME_API_KEY/PRIME_TEAM_ID and were not run)

start_background_job accepted working_dir but only used it as a cd prefix
inside the eventual background command; the internal nohup launcher exec
called execute_command without it, so the launch itself ran from the
image-default cwd and failed when that directory no longer exists.

Forward working_dir to the launcher execute_command call in both the sync
and async implementations.

Fixes PrimeIntellect-ai#890
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-03T04:45:55.520984Z f4e2f51 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4e2f51461

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

sandbox_id,
bg_cmd,
timeout=_BACKGROUND_JOB_LAUNCH_TIMEOUT_SECONDS,
working_dir=working_dir,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid applying relative working directories twice

When working_dir is relative, forwarding it here starts the launcher in that directory, but the generated background command still executes cd <working_dir> before the user command. For example, with the image cwd /app and working_dir="tasks", the launcher starts in /app/tasks and then tries to enter /app/tasks/tasks, causing the job to fail before running the requested command. The async implementation has the same issue; apply the working directory only once or normalize it before using both mechanisms.

Useful? React with 👍 / 👎.

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.

[prime-sandboxes] start_background_job ignores working_dir for its launcher

1 participant