diff --git a/crates/ide-agent/src/lib.rs b/crates/ide-agent/src/lib.rs index 5d4f64a6d7..0d29ec5ca8 100644 --- a/crates/ide-agent/src/lib.rs +++ b/crates/ide-agent/src/lib.rs @@ -2050,6 +2050,11 @@ impl AgentManager { s.busy = true; s.pending_prompt = Some(prompt.clone()); s.active_scheduled_turn = scheduled.clone(); + // A run watcher reads the status before the spawned turn shows its prompt, and + // would take the previous turn's `Ready` for the end of this one. + if scheduled.is_some() { + s.change_status(AgentStatus::Starting, None); + } Some((prompt, scheduled, epoch)) } }; diff --git a/crates/ide-agent/src/tests.rs b/crates/ide-agent/src/tests.rs index 9d04df804d..a8aa8abc3b 100644 --- a/crates/ide-agent/src/tests.rs +++ b/crates/ide-agent/src/tests.rs @@ -7604,3 +7604,22 @@ async fn metadata_edits_do_not_bump_updated_ms() { .unwrap(); assert_eq!(after_memory.updated_ms, fixed_ms); } + +/// An automation reads the status as soon as its prompt is accepted: the previous turn's +/// `Ready` would complete the run before its turn started. +#[tokio::test] +async fn an_accepted_scheduled_prompt_no_longer_reads_as_ready() { + let tmp = tempfile::tempdir().unwrap(); + let mgr = manager(tmp.path(), Arc::new(FakeAgent::default())); + let _down = ShutDown(&mgr); + let task = mgr + .create(NewAgentTask { provider: "claude".into(), prompt: text("again"), ..Default::default() }) + .await + .unwrap(); + wait_for(&mgr, &task.id, AgentStatus::Ready).await; + + mgr.prompt_scheduled(&task.id, text("again"), ScheduledTurnMeta::default()).await.unwrap(); + // The single-threaded runtime has not started the spawned turn yet. + assert_eq!(mgr.task_snapshot(&task.id).unwrap().status, AgentStatus::Starting); + wait_for(&mgr, &task.id, AgentStatus::Ready).await; +}