From fd22254194bbf91be10923a4f1f3dd469dfa85b4 Mon Sep 17 00:00:00 2001 From: LU XIANGRUI <1078666705@qq.com> Date: Fri, 4 Dec 2026 01:33:53 +0900 Subject: [PATCH] fix(automations): keep a run open until its scheduled turn starts (#7834) A scheduled turn in an existing conversation could be recorded as Completed before it started: the run watcher reads the task status right after the prompt is accepted, and the previous turn's Ready stayed until the spawned turn showed its prompt. The status now turns Starting as soon as a scheduled prompt is accepted. This also fixes the intermittent SameTask failure of the automations safety-ceilings test. Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com> --- crates/ide-agent/src/lib.rs | 5 +++++ crates/ide-agent/src/tests.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) 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; +}