Skip to content

fix(terminal): WSL path conversion breaks every terminal command (exit 126) - #53475

Closed
Icather wants to merge 3 commits into
NousResearch:mainfrom
Icather:fix/terminal-wsl-snapshot-path
Closed

Icather wants to merge 3 commits into
NousResearch:mainfrom
Icather:fix/terminal-wsl-snapshot-path

Conversation

@Icather

@Icather Icather commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes _windows_to_msys_path() to generate WSL-compatible /mnt/drive/... paths on Windows hosts. Currently it produces Git Bash-style /c/... paths which WSL cannot resolve — causing every terminal command to immediately fail with exit 126 on all Windows installations.

Impact

The terminal is the primary code execution and system interaction surface for Hermes. With this bug, every command aborts before execution: builtin cd always fails against the WSL-invalid path → || exit 126 → the actual command never runs. Users get zero usable terminal output. All Windows installations are affected because Hermes terminal on Windows always runs inside WSL.

Two cascading failures:

  1. Snapshot files: source D:/... (unquoted Windows path) fails silently in WSL. After the quoting fix in the first commit, the path became /d/... — also unrecognised by WSL. Session snapshots never load, forcing fallback to bash -l per-command.
  2. CWD resolution: _windows_to_msys_path("D:\hermes_data\.hermes")/d/hermes_data/.hermes. WSL mounts drives at /mnt/d/, not /d/. Every terminal execution hits builtin cd /d/... || exit 126 and aborts.

Root Cause

_windows_to_msys_path() hardcodes the Git Bash/MSYS2 mount convention (/{drive}/...) which differs from WSL's mount convention (/mnt/{drive}/...). On Windows, Hermes' terminal tool always runs inside WSL, so the Git Bash convention is never correct.

Fix

Detect WSL availability via shutil.which("wsl.exe") and generate /mnt/{drive}/... when WSL is present. Fall back to /{drive}/... for non-WSL environments. Two files changed (the function and its mirror copy).

Related Issue

Observable on every Windows Hermes installation since the path conversion was introduced.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (existing functionality changes)
  • 📚 Documentation
  • 🧪 Tests
  • 🔧 Configuration / CI / tooling

Checklist

  • I have tested these changes locally
  • _windows_to_msys_path("D:\hermes_data\.hermes") now returns /mnt/d/hermes_data/.hermes on WSL hosts
  • No new dependencies
  • Backward compatible — non-WSL paths unchanged

Icather added 2 commits June 27, 2026 04:26
…bility

The snapshot_path and cwd_file were left as Windows native paths
(D:/hermes_data/...) when written into bash scripts that execute in
WSL. WSL bash cannot access D:/... — it needs /mnt/d/...

Fix: apply _windows_to_msys_path() to snapshot_path and cwd_file
before quoting, matching the existing treatment of CWD in init_session().
On Windows, Hermes terminal runs inside WSL where drives are at
/mnt/c, /mnt/d, etc. _windows_to_msys_path was producing /c, /d
format which works in Git Bash but fails in WSL — causing exit 126
on every cd attempt.

Detect WSL via shutil.which('wsl.exe') and generate /mnt/{drive}/...
paths when running on a WSL-capable host.
@alt-glitch alt-glitch added type/bug Something isn't working backend/local Local shell execution tool/terminal Terminal execution and process management platform/windows Native Windows-specific behavior or breakage P2 Medium — degraded but workaround exists sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows labels Jun 27, 2026

@tonydwb tonydwb 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.

Code Review Summary

Verdict: Comment — Stale artifact file must be removed before merge.

The actual fix in tools/environments/base.py (35 additions, 7 deletions) is well-motivated and correctly detects WSL via shutil.which("wsl.exe") to generate /mnt/{drive}/... paths instead of Git Bash-style /{drive}/... paths.

Issue: The PR includes tools_environments_base.py (926 additions) at the repo root — this appears to be a stale copy/artifact of the entire tools/environments/base.py file. It should not be committed. Please remove it before merge.

Warnings

  • tools_environments_base.py — 926-line stale file at repo root. Must be removed.

Looks Good

  • WSL detection via shutil.which("wsl.exe") is the right approach
  • Backward compatible (non-WSL paths unchanged)
  • builtin cd -- with -- prevents hyphen-prefixed dir names from being parsed as options

Reviewed by Hermes Agent

@Icather Icather left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, removed the stale file — was accidentally included when syncing from the production deployment. Only tools/environments/base.py remains now.

@teknium1

teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Closing in favor of PR #56384. This PR's premise — that Hermes terminal on Windows "always runs inside WSL" — doesn't hold against _find_bash(), which is built to resolve Git for Windows bash (its error even says "requires Git for Windows"). The real issue was a resolution-order bug: shutil.which("bash") ran before the Git-for-Windows path check, so the WSL shim won on machines that had it (#47837). #56384 fixes that ordering, making Git Bash canonical and /c/ always correct — so a hardcoded /mnt/c/ conversion isn't the right direction. Appreciate the investigation into the WSL failure mode; it helped confirm the root cause.
#56384

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend/local Local shell execution P2 Medium — degraded but workaround exists platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows tool/terminal Terminal execution and process management type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants