coordinator: push_todo returns Result so callers can see delivery outcome

This commit is contained in:
damocles 2026-08-03 00:37:39 +02:00 committed by mara
commit 7c6f108716
6 changed files with 27 additions and 17 deletions

View file

@ -1387,6 +1387,14 @@ impl Coordinator {
/// delivery. An agent that's down doesn't need a todo about
/// something it'll never see appear this way; whatever mechanism
/// resurfaces its state on the next boot is unrelated to this path.
///
/// Returns `Ok(())` on a successful push and `Err(reason)` — a
/// short human-readable string, already logged at `debug`/`warn`
/// by this function — on any of the silent-no-op cases below.
/// Most callers are pure fire-and-forget notices and ignore it
/// (`let _ = coord.push_todo(...).await;`); callers that track a
/// per-target delivery outcome (e.g. the scheduled-prompts worker's
/// `last_result` column) use it instead of assuming success.
pub async fn push_todo(
&self,
agent: &str,
@ -1394,15 +1402,15 @@ impl Coordinator {
key: Option<String>,
summary: String,
source: Option<String>,
) {
) -> Result<(), String> {
let Ok(ident) = hive_types::Ident::parse(agent) else {
tracing::warn!(%agent, "push_todo: not a valid agent ident, skipping");
return;
return Err(format!("'{agent}' is not a valid agent ident"));
};
let path = hive_host_sock::agent_todo_socket(&ident);
if !path.exists() {
tracing::debug!(%agent, path = %path.display(), "push_todo: agent socket not present (offline?), skipping");
return;
return Err(format!("agent '{agent}' socket not present (offline?)"));
}
let req = hive_agent_sock::Request::UpsertTodo {
subsystem: subsystem.to_owned(),
@ -1419,11 +1427,13 @@ impl Coordinator {
{
Ok(hive_agent_sock::Response::Err { message }) => {
tracing::warn!(%agent, %message, "push_todo: agent rejected the todo");
Err(format!("agent '{agent}' rejected the todo: {message}"))
}
Err(e) => {
tracing::warn!(%agent, error = ?e, "push_todo: dial failed");
Err(format!("push_todo dial to '{agent}' failed: {e:#}"))
}
Ok(_) => {}
Ok(_) => Ok(()),
}
}
@ -1436,10 +1446,10 @@ impl Coordinator {
key: Option<String>,
summary: String,
source: Option<String>,
) {
) -> Result<(), String> {
let target = self.submitter_or_manager(approval_id);
self.push_todo(&target, subsystem, key, summary, source)
.await;
.await
}
/// Push a `HelperEvent` into an arbitrary agent's inbox. Encoded