loopd: consult waits one hundred and eighty seconds

Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
2026-10-03 21:47:20 -07:00
co-authored by ornith-1.5-35b-a3b
parent 658bc7d1e8
commit 45eb16a30a
3 changed files with 32 additions and 1 deletions
+9 -1
View File
@@ -26,6 +26,9 @@ pub const MAX_PENDING_WAIT: Duration = Duration::from_secs(24 * 60 * 60);
/// longer: `brokerd` waits 170 s for `memoryd`, whose Honcho chats have 150 s (M5c spec,
/// section 9).
pub const ASK_MEMORY_WAIT: Duration = Duration::from_secs(180);
/// The longest `BrokerPort` waits for a `consult` answer, unless `[broker] timeout_ms` is
/// longer: `brokerd`'s `[consult] timeout_ms` defaults to 180 s (M6 spec, section 4.3).
pub const CONSULT_WAIT: Duration = Duration::from_secs(180);
/// The runbook entry every outage line ends with.
pub const POINTER: &str = "see docs/runbook.md#broker-unavailable";
@@ -63,6 +66,7 @@ pub struct BrokerPort {
socket: PathBuf,
timeout: Duration,
ask_timeout: Duration,
consult_timeout: Duration,
pending_cap: Duration,
log: Box<dyn Fn(&str) + Send + Sync>,
}
@@ -73,6 +77,7 @@ impl BrokerPort {
socket,
timeout,
ask_timeout: ASK_MEMORY_WAIT,
consult_timeout: CONSULT_WAIT,
pending_cap: MAX_PENDING_WAIT,
log: Box::new(|l| eprintln!("{l}")),
}
@@ -88,10 +93,12 @@ impl BrokerPort {
}
/// The wait for one call of `tool`, used wherever the port waits for that call: the timeout,
/// or for `ask_memory` the longer of the timeout and its own wait.
/// or for `ask_memory` and `consult` the longer of the timeout and that tool's own wait.
pub fn timeout_for(&self, tool: &str) -> Duration {
if tool == crate::memory::ASK_MEMORY {
self.timeout.max(self.ask_timeout)
} else if tool == crate::consult::CONSULT {
self.timeout.max(self.consult_timeout)
} else {
self.timeout
}
@@ -114,6 +121,7 @@ impl BrokerPort {
socket,
timeout,
ask_timeout: ASK_MEMORY_WAIT,
consult_timeout: CONSULT_WAIT,
pending_cap: MAX_PENDING_WAIT,
log,
}
@@ -0,0 +1,22 @@
//! How long `BrokerPort` waits for `consult`: 180 s, or `[broker] timeout_ms` if that is longer.
//! Do not edit.
use std::time::Duration;
use loopd::broker_port::{BrokerPort, CONSULT_WAIT};
fn quiet(timeout: Duration) -> BrokerPort {
BrokerPort::with_log("unused.sock".into(), timeout, Box::new(|_| {}))
}
#[test]
fn consult_waits_one_hundred_and_eighty_seconds() {
assert_eq!(CONSULT_WAIT, Duration::from_secs(180));
let port = BrokerPort::new("unused.sock".into(), Duration::from_secs(120));
assert_eq!(port.timeout_for("consult"), CONSULT_WAIT);
assert_eq!(port.timeout_for("recall"), Duration::from_secs(120));
let port = BrokerPort::new("unused.sock".into(), Duration::from_secs(300));
assert_eq!(port.timeout_for("consult"), Duration::from_secs(300));
let port = quiet(Duration::from_secs(120));
assert_eq!(port.timeout_for("consult"), CONSULT_WAIT, "with_log as new");
}