fix(terminal): guard background process spawn against deleted cwd (#19933)

Follow-up to #19928 which fixed the foreground path in _run_bash.
The background process spawn in process_registry.py had the same
vulnerability: Popen(cwd=session.cwd) and PtyProcess.spawn(cwd=...)
would raise FileNotFoundError if the directory was deleted.

Apply _resolve_safe_cwd() at session creation time so both the PTY
and pipe-mode Popen paths receive a validated cwd.
This commit is contained in:
kshitij 2026-05-04 15:35:34 -07:00 committed by GitHub
parent 9fa3a093f2
commit 109c3e468c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,7 +41,7 @@ import time
import uuid import uuid
_IS_WINDOWS = platform.system() == "Windows" _IS_WINDOWS = platform.system() == "Windows"
from tools.environments.local import _find_shell, _sanitize_subprocess_env from tools.environments.local import _find_shell, _resolve_safe_cwd, _sanitize_subprocess_env
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
@ -480,7 +480,7 @@ class ProcessRegistry:
command=command, command=command,
task_id=task_id, task_id=task_id,
session_key=session_key, session_key=session_key,
cwd=cwd or os.getcwd(), cwd=_resolve_safe_cwd(cwd or os.getcwd()),
started_at=time.time(), started_at=time.time(),
) )