feat(#1106): transient wake for bash tasks — bypass broker sqlite

This commit is contained in:
damocles 2026-06-03 10:40:33 +02:00 committed by mara
commit a1c6736ba5
8 changed files with 102 additions and 19 deletions

View file

@ -117,6 +117,11 @@ pub enum MessageEvent {
at: i64,
in_reply_to: Option<i64>,
},
/// Transient wake signal — NOT persisted to sqlite. Wakes
/// `recv_blocking_batch` for the target agent but is not stored,
/// not re-delivered on restart, and not shown in message history.
/// Used for bash task completion notifications.
Ping { to: String, from: String, body: String },
}
/// Per-recipient in-memory bookkeeping for the deliver-then-ack
@ -191,6 +196,19 @@ impl Broker {
Ok(())
}
/// Deliver a transient wake signal to `to` without writing to sqlite.
/// The signal wakes a long-polling `recv_blocking_batch` for the target
/// agent but is not persisted, not redelivered on restart, and not shown
/// in message history. Use for ephemeral notifications (bash task
/// completions) where persistence would cause duplicate delivery.
pub fn ping(&self, to: &str, from: &str, body: &str) {
let _ = self.events.send(MessageEvent::Ping {
to: to.to_owned(),
from: from.to_owned(),
body: body.to_owned(),
});
}
/// Latest `limit` messages addressed to `recipient`, newest-first.
/// Includes delivered + undelivered alike — used for the operator
/// inbox view on the dashboard. Caller decides what to show.
@ -402,6 +420,32 @@ impl Broker {
}
// Lost a race (concurrent recv elsewhere). Keep waiting.
}
// Transient ping — not sqlite-backed. Return it directly as
// a Delivery with id=0 (sentinel: never pushed to unacked_ids
// so ack_turn silently ignores it).
Ok(Ok(MessageEvent::Ping {
to,
from,
body,
})) if to == recipient => {
// Also drain any real sqlite messages that may have landed
// concurrently; prepend the ping so the agent sees both.
let mut batch = self.recv_batch(recipient, max.saturating_sub(1))?;
batch.insert(
0,
Delivery {
id: 0,
redelivered: false,
message: Message {
from,
to,
body,
in_reply_to: None,
},
},
);
return Ok(batch);
}
Ok(Ok(_)) => {}
}
}