hermes-agent/tools/environments
kyssta-exe a54be30b6e fix(terminal): atomic env-snapshot replacement to prevent PATH corruption (#38249)
Concurrent terminal calls in one session both source AND rewrite the shared
env snapshot. The per-command re-dump used `export -p > snap` — a non-atomic
truncate-then-write in place (the code even noted "last-writer-wins"). A
concurrent `source snap` could read a half-written file and embed literal
`declare -x` / `export` fragments into PATH, breaking `ls`/`git`/`tr` with
command-not-found until PATH was manually repaired. The corruption persisted
because the malformed env got saved back into the snapshot.

Write to a unique temp file then `mv -f` over the snapshot. `mv`/rename is
atomic on POSIX (same filesystem), so a reader always sees the old-complete or
new-complete file — never a torn one. Applied at both the init_session
bootstrap and the per-command re-dump. `$$` (bash PID) makes the temp name
unique per concurrent process so their temp writes can't collide before the mv.

Salvaged from #38279 by @kyssta-exe (authorship preserved via cherry-pick).
On top of the original I hardened the temp-path quoting: the static path is now
shlex-quoted with `$$` left outside the quotes to expand, so a snapshot path
with a space or a Windows `C:/Users/...` drive letter doesn't break the shell
(matching the existing quoting care for the snapshot path itself; `bash -n`
verified on a spaced path). Added a regression test class (atomic temp+mv used,
not in-place write; per-process-unique temp; static part quoted; bootstrap also
atomic). 22 tests pass, mutation-verified (reverting to the in-place write fails
the atomic tests), ruff clean.

Closes #38249. Supersedes #38267 (serialize-execution lock — heavier and
serializes the spawn-per-call concurrency this fix preserves).
2026-06-26 21:56:59 +05:30
..
__init__.py remove Vercel AI Gateway and Vercel Sandbox (#33067) 2026-05-27 00:43:32 -07:00
base.py fix(terminal): atomic env-snapshot replacement to prevent PATH corruption (#38249) 2026-06-26 21:56:59 +05:30
daytona.py fix(daytona): migrate legacy-sandbox lookup to cursor-based list() (#24587) 2026-05-12 16:31:46 -07:00
docker.py fix: prevent TUI gateway stdin EOF crash across all TUI-context subprocess calls 2026-06-08 22:46:57 -07:00
file_sync.py fix(ssh): handle WinError 1314 symlink failure with shutil.copy2 fallback 2026-06-04 18:06:21 -07:00
local.py fix(terminal): atomic env-snapshot replacement to prevent PATH corruption (#38249) 2026-06-26 21:56:59 +05:30
managed_modal.py feat(environments): unified spawn-per-call execution layer 2026-04-08 17:23:15 -07:00
modal.py fix(async): close unscheduled coroutines in all threadsafe bridges (#26584) 2026-05-15 14:00:01 -07:00
modal_utils.py fix(tools): don't compound-rewrite spawn_via_env background wrappers 2026-06-01 00:05:10 +05:30
singularity.py fix: prevent TUI gateway stdin EOF crash across all TUI-context subprocess calls 2026-06-08 22:46:57 -07:00
ssh.py fix(tui): preserve remote cwd for ssh sessions 2026-06-06 18:40:43 -07:00