The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(delegation): a profile child reads the starting directory seeded for it
Teknium433323077a9c
diff --git a/tests/tools/test_delegation_profile_route.py b/tests/tools/test_delegation_profile_route.pyindex f578b88da7d..63d54f98bf0 100644--- a/tests/tools/test_delegation_profile_route.py+++ b/tests/tools/test_delegation_profile_route.py@@ -319,3 +319,30 @@ def test_one_profile_under_two_labels_resolves_once_and_keeps_each_label(two_proassert rp.call_count == 1assert (first.label, second.label) == ("reviewer", "fixer")assert first.creds == second.creds and first.creds["model"] == "coder-model"++[email protected]("worktree", [None, {"path": "/work/wt-1", "branch": "subagent/wt-1"}])+def test_profile_child_reads_the_starting_directory_seeded_for_it(two_profiles, worktree):+ """cwd records are keyed by the active profile on a multiplexed host: the child's starting directory (the+ parent's, or its isolated worktree) is recorded where the child, running as the target profile, reads it."""+ from tools.delegate_tool_child_run import _ChildRun+ from tools.delegate_tool_routes import child_profile_scope+ from tools.terminal_tool import clear_session_cwd, get_session_cwd, record_session_cwd++ _, coder = two_profiles++ class _Child:+ _delegate_profile_home = coder++ class _Parent:+ _current_task_id = "parent-task"++ record_session_cwd("parent-task", "/work/repo")+ run = _ChildRun(_Child(), _Parent(), 0, "work as coder", None, None)+ try:+ with patch("tools.delegate_tool_child_run._create_isolated_worktree", return_value=worktree):+ run.seed_workspace()+ with child_profile_scope(run.child):+ assert get_session_cwd(run.child_task_id) == (worktree or {}).get("path", "/work/repo")+ finally:+ clear_session_cwd("parent-task")diff --git a/tools/delegate_tool_child_run.py b/tools/delegate_tool_child_run.pyindex 34776916689..25080ea7269 100644--- a/tools/delegate_tool_child_run.py+++ b/tools/delegate_tool_child_run.py@@ -781,14 +781,19 @@ class _ChildRun:# Seed the child's cwd record from the parent's: same starting directory,# but the child's later `cd`s stay in its own record. Per-session container# isolation keys containers by task_id; the child must share the PARENT's.+ # The parent's record is read in the parent's scope; the child's is written in the child's (cwd records+ # are keyed by the active profile, and a profile-routed child looks its own up as that profile).+ from tools.delegate_tool_routes import child_profile_scopewith _quiet("Child cwd seed failed: %s"):from tools.terminal_tool import get_session_cwd, record_session_cwd, register_container_alias- record_session_cwd(self.child_task_id, get_session_cwd(self.parent_task_id))+ parent_cwd = get_session_cwd(self.parent_task_id)+ with child_profile_scope(self.child):+ record_session_cwd(self.child_task_id, parent_cwd)register_container_alias(self.child_task_id, self.parent_task_id)self.worktree_info = _create_isolated_worktree(self.parent_agent, self.parent_task_id, self.subagent_id)if self.worktree_info is not None:- with _quiet("worktree cwd seed failed: %s"):+ with _quiet("worktree cwd seed failed: %s"), child_profile_scope(self.child):from tools.terminal_tool import record_session_cwd as _rsc_rsc(self.child_task_id, self.worktree_info["path"])# The child's context is already built; carry the isolation contract on