fix(tools): isolate per-session worktree cwd
This commit is contained in:
+15
-2
@@ -2290,14 +2290,27 @@ def terminal_tool(
|
||||
"EOF."
|
||||
)
|
||||
|
||||
# Claim the (shared "default") terminal env for the session driving this
|
||||
# command. File tools read env.cwd_owner to decide whether the env's live
|
||||
# cwd is THIS session's `cd` or a different worktree session's — without
|
||||
# it, two open worktree sessions sharing the env route each other's edits
|
||||
# to the wrong checkout. get_current_session_key()'s contextvar doesn't
|
||||
# cross tool-worker threads, so fall back to the raw task_id (which IS the
|
||||
# session_key for the top-level agent) — a stable, thread-safe anchor.
|
||||
from tools.approval import get_current_session_key
|
||||
|
||||
session_key = get_current_session_key(default="") or (task_id or "")
|
||||
try:
|
||||
env.cwd_owner = session_key
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if background:
|
||||
# Spawn a tracked background process via the process registry.
|
||||
# For local backends: uses subprocess.Popen with output buffering.
|
||||
# For non-local backends: runs inside the sandbox via env.execute().
|
||||
from tools.approval import get_current_session_key
|
||||
from tools.process_registry import process_registry
|
||||
|
||||
session_key = get_current_session_key(default="")
|
||||
effective_cwd = _resolve_command_cwd(
|
||||
workdir=workdir,
|
||||
env=env,
|
||||
|
||||
Reference in New Issue
Block a user