ππΌββοΈ The blackboard for coding agents - agentic development environment for claude code, codex, cursor, opencode, grok and more.
Rust adeai-agentsclaudeclaude-codecodexcursorgeminigrokopencodespec-driven-developmentvibe-codingvim
fix: run a task on the agent picked in the wizard (#159)
Fynn Fluegge79627cc8e008
diff --git a/CLAUDE.md b/CLAUDE.mdindex 1c5b00c..d41ae41 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -1290,7 +1290,7 @@ The flow is **Title β Agent β Plugin β Prompt**. Both middle steps are opt`WizardState` (`src/tui/wizard.rs`) is the whole flow as one value β the step, both text fields, both list picks, and the edited task's id. Holding every field at once is what makes back-navigation work: stepping back has to find the earlier answers still intact.-**The agent step writes `Task::agent`**, the database field every later phase reads. The plugin list is filtered by whatever the agent step settled on, so changing the agent rebuilds it (`reseed_plugins_for_agent`), keeping the pick when that plugin survives the new filter β switching agent is not a decision about the plugin. `try_save_wizard` rebuilds too, so saving straight from the agent step cannot store an incompatible plugin.+**The agent step writes `Task::base_agent`**, which stands in for `default_agent` whenever a phase's agent is resolved (`phase_agent` in `app.rs`): a phase's own `[agents]` entry wins, else the task's pick, else the configured default. It is a column of its own, not `Task::agent`, because `agent` names what is running in the window *now* β a per-phase override rewrites it on every switch, so a pick stored there is gone the first time an override runs, and the next un-overridden phase would stay on the override's agent. Resolving against `config.agent_for_phase` instead ignores the pick entirely: every task created on a non-default agent is switched back to the default on its first transition. A row stored before the column is `NULL` and resolves to the configured default; the migration backfills `base_agent` from `agent` only for Backlog tasks with no session, the one case where `agent` is known to still be the pick. The plugin list is filtered by whatever the agent step settled on, so changing the agent rebuilds it (`reseed_plugins_for_agent`), keeping the pick when that plugin survives the new filter β switching agent is not a decision about the plugin. `try_save_wizard` rebuilds too, so saving straight from the agent step cannot store an incompatible plugin.**Both lists are seeded when the wizard opens**, not on the first `Enter`, so the breadcrumb shows the real flow from the first frame.@@ -1322,7 +1322,7 @@ A refusal is never silent. `title_problem()` is the single source for both `Ente**The renderer is a real `Layout`** (`draw_wizard`): breadcrumb, the steps already behind you, the active step, a validation row. Each step sizes its own body β a title is one line, a prompt and a list want the room β and text fields draw inside their own bordered box, so the caret starts at column 0 of the inner area with no prefix to measure. List steps use ratatui's `List` and `Scrollbar`. The scrollbar track is inset by one row at each end; handed the whole area it draws over the block's corners.-Agent is determined by `config.default_agent` (set via config file), not selected per-task.+Agent defaults to `config.default_agent`; the agent step overrides it per task. The prompt step's `/` skill picker lists skills in the syntax of the agent the step settled on.Plugin defaults to the project's active plugin (set via `P` on the board).The prompt step's `#`/`@`, `/` and `!` dropdowns are each their own handler (`handle_file_search_key`, `handle_skill_search_key`, `handle_task_ref_search_key`), and each **takes its state out** for the duration: every arm needs the dropdown alongside the wizard's prompt field, and several call back into `self` to refresh the match list, which a held borrow would not allow. They return whether the key belonged to them, so the prompt handler keeps a fallback. All three commit and cancel through `splice_search_region` β only the replacement text differs.diff --git a/src/db/models.rs b/src/db/models.rsindex fd35800..ccf33f9 100644--- a/src/db/models.rs+++ b/src/db/models.rs@@ -62,7 +62,16 @@ pub struct Task {pub title: String,pub description: Option<String>,pub status: TaskStatus,+ /// The agent running in the task's window now. A phase with its own agent+ /// in `[agents]` switches the task over and rewrites this, which is why it+ /// cannot also carry the task's own pick β see `base_agent`.pub agent: String,+ /// The agent this task runs on in any phase without a per-phase override:+ /// the task wizard's pick, or the configured default at creation. Stands in+ /// for `default_agent` when a phase's agent is resolved, so a task picked to+ /// run on another agent stays on it. `None` for a task stored before the+ /// column existed, which falls back to the configured default.+ pub base_agent: Option<String>,pub project_id: String,pub session_name: Option<String>,pub worktree_path: Option<String>,@@ -93,12 +102,14 @@ impl Task {) -> Self {let id = uuid::Uuid::new_v4().to_string();let now = Utc::now();+ let agent = agent.into();Self {id,title: title.into(),description: None,status: TaskStatus::Backlog,- agent: agent.into(),+ base_agent: Some(agent.clone()),+ agent,project_id: project_id.into(),session_name: None,worktree_path: None,diff --git a/src/db/schema.rs b/src/db/schema.rsindex 28cb480..479ba09 100644--- a/src/db/schema.rs+++ b/src/db/schema.rs@@ -209,6 +209,17 @@ impl Database {let _ = self.conn.execute("ALTER TABLE tasks ADD COLUMN phase_entered_at TEXT", []);+ let _ = self+ .conn+ .execute("ALTER TABLE tasks ADD COLUMN base_agent TEXT", []);+ // A task that has never had a session has never been switched, so its+ // `agent` is still the pick it was created with. Any other row's `agent`+ // may be a per-phase override's, and is left to the configured default.+ let _ = self.conn.execute(+ "UPDATE tasks SET base_agent = agent+ WHERE base_agent IS NULL AND status = 'backlog' AND session_name IS NULL",+ [],+ );// MCP transition request queueself.conn.execute_batch(@@ -353,8 +364,8 @@ impl Database {pub fn create_task(&self, task: &Task) -> Result<()> {self.conn.execute(r#"- INSERT INTO tasks (id, title, description, status, agent, project_id, session_name, worktree_path, branch_name, pr_number, pr_url, plugin, cycle, referenced_tasks, escalation_note, base_branch, created_at, updated_at, phase_entered_at)- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19)+ INSERT INTO tasks (id, title, description, status, agent, project_id, session_name, worktree_path, branch_name, pr_number, pr_url, plugin, cycle, referenced_tasks, escalation_note, base_branch, created_at, updated_at, phase_entered_at, base_agent)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20)"#,params![task.id,@@ -376,6 +387,7 @@ impl Database {task.created_at.to_rfc3339(),task.updated_at.to_rfc3339(),task.phase_entered_at.map(|t| t.to_rfc3339()),+ task.base_agent,],)?;Ok(())@@ -386,8 +398,8 @@ impl Database {for task in tasks {tx.execute(r#"- INSERT INTO tasks (id, title, description, status, agent, project_id, session_name, worktree_path, branch_name, pr_number, pr_url, plugin, cycle, referenced_tasks, escalation_note, base_branch, created_at, updated_at, phase_entered_at)- VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19)+ INSERT INTO tasks (id, title, description, status, agent, project_id, session_name, worktree_path, branch_name, pr_number, pr_url, plugin, cycle, referenced_tasks, escalation_note, base_branch, created_at, updated_at, phase_entered_at, base_agent)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20)"#,params![task.id,@@ -409,6 +421,7 @@ impl Database {task.created_at.to_rfc3339(),task.updated_at.to_rfc3339(),task.phase_entered_at.map(|t| t.to_rfc3339()),+ task.base_agent,],)?;}@@ -443,7 +456,8 @@ impl Database {escalation_note = ?14,base_branch = ?15,updated_at = ?16,- phase_entered_at = CASE WHEN status != ?4 THEN ?17 ELSE phase_entered_at END+ phase_entered_at = CASE WHEN status != ?4 THEN ?17 ELSE phase_entered_at END,+ base_agent = ?18WHERE id = ?1"#,params![@@ -464,6 +478,7 @@ impl Database {task.base_branch,task.updated_at.to_rfc3339(),chrono::Utc::now().to_rfc3339(),+ task.base_agent,],)?;Ok(())@@ -483,6 +498,7 @@ impl Database {status: TaskStatus::from_str(&row.get::<_, String>("status")?).unwrap_or(TaskStatus::Backlog),agent: row.get("agent")?,+ base_agent: row.get("base_agent").ok().flatten(),project_id: row.get("project_id")?,session_name: row.get("session_name")?,worktree_path: row.get("worktree_path")?,diff --git a/src/tui/app.rs b/src/tui/app.rsindex 13c621c..e5136ee 100644--- a/src/tui/app.rs+++ b/src/tui/app.rs@@ -1001,19 +1001,22 @@ impl App {// Re-deploy agent configs for worktrees set up by a different agtx binary.if let Some(ref project_path) = app.state.project_path {- let candidates: Vec<(String, Option<String>)> = app+ let candidates: Vec<(String, Option<String>, Vec<String>)> = app.state.board.tasks.iter().filter(|t| t.status != TaskStatus::Done)- .filter_map(|t| t.worktree_path.clone().map(|wt| (wt, t.plugin.clone())))+ .filter_map(|t| {+ t.worktree_path.clone().map(|wt| {+ (wt, t.plugin.clone(), collect_phase_agents(&app.state.config, t))+ })+ }).collect();if !candidates.is_empty() {refresh_stale_worktree_configs(candidates,project_path.clone(),- collect_phase_agents(&app.state.config),app.state.config.agent_hooks,);}@@ -5319,10 +5322,20 @@ impl App {let start_pos = self.prompt_mut().cursor;self.prompt_mut().insert_char('/');+ // In the syntax of the agent the task will run on, which the+ // wizard's agent step may have changed.+ let skill_agent = self+ .state+ .wizard+ .as_ref()+ .and_then(|w| w.agent_name())+ .unwrap_or(self.state.config.default_agent.as_str())+ .to_string();+// Start with bundled skills (always available, no filesystem needed)let mut seen = std::collections::HashSet::new();let mut all_skills: Vec<SkillEntry> =- skills::enumerate_available_skills(&self.state.config.default_agent)+ skills::enumerate_available_skills(&skill_agent).into_iter().map(|(command, description)| {seen.insert(command.clone());@@ -5336,7 +5349,7 @@ impl App {// Merge filesystem-discovered skills (project root), dedup by commandif let Some(ref project_path) = self.state.project_path {for (command, description) in- skills::scan_agent_skills(&self.state.config.default_agent, project_path)+ skills::scan_agent_skills(&skill_agent, project_path){if seen.insert(command.clone()) {all_skills.push(SkillEntry {@@ -5440,7 +5453,8 @@ impl App {return Ok(());};// The agent step's pick when it offered one, else the configured- // default. `Task::agent` is what every later phase reads.+ // default. Stored as `Task::base_agent`, which every later phase+ // without its own `[agents]` entry resolves to.let agent = wizard.agent_name().map(str::to_string)@@ -5472,7 +5486,13 @@ impl App {if let Some(mut task) = db.get_task(&task_id)? {task.title = title;task.description = description;- task.agent = agent;+ task.base_agent = Some(agent.clone());+ // A research window keeps running the agent it was launched+ // with; `agent` must keep naming it, so the next phase sees the+ // difference and switches.+ if task.session_name.is_none() {+ task.agent = agent;+ }task.plugin = plugin;task.referenced_tasks = refs;task.updated_at = chrono::Utc::now();@@ -5565,7 +5585,7 @@ impl App {.as_ref().and_then(|db| db.get_task(&id).ok().flatten())})- .map(|t| t.agent)+ .map(|t| t.base_agent.unwrap_or(t.agent)).unwrap_or_else(|| default_agent.clone());let options: Vec<PickOption> = self@@ -6026,7 +6046,7 @@ impl App {false,);let prompt_trigger = resolve_prompt_trigger(&plugin, "planning");- let all_agents = collect_phase_agents(&self.state.config);+ let all_agents = collect_phase_agents(&self.state.config, task);let project_name = self.state.project_name.clone();let tmux_project_name = self.state.tmux_project_name.clone();let base_branch = task@@ -6444,11 +6464,11 @@ impl App {return Ok(());}- let agent_name = self.state.config.agent_for_phase("research").to_string();+ let agent_name = phase_agent(&self.state.config, &task, "research").to_string();let task_content = task.content_text();- let all_agents = collect_phase_agents(&self.state.config);+ let all_agents = collect_phase_agents(&self.state.config, &task);let project_name = self.state.project_name.clone();let tmux_project_name = self.state.tmux_project_name.clone();let base_branch = task@@ -7229,8 +7249,8 @@ impl App {let plugin_name = task.plugin.clone();let plugin = self.load_task_plugin(&task);- let running_agent = self.state.config.agent_for_phase("running").to_string();- let all_agents = collect_phase_agents(&self.state.config);+ let running_agent = phase_agent(&self.state.config, &task, "running").to_string();+ let all_agents = collect_phase_agents(&self.state.config, &task);let prompt = resolve_prompt(&plugin, "running", &task_content, &task.id, task.cycle);let skill_cmd = resolve_skill_command(&plugin,@@ -12735,23 +12755,39 @@ fn glob_path_exists(pattern: &str) -> bool {false}-/// Check if a phase transition requires switching to a different agent.-/// Returns (target_agent_name, needs_switch).+/// The agent `task` runs in `phase`: the phase's own `[agents]` entry, else the+/// task's own agent (`Task::base_agent`), else the configured default.+///+/// The task's agent stands exactly where `default_agent` would, so a per-phase+/// override still wins, and a phase without one returns to the task's pick β+/// not to the global default, and not to whichever override ran last, which is+/// what `Task::agent` holds by then.+fn phase_agent<'a>(config: &'a MergedConfig, task: &'a Task, phase: &str) -> &'a str {+ config+ .explicit_agent_for_phase(phase)+ .or(task.base_agent.as_deref().filter(|a| !a.is_empty()))+ .unwrap_or(&config.default_agent)+}+/// Determine the target agent for a phase and whether a switch is needed.-/// Uses the phase-specific agent if configured, otherwise falls back to default_agent.+/// Returns (target_agent_name, needs_switch). See `phase_agent` for the target.fn needs_agent_switch(config: &MergedConfig, task: &Task, phase: &str) -> (String, bool) {- let target = config.agent_for_phase(phase);+ let target = phase_agent(config, task, phase);// Empty task.agent means agent not yet assigned (SetupResult pending) β no switch neededlet switch = !task.agent.is_empty() && task.agent != target;(target.to_string(), switch)}-/// Collect all unique agent names configured across phases.-/// Used to deploy skills for all agents that might be used during a task's lifecycle.-fn collect_phase_agents(config: &MergedConfig) -> Vec<String> {- let mut agents: Vec<String> = vec![config.default_agent.clone()];+/// Every agent `task` can run on: the one in its window now, plus each phase's.+/// Used to deploy skills for all of them at worktree setup, since a later phase+/// switch finds the worktree already written.+fn collect_phase_agents(config: &MergedConfig, task: &Task) -> Vec<String> {+ let mut agents: Vec<String> = Vec::new();+ if !task.agent.is_empty() {+ agents.push(task.agent.clone());+ }for phase in &["research", "planning", "running", "review"] {- let agent = config.agent_for_phase(phase).to_string();+ let agent = phase_agent(config, task, phase).to_string();if !agents.contains(&agent) {agents.push(agent);}@@ -13601,9 +13637,8 @@ fn claude_shaped_hooks(/// Runs on a background thread at startup and rewrites only worktrees whose/// marker disagrees with the running binary.fn refresh_stale_worktree_configs(- stale_candidates: Vec<(String, Option<String>)>,+ stale_candidates: Vec<(String, Option<String>, Vec<String>)>,project_path: PathBuf,- agent_names: Vec<String>,agent_hooks: bool,) {let Ok(current_bin) = std::env::current_exe() else {@@ -13613,9 +13648,8 @@ fn refresh_stale_worktree_configs(std::thread::spawn(move || {let mut plugin_cache: HashMap<Option<String>, Option<WorkflowPlugin>> = HashMap::new();- let refs: Vec<&str> = agent_names.iter().map(|s| s.as_str()).collect();- for (worktree, plugin_name) in stale_candidates {+ for (worktree, plugin_name, agent_names) in stale_candidates {let wt = Path::new(&worktree);if !wt.exists() {continue;@@ -13639,6 +13673,7 @@ fn refresh_stale_worktree_configs(worktree = %worktree,"Re-deploying agent configs: worktree was set up by a different agtx binary");+ let refs: Vec<&str> = agent_names.iter().map(|s| s.as_str()).collect();write_skills_to_worktree(&worktree, &project_path, &plugin, &refs, agent_hooks);}});diff --git a/src/tui/app_tests.rs b/src/tui/app_tests.rsindex 0b9d778..e5cc11b 100644--- a/src/tui/app_tests.rs+++ b/src/tui/app_tests.rs@@ -305,6 +305,7 @@ fn test_create_pr_with_content_success() {description: None,status: TaskStatus::Running,agent: "claude".to_string(),+ base_agent: Some("claude".to_string()),project_id: "proj-1".to_string(),session_name: Some("test-session".to_string()),worktree_path: Some("/tmp/worktree".to_string()),@@ -405,6 +406,7 @@ fn test_create_pr_with_content_no_changes() {description: None,status: TaskStatus::Running,agent: "claude".to_string(),+ base_agent: Some("claude".to_string()),project_id: "proj-1".to_string(),session_name: Some("test-session".to_string()),worktree_path: Some("/tmp/worktree".to_string()),@@ -464,6 +466,7 @@ fn test_create_pr_with_content_push_failure() {description: None,status: TaskStatus::Running,agent: "claude".to_string(),+ base_agent: Some("claude".to_string()),project_id: "proj-1".to_string(),session_name: None,worktree_path: Some("/tmp/worktree".to_string()),@@ -529,6 +532,7 @@ fn test_push_changes_to_existing_pr_success() {description: None,status: TaskStatus::Review,agent: "claude".to_string(),+ base_agent: Some("claude".to_string()),project_id: "proj-1".to_string(),session_name: Some("test-session".to_string()),worktree_path: Some("/tmp/worktree".to_string()),@@ -585,6 +589,7 @@ fn test_push_changes_to_existing_pr_no_changes() {description: None,status: TaskStatus::Review,agent: "claude".to_string(),+ base_agent: Some("claude".to_string()),project_id: "proj-1".to_string(),session_name: None,worktree_path: Some("/tmp/worktree".to_string()),@@ -624,6 +629,7 @@ fn test_push_changes_to_existing_pr_no_url() {description: None,status: TaskStatus::Review,agent: "claude".to_string(),+ base_agent: Some("claude".to_string()),project_id: "proj-1".to_string(),session_name: None,worktree_path: Some("/tmp/worktree".to_string()),@@ -3340,24 +3346,104 @@ fn test_needs_agent_switch_explicit_same_as_current() {assert!(!switch);}+#[test]+fn a_task_picked_to_run_on_another_agent_keeps_it() {+ use crate::config::{GlobalConfig, MergedConfig, ProjectConfig};+ use crate::db::Task;++ // Default agent is claude; the wizard picked gemini for this task.+ let config = MergedConfig::merge(&GlobalConfig::default(), &ProjectConfig::default());+ let task = Task::new("Test", "gemini", "project-1");++ for phase in ["research", "planning", "running", "review"] {+ let (agent, switch) = needs_agent_switch(&config, &task, phase);+ assert_eq!(agent, "gemini", "{phase}");+ assert!(!switch, "{phase}");+ }+}++#[test]+fn a_phase_override_still_beats_the_task_pick() {+ use crate::config::{GlobalConfig, MergedConfig, ProjectConfig};+ use crate::db::Task;++ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());+ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ let task = Task::new("Test", "gemini", "project-1");++ let (agent, switch) = needs_agent_switch(&config, &task, "running");+ assert_eq!(agent, "codex");+ assert!(switch);+}++#[test]+fn a_phase_without_an_override_returns_to_the_task_pick() {+ use crate::config::{GlobalConfig, MergedConfig, ProjectConfig};+ use crate::db::Task;++ // Running was overridden to codex, which rewrote `agent`; review has no+ // override, so it goes back to what the task was created with.+ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());+ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ let mut task = Task::new("Test", "gemini", "project-1");+ task.agent = "codex".to_string();++ let (agent, switch) = needs_agent_switch(&config, &task, "review");+ assert_eq!(agent, "gemini");+ assert!(switch);+}++#[test]+fn a_task_stored_without_a_base_agent_falls_back_to_the_default() {+ use crate::config::{GlobalConfig, MergedConfig, ProjectConfig};+ use crate::db::Task;++ let config = MergedConfig::merge(&GlobalConfig::default(), &ProjectConfig::default());+ let mut task = Task::new("Test", "codex", "project-1");+ task.base_agent = None;++ let (agent, switch) = needs_agent_switch(&config, &task, "review");+ assert_eq!(agent, "claude");+ assert!(switch);+}+#[test]fn test_collect_phase_agents_all_same() {use crate::config::{GlobalConfig, MergedConfig, ProjectConfig};+ use crate::db::Task;let config = MergedConfig::merge(&GlobalConfig::default(), &ProjectConfig::default());- let agents = collect_phase_agents(&config);+ let task = Task::new("Test", "claude", "project-1");+ let agents = collect_phase_agents(&config, &task);assert_eq!(agents, vec!["claude".to_string()]);}+#[test]+fn collect_phase_agents_deploys_for_the_task_pick_not_the_default() {+ use crate::config::{GlobalConfig, MergedConfig, ProjectConfig};+ use crate::db::Task;++ let mut global = GlobalConfig::default();+ global.agents.running = Some("codex".to_string());+ let config = MergedConfig::merge(&global, &ProjectConfig::default());+ let task = Task::new("Test", "gemini", "project-1");+ let agents = collect_phase_agents(&config, &task);+ assert_eq!(agents, vec!["gemini".to_string(), "codex".to_string()]);+}+#[test]fn test_collect_phase_agents_mixed() {use crate::config::{GlobalConfig, MergedConfig, ProjectConfig};+ use crate::db::Task;let mut global = GlobalConfig::default();global.agents.running = Some("codex".to_string());global.agents.review = Some("gemini".to_string());let config = MergedConfig::merge(&global, &ProjectConfig::default());- let agents = collect_phase_agents(&config);+ let task = Task::new("Test", "claude", "project-1");+ let agents = collect_phase_agents(&config, &task);assert_eq!(agents,vec![diff --git a/src/tui/dep_graph.rs b/src/tui/dep_graph.rsindex 32820fc..e74d071 100644--- a/src/tui/dep_graph.rs+++ b/src/tui/dep_graph.rs@@ -219,6 +219,7 @@ mod tests {description: None,status,agent: "claude".to_string(),+ base_agent: Some("claude".to_string()),project_id: "proj".to_string(),session_name: None,worktree_path: None,diff --git a/tests/db_tests.rs b/tests/db_tests.rsindex f810b10..97ef120 100644--- a/tests/db_tests.rs+++ b/tests/db_tests.rs@@ -168,6 +168,27 @@ fn test_in_memory_project_db_update_task() {assert_eq!(retrieved.session_name.as_deref(), Some("session-1"));}+#[test]+#[cfg(feature = "test-mocks")]+fn a_phase_switch_does_not_overwrite_the_task_pick() {+ let db = Database::open_in_memory_project().unwrap();+ let mut task = Task::new("Picked gemini", "gemini", "proj-1");+ db.create_task(&task).unwrap();+ assert_eq!(+ db.get_task(&task.id).unwrap().unwrap().base_agent.as_deref(),+ Some("gemini")+ );++ // A per-phase override switches the running agent.+ task.agent = "codex".to_string();+ task.status = TaskStatus::Running;+ db.update_task(&task).unwrap();++ let retrieved = db.get_task(&task.id).unwrap().unwrap();+ assert_eq!(retrieved.agent, "codex");+ assert_eq!(retrieved.base_agent.as_deref(), Some("gemini"));+}+#[test]#[cfg(feature = "test-mocks")]fn test_in_memory_project_db_list_tasks() {@@ -549,6 +570,36 @@ fn test_open_project_same_path_returns_same_db() {assert_eq!(retrieved.unwrap().title, "Persistence test");}+#[test]+fn base_agent_is_backfilled_only_for_tasks_that_never_started() {+ let (_data_dir, _guard) = redirect_data_dir();+ let temp_dir = TempDir::new().unwrap();+ let project_path = temp_dir.path();++ // Rows as a binary without the column would have left them.+ let db = Database::open_project(project_path).unwrap();+ let mut fresh = Task::new("Never started", "gemini", "proj");+ fresh.base_agent = None;+ db.create_task(&fresh).unwrap();+ let mut researched = Task::new("Has a session", "codex", "proj");+ researched.base_agent = None;+ researched.session_name = Some("proj:task-researched".to_string());+ db.create_task(&researched).unwrap();+ let mut running = Task::new("Running", "codex", "proj");+ running.base_agent = None;+ running.status = TaskStatus::Running;+ db.create_task(&running).unwrap();+ drop(db);++ let db = Database::open_project(project_path).unwrap();+ let base = |id: &str| db.get_task(id).unwrap().unwrap().base_agent;+ // Its `agent` is still the pick it was created with.+ assert_eq!(base(&fresh.id).as_deref(), Some("gemini"));+ // These may be running a per-phase override's agent; not a pick.+ assert_eq!(base(&researched.id), None);+ assert_eq!(base(&running.id), None);+}+#[test]fn test_open_project_different_paths_are_isolated() {let (_data_dir, _guard) = redirect_data_dir();