From 098c2350ba86cdc741f00c008ced326e14552f44 Mon Sep 17 00:00:00 2001 From: Harry <4210852+harryert@users.noreply.github.com> Date: Thu, 29 Oct 2026 17:28:52 +0800 Subject: [PATCH 1/2] fix(ecc2): resolve native assignment directory from parent lead --- ecc2/src/session/manager.rs | 56 +++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/ecc2/src/session/manager.rs b/ecc2/src/session/manager.rs index aca68a676..e280725e9 100644 --- a/ecc2/src/session/manager.rs +++ b/ecc2/src/session/manager.rs @@ -883,8 +883,9 @@ pub async fn assign_session_with_profile_and_grouping( profile_name: Option<&str>, grouping: SessionGrouping, ) -> Result { - let repo_root = - std::env::current_dir().context("Failed to resolve current working directory")?; + // Native assignment belongs to the recorded Lead, not the operator's + // shell (which may be outside the project and lack its model settings). + let repo_root = resolve_session(db, lead_id)?.working_dir; assign_session_in_dir_with_runner_program( db, cfg, @@ -6855,6 +6856,57 @@ mod tests { Ok(()) } + #[tokio::test(flavor = "current_thread")] + async fn native_assign_uses_lead_working_dir_not_operator_cwd() -> Result<()> { + let tempdir = TestDir::new("manager-assign-lead-cwd")?; + let repo_root = tempdir.path().join("original-lead-repo"); + init_git_repo(&repo_root)?; + let foreign_dir = tempdir.path().join("operator-outside-repo"); + fs::create_dir_all(&foreign_dir)?; + let mut cfg = build_config(tempdir.path()); + cfg.max_parallel_sessions = 3; + cfg.max_parallel_worktrees = 0; // queue without launching a test process + let db = StateStore::open(&cfg.db_path)?; + let now = Utc::now(); + db.insert_session(&Session { + id: "lead".to_string(), + task: "original lead task".to_string(), + project: "original-project".to_string(), + task_group: "general".to_string(), + agent_type: "claude".to_string(), + working_dir: repo_root.clone(), + state: SessionState::Running, + pid: Some(42), + worktree: None, + created_at: now, + updated_at: now, + last_heartbeat_at: now, + metrics: SessionMetrics::default(), + })?; + let _cwd_guard = crate::test_support::CurrentDirGuard::enter(&foreign_dir)?; + let outcome = assign_session_with_profile_and_grouping( + &db, + &cfg, + "lead", + "One independent change", + "claude", + true, + None, + SessionGrouping::default(), + ) + .await?; + assert_eq!(outcome.action, AssignmentAction::Spawned); + let delegate = db + .get_session(&outcome.session_id)? + .context("missing queued delegate")?; + assert_eq!( + delegate.working_dir, repo_root, + "never inherit caller working directory" + ); + assert_eq!(delegate.state, SessionState::Pending); + Ok(()) + } + #[tokio::test(flavor = "current_thread")] async fn assign_session_reuses_idle_delegate_when_available() -> Result<()> { let tempdir = TestDir::new("manager-assign-reuse-idle")?; From ad51be75157786fb5d2df599358c2b7196214e62 Mon Sep 17 00:00:00 2001 From: Harry <4210852+harryert@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:12:31 +0800 Subject: [PATCH 2/2] test(ecc2): reject ambiguous relative Lead directory for assignment --- ecc2/src/session/manager.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ecc2/src/session/manager.rs b/ecc2/src/session/manager.rs index e280725e9..61456b0c0 100644 --- a/ecc2/src/session/manager.rs +++ b/ecc2/src/session/manager.rs @@ -886,6 +886,12 @@ pub async fn assign_session_with_profile_and_grouping( // Native assignment belongs to the recorded Lead, not the operator's // shell (which may be outside the project and lack its model settings). let repo_root = resolve_session(db, lead_id)?.working_dir; + // A relative historical path cannot be safely rebased against an arbitrary + // operator cwd: doing so would reintroduce the original misrouting defect. + anyhow::ensure!( + repo_root.is_absolute(), + "Lead working directory must be absolute before assignment: {lead_id}" + ); assign_session_in_dir_with_runner_program( db, cfg, @@ -6904,6 +6910,27 @@ mod tests { "never inherit caller working directory" ); assert_eq!(delegate.state, SessionState::Pending); + + let mut relative_lead = db.get_session("lead")?.context("missing original lead")?; + relative_lead.id = "relative-lead".to_string(); + relative_lead.working_dir = PathBuf::from("relative-project"); + db.insert_session(&relative_lead)?; + let result = assign_session_with_profile_and_grouping( + &db, + &cfg, + "relative-lead", + "Must never dispatch from operator cwd", + "claude", + true, + None, + SessionGrouping::default(), + ) + .await; + let error = result.err().context("relative Lead path must fail closed")?; + assert!( + format!("{error:#}").contains("must be absolute"), + "error must describe the invalid persisted Lead working directory" + ); Ok(()) }