fix(#937): skip scheduled delivery if target already has pending scheduled message

This commit is contained in:
damocles 2026-06-01 13:33:34 +02:00 committed by mara
commit bf4937d116
2 changed files with 40 additions and 0 deletions

View file

@ -96,6 +96,31 @@ fn fire_schedule(coord: &Arc<Coordinator>, schedule: &Schedule, now: i64) {
notify_operator_missing_target(coord, schedule, target);
continue;
}
// Skip delivery if there is already an unread message from
// "scheduled" waiting in this target's inbox. Prevents prompt
// accumulation when the agent is slow to drain its queue or
// was briefly offline: at most one scheduled message is ever
// pending per target at a time.
match coord.broker.has_pending_from(target, "scheduled") {
Ok(true) => {
tracing::debug!(
schedule = schedule.id,
%target,
"scheduled_prompts: skipping — target already has pending scheduled message"
);
let _ = coord.scheduled_prompts.record_target_result(
schedule.id,
target,
now,
"skipped: already pending",
);
continue;
}
Err(e) => {
tracing::warn!(schedule = schedule.id, %target, error = ?e, "has_pending_from failed");
}
Ok(false) => {}
}
let msg = Message {
from: "scheduled".to_owned(),
to: target.clone(),