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 <[email protected]>
Цей коміт міститься в:
LU XIANGRUIтаwildcatDownstairs authored and GitHub committed 2026-12-04 00:33:53 +08:00
1 джерело e666bb2e33
коміт fd22254194
2 files changed
+24

No files matched your search

+5
Переглянути файл
@@ -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))
}
};
+19
Переглянути файл
@@ -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;
}