From 109c3e468c8ffaf5733683aa1f02afb925104be4 Mon Sep 17 00:00:00 2001 From: kshitij <82637225+kshitijk4poor@users.noreply.github.com> Date: Mon, 4 May 2026 15:35:34 -0700 Subject: [PATCH] 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. --- tools/process_registry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/process_registry.py b/tools/process_registry.py index da5c8d224b..0fc312185d 100644 --- a/tools/process_registry.py +++ b/tools/process_registry.py @@ -41,7 +41,7 @@ import time import uuid _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 typing import Any, Dict, List, Optional @@ -480,7 +480,7 @@ class ProcessRegistry: command=command, task_id=task_id, session_key=session_key, - cwd=cwd or os.getcwd(), + cwd=_resolve_safe_cwd(cwd or os.getcwd()), started_at=time.time(), )