Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(tinyplace): classify the not-yet-published 404 and surface the real cause

M3gA-Mindbd3ea372c4f4
diff --git a/src/openhuman/hosted/orchestration/ops.rs b/src/openhuman/hosted/orchestration/ops.rs
index 63a4647e69..8af5e49646 100644
--- a/src/openhuman/hosted/orchestration/ops.rs
+++ b/src/openhuman/hosted/orchestration/ops.rs
@@ -21,6 +21,38 @@ use super::types::SessionEnvelopeV1;
const LOG: &str = "orchestration";
static MESSAGE_DRAIN_SUPERVISOR_STARTED: OnceLock<()> = OnceLock::new();
+/// How long the drain supervisor sleeps between cycles.
+///
+/// Named because [`NOT_DISCOVERABLE_WARN_AFTER_CYCLES`] is expressed in cycles
+/// and the escalation message reports elapsed seconds; deriving one from the
+/// other keeps them from drifting apart when the interval is tuned.
+const CYCLE_SLEEP_SECS: u32 = 15;
+
+/// Consecutive supervisor cycles in which this agent is still not discoverable
+/// before the loop escalates the **cause** from `debug` to exactly one `warn`.
+///
+/// The cycle sleeps 15 s, so 4 is ~1 minute — long enough to sit through the
+/// ordinary boot case (the wallet is usually locked for the first cycle or two
+/// and `ensure_signal_keys_published` returns `Err` until it is unlocked),
+/// short enough that a registration that never completes is visible while an
+/// operator is still looking.
+///
+/// Same shape as `platform::socket::ws_loop`'s `FAIL_ESCALATE_THRESHOLD`
+/// (`ws_loop.rs:52`), which solved this exact problem for the socket loop: one
+/// escalated line per run, not one per cycle, so a permanently-locked wallet
+/// costs one `warn` rather than an unbounded stream of them.
+const NOT_DISCOVERABLE_WARN_AFTER_CYCLES: u32 = 4;
+
+/// Whether this cycle is the one that escalates.
+///
+/// Exactly one cycle in a consecutive run qualifies — `==`, not `>=`. Above the
+/// threshold the loop returns to `debug`, which is what keeps a long-running
+/// unregistered instance from re-creating the very problem #5627 is about: an
+/// expected-but-persistent state reported on a repeating timer.
+fn should_escalate_not_discoverable(consecutive_cycles: u32) -> bool {
+ consecutive_cycles == NOT_DISCOVERABLE_WARN_AFTER_CYCLES
+}
+
pub fn start_message_drain_supervisor() {
if MESSAGE_DRAIN_SUPERVISOR_STARTED.set(()).is_err() {
log::debug!(target: LOG, "[orchestration] message drain supervisor already running");
@@ -36,12 +68,16 @@ pub fn start_message_drain_supervisor() {
// enabled instance. Retry each cycle until confirmed (the wallet may not
// be unlocked at boot), then stop probing.
let mut discoverable = false;
+ // Consecutive cycles spent still-not-discoverable, for the one-shot
+ // escalation below. Reset the moment publication is confirmed.
+ let mut not_discoverable_cycles: u32 = 0;
loop {
let config = match Config::load_or_init().await {
Ok(c) => c,
Err(e) => {
log::debug!(target: LOG, "[orchestration] drain config load: {e}");
- tokio::time::sleep(std::time::Duration::from_secs(15)).await;
+ tokio::time::sleep(std::time::Duration::from_secs(CYCLE_SLEEP_SECS as u64))
+ .await;
continue;
}
};
@@ -49,26 +85,52 @@ pub fn start_message_drain_supervisor() {
// false we must NOT publish Signal keys (that mutates remote directory
// state and makes the user discoverable) nor drain the mailbox.
if !config.orchestration.enabled {
- tokio::time::sleep(std::time::Duration::from_secs(15)).await;
+ tokio::time::sleep(std::time::Duration::from_secs(CYCLE_SLEEP_SECS as u64)).await;
continue;
}
if !discoverable {
+ // #5627: the symptom used to be loud and the cause silent —
+ // `signal_key_status`'s 404s logged at `warn` every cycle while
+ // the reason registration had not completed sat at `debug`. The
+ // 404s are now `debug` (they are the expected not-yet-published
+ // state); in exchange the *cause* escalates once, here, when a
+ // run of cycles proves it is not merely a slow boot.
+ //
+ // Both arms below share one escalation block: the decision is
+ // the same, only the reason text differs.
match crate::openhuman::tinyplace::ensure_signal_keys_published().await {
Ok(true) => {
discoverable = true;
+ not_discoverable_cycles = 0;
log::info!(
target: LOG,
"[orchestration] discoverable: Signal keys published — peers can reply"
);
}
- Ok(false) => log::debug!(
- target: LOG,
- "[orchestration] ensure_signal_keys: publish attempted, not yet confirmed — will retry"
- ),
- Err(e) => log::debug!(
- target: LOG,
- "[orchestration] ensure_signal_keys deferred (wallet locked / no signer?): {e}"
- ),
+ // Bound by value so the inner match can consume it — the
+ // two non-success outcomes take the same decision and differ
+ // only in the reason they report.
+ other => {
+ let reason = match other {
+ Err(e) => format!("last error (wallet locked / no signer?): {e}"),
+ _ => "publish was attempted each cycle but never confirmed".to_string(),
+ };
+ not_discoverable_cycles += 1;
+ if should_escalate_not_discoverable(not_discoverable_cycles) {
+ let elapsed_secs = not_discoverable_cycles * CYCLE_SLEEP_SECS;
+ log::warn!(
+ target: LOG,
+ "[orchestration] Signal keys still not published after \
+ {not_discoverable_cycles} cycles (~{elapsed_secs}s) — this agent \
+ is not discoverable and cannot receive DMs; {reason}"
+ );
+ } else {
+ log::debug!(
+ target: LOG,
+ "[orchestration] ensure_signal_keys not yet confirmed — will retry; {reason}"
+ );
+ }
+ }
}
}
// Auto-accept contact requests from already-linked agents FIRST, so a
@@ -93,7 +155,7 @@ pub fn start_message_drain_supervisor() {
Ok(_) => {}
Err(e) => log::debug!(target: LOG, "[orchestration] drain error: {e}"),
}
- tokio::time::sleep(std::time::Duration::from_secs(15)).await;
+ tokio::time::sleep(std::time::Duration::from_secs(CYCLE_SLEEP_SECS as u64)).await;
}
});
}
@@ -453,4 +515,37 @@ mod tests {
assert_eq!(session_send_plaintext("master", "hi").unwrap(), "hi");
assert_eq!(session_send_plaintext("subconscious", "hi").unwrap(), "hi");
}
+
+ /// #5627 — the escalation must fire on **exactly one** cycle in a run.
+ ///
+ /// The point of the threshold is that silencing the 404s (which are the
+ /// expected not-yet-published state) must not make a registration that
+ /// never completes invisible. So the cause has to become visible — once.
+ /// `>=` here would re-create the defect this issue is about in the other
+ /// direction: an expected-but-persistent state reported on every tick of a
+ /// 15-second timer, forever.
+ #[test]
+ fn not_discoverable_escalates_once_per_run_not_every_cycle() {
+ // Below the threshold: still quiet, so an ordinary boot (wallet locked
+ // for a cycle or two) costs nothing.
+ for cycles in 0..NOT_DISCOVERABLE_WARN_AFTER_CYCLES {
+ assert!(
+ !should_escalate_not_discoverable(cycles),
+ "cycle {cycles} is below the threshold and must stay at debug"
+ );
+ }
+ // Exactly at the threshold: the one escalated line.
+ assert!(
+ should_escalate_not_discoverable(NOT_DISCOVERABLE_WARN_AFTER_CYCLES),
+ "the threshold cycle must escalate so a stuck registration is visible"
+ );
+ // Above it: quiet again — one warn per run, not one per cycle.
+ for extra in 1..=20 {
+ let cycles = NOT_DISCOVERABLE_WARN_AFTER_CYCLES + extra;
+ assert!(
+ !should_escalate_not_discoverable(cycles),
+ "cycle {cycles} is past the threshold and must NOT escalate again"
+ );
+ }
+ }
}
diff --git a/src/openhuman/tinyplace/manifest.rs b/src/openhuman/tinyplace/manifest.rs
index 4d876c52f0..828e03a9a2 100644
--- a/src/openhuman/tinyplace/manifest.rs
+++ b/src/openhuman/tinyplace/manifest.rs
@@ -3190,6 +3190,28 @@ pub(crate) fn handle_tinyplace_signal_get_bundle(params: Map<String, Value>) ->
})
}
+/// Whether a failed relay read in [`handle_tinyplace_signal_key_status`] means
+/// "this agent has not published anything yet" rather than "the relay is unwell".
+///
+/// A 404 from `GET /keys/<id>/health` or `GET /directory/agents/<id>` is the
+/// **expected** answer for an agent whose Signal keys are not yet published —
+/// precisely the precondition [`ensure_signal_keys_published`] exists to
+/// remove, and which `handle_tinyplace_signal_register_encryption_key` repairs
+/// by building the card when the directory 404s. So a 404 here is the state the
+/// very next step fixes, not a fault.
+///
+/// This is the same classification the rest of this file already makes at six
+/// other sites (`Err(e) if e.status() == Some(404)`); the two probe arms below
+/// were the only ones that lacked it, which is why they logged at `warn` on the
+/// orchestration supervisor's 15-second timer forever (#5627).
+///
+/// Named rather than inlined so the rule is unit-testable without a relay —
+/// deliberately narrow: **only** 404. A 500 from a broken relay must stay
+/// warn-worthy, or a genuine outage becomes as quiet as a fresh install.
+pub(super) fn is_not_published_yet(e: &tinyplace::Error) -> bool {
+ e.status() == Some(404)
+}
+
/// Local + remote key status for the current user. Remote health degrades
/// gracefully if the backend is unreachable.
pub(crate) fn handle_tinyplace_signal_key_status(_params: Map<String, Value>) -> ControllerFuture {
@@ -3218,6 +3240,15 @@ pub(crate) fn handle_tinyplace_signal_key_status(_params: Map<String, Value>) ->
);
Some(h)
}
+ Err(e) if is_not_published_yet(&e) => {
+ // Expected on a fresh identity: no keys published yet, so the
+ // relay has no health record to return. `remote: null` is the
+ // correct answer and the supervisor's next cycle publishes.
+ log::debug!(
+ "{LOG_PREFIX} signal_key_status: no remote keys yet for {agent_id} (not published)"
+ );
+ None
+ }
Err(e) => {
log::warn!("{LOG_PREFIX} signal_key_status remote health fetch failed: {e}");
None
@@ -3261,6 +3292,15 @@ pub(crate) fn handle_tinyplace_signal_key_status(_params: Map<String, Value>) ->
log::debug!("{LOG_PREFIX} signal_key_status encryption_key_published={matches}");
matches
}
+ Ok(Err(e)) if is_not_published_yet(&e) => {
+ // Expected on a fresh identity: no directory card exists yet.
+ // `signal_register_encryption_key` builds one on this same 404,
+ // so this is the state the next step repairs, not a failure.
+ log::debug!(
+ "{LOG_PREFIX} signal_key_status: no directory card yet for {agent_id} (not published)"
+ );
+ false
+ }
Ok(Err(e)) => {
log::warn!("{LOG_PREFIX} signal_key_status directory card fetch failed: {e}");
false
diff --git a/src/openhuman/tinyplace/tests.rs b/src/openhuman/tinyplace/tests.rs
index ea4bdb191b..482fd56900 100644
--- a/src/openhuman/tinyplace/tests.rs
+++ b/src/openhuman/tinyplace/tests.rs
@@ -608,3 +608,71 @@ mod publish_directory_card_tests {
);
}
}
+
+// ── #5627: not-yet-published probe classification ─────────────────────────────
+
+#[cfg(test)]
+mod signal_key_status_probe_classification_tests {
+ use crate::openhuman::tinyplace::manifest::is_not_published_yet;
+ use tinyplace::error::HttpError;
+
+ fn http_err(status: u16, message: &str) -> tinyplace::Error {
+ tinyplace::Error::Http(Box::new(HttpError {
+ status,
+ message: message.to_string(),
+ body: serde_json::Value::Null,
+ headers: Default::default(),
+ payment_required: None,
+ }))
+ }
+
+ /// A 404 from either probe is the **expected** answer for an agent that has
+ /// not published its Signal keys yet — the precondition
+ /// `ensure_signal_keys_published` exists to remove, and which
+ /// `signal_register_encryption_key` repairs by building the card on this
+ /// same 404. Classified as not-published, it logs at `debug`; misclassified,
+ /// it logs at `warn` on the orchestration supervisor's 15-second timer
+ /// forever, on every instance (#5627).
+ #[test]
+ fn a_404_from_either_probe_is_not_published_yet() {
+ for path in [
+ "HTTP 404: /keys/EJXoqJp6CYtme1pJ8qT94avpsa5Ji3UdMZqdCH3MnvxE/health",
+ "HTTP 404: /directory/agents/EJXoqJp6CYtme1pJ8qT94avpsa5Ji3UdMZqdCH3MnvxE",
+ ] {
+ assert!(
+ is_not_published_yet(&http_err(404, path)),
+ "a 404 is the expected not-yet-published state, not a warning: {path}"
+ );
+ }
+ }
+
+ /// The demotion must stay narrow. A relay that is genuinely unwell has to
+ /// keep reaching `warn`, or a real outage becomes as quiet as a fresh
+ /// install — which is the failure mode of over-correcting this class of bug.
+ #[test]
+ fn any_other_status_stays_warn_worthy() {
+ for status in [400u16, 401, 403, 408, 429, 500, 502, 503, 504] {
+ assert!(
+ !is_not_published_yet(&http_err(status, "HTTP error: /keys/x/health")),
+ "HTTP {status} is not a not-yet-published state and must stay warn-worthy"
+ );
+ }
+ }
+
+ /// A non-HTTP failure has no status at all — `Error::status()` returns
+ /// `None` for every variant except `Http`. `None != Some(404)`, so these
+ /// must stay warn-worthy: a signer that cannot sign is a real fault, not an
+ /// agent that has simply not published yet.
+ #[test]
+ fn a_statusless_error_stays_warn_worthy() {
+ for err in [
+ tinyplace::Error::Signing("no signer available".to_string()),
+ tinyplace::Error::InvalidArgument("empty agent id".to_string()),
+ ] {
+ assert!(
+ !is_not_published_yet(&err),
+ "a statusless error is not a not-yet-published state: {err}"
+ );
+ }
+ }
+}