Skip to content

Translate PWD for WSL-launched Windows agents - #7111

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
Imagineer99:fix/start-agent-wsl-shim-pwd
Jul 20, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
Imagineer99:fix/start-agent-wsl-shim-pwd

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Summary

  • pass PWD through the existing WSLENV /p bridge when launching Windows npm shims from WSL
  • keep this scoped to the WSL Windows-executable path, separate from native POSIX agent launch behavior
  • add regression coverage for a WSL-launched Windows shim with stale inherited PWD

Why

If an agent was installed on Windows first, WSL may resolve the Windows npm shim under /mnt/c. In that case the wrapper already uses WSLENV to translate path-valued environment variables for the Windows child process. PWD should follow the same path: otherwise a stale inherited Linux PWD can affect project-root discovery in the Windows-launched agent.

Verification

  • /home/samle/dev/unsloth_main/unsloth-fix-start-agent-harness-pwd/.venv/bin/python -m pytest unsloth_cli/tests/test_start.py -q
    • 189 passed, 3 skipped

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

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.

Code Review

This pull request updates the WSL command launching logic to inject the current working directory (PWD) into the environment when WSL environment bridging is active, and updates the corresponding tests to verify this behavior. The reviewer suggested optimizing this change by directly appending "PWD/p" to wsl_env_bridge instead of redundantly re-running _wsl_bridge_names, and recommended moving this logic earlier to ensure consistency with the --no-launch execution path.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread unsloth_cli/commands/start.py Outdated
Comment on lines +1064 to +1066
if wsl_env_bridge:
env = {**env, "PWD": os.getcwd()}
wsl_env_bridge = _wsl_bridge_names(env, unset_env)

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.

medium

Re-running _wsl_bridge_names(env, unset_env) is redundant and inefficient since we already know that PWD is a path and will be translated with the /p suffix (i.e., PWD/p). We can simply append "PWD/p" to the existing wsl_env_bridge tuple, which avoids iterating over the entire environment dictionary again.

Additionally, please note that the --no-launch path in _run (which prints the environment for copy-pasting) currently does not update env with PWD or bridge it. To ensure consistency between the direct launch and --no-launch copy-paste behaviors, you might want to apply this PWD injection logic in _run before the if not launch: check so both paths benefit from it.

Suggested change
if wsl_env_bridge:
env = {**env, "PWD": os.getcwd()}
wsl_env_bridge = _wsl_bridge_names(env, unset_env)
if wsl_env_bridge:
env = {**env, "PWD": os.getcwd()}
wsl_env_bridge = (*wsl_env_bridge, "PWD/p")

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.

Addressed in c725796. _wsl_shim_env now computes the bridge once and is called only on the no-launch path, and the PWD override is applied on the launch path in _launch, so the redundant second computation is gone and the printed recipe is no longer frozen to the generation-time directory.

When a Windows npm shim is launched from WSL, route PWD through the existing WSLENV /p bridge so the Windows child process receives the cwd used by the wrapper instead of a stale inherited Linux PWD.

Apply the same environment preparation to both direct launches and --no-launch copy-paste recipes, so printed commands behave like launched sessions.

Add regression coverage for a WSL-launched Windows shim with a deliberately stale inherited PWD.
@Imagineer99
Imagineer99 force-pushed the fix/start-agent-wsl-shim-pwd branch from 86230fe to f454f18 Compare July 13, 2026 21:04
@Imagineer99
Imagineer99 marked this pull request as ready for review July 15, 2026 11:55

@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: 15d85a4553

ℹ️ 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".

Comment thread unsloth_cli/commands/start.py Outdated
click.clear()
typer.echo(f"Studio {base} · model {entry['id']}")
wsl_env_bridge = _wsl_bridge_names(env, unset_env) if _wsl_windows_executable(command) else ()
env, wsl_env_bridge = _wsl_shim_env(command, env, unset_env)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Don't freeze PWD in no-launch recipes

When --no-launch is used in WSL with a Windows shim, this call now injects a literal PWD=os.getcwd() before the print branch, and _print_env emits it as both an export and an inline assignment. If the printed recipe is run later from a different repository or by a driver that changes directories, the Windows agent gets a translated PWD for the old generation directory while its actual cwd is the new directory, so project-root discovery can target the wrong tree. The launch path needs the Python process cwd override, but the no-launch recipe should leave PWD to the shell at execution time while still adding PWD/p to WSLENV.

Useful? React with 👍 / 👎.

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.

Fixed in c725796. The no-launch recipe now only adds PWD/p to WSLENV and no longer emits a literal export PWD, so it translates the shell's live PWD at execution time; the concrete cwd override stays on the direct-launch path in _launch.

Only add PWD/p to WSLENV in the no-launch path so the printed recipe
translates the shell's live PWD when it is run, instead of pinning the
generation-time directory. Apply the concrete cwd override only for a
direct launch, which also removes the redundant second bridge computation.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: c725796050

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 03bd398fdc

ℹ️ 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".

Resolve the _run echo conflict: keep main's Unsloth rename and drop the
unconditional WSL bridge line, which now lives in the no-launch branch.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 1f9b57de60

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 63ca58a2eb

ℹ️ 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".

@danielhanchen danielhanchen left a comment

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.

Reviewed: bridges PWD via WSLENV for WSL-launched Windows shims without freezing it in no-launch recipes; concrete cwd override only on direct launch.

@danielhanchen
danielhanchen merged commit 39497e6 into unslothai:main Jul 20, 2026
44 checks passed
VectorCipher pushed a commit to VectorCipher/unsloth that referenced this pull request Jul 20, 2026
Bridge PWD through WSLENV /p when launching a Windows npm shim from WSL so project-root discovery uses the live cwd. The no-launch recipe adds PWD/p without freezing PWD; the concrete cwd override applies only on direct launch.
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.

2 participants