Skip to content

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

fix(profiles): cap retry_after_ms in gateway 409 refusals

Steven Enamakel4837f60daec5
diff --git a/crates/openhuman-core/src/profiles/gateway.rs b/crates/openhuman-core/src/profiles/gateway.rs
index 4f57634077..0e8aab898e 100644
--- a/crates/openhuman-core/src/profiles/gateway.rs
+++ b/crates/openhuman-core/src/profiles/gateway.rs
@@ -121,11 +121,14 @@ impl GatewayRefusal {
record.owner,
record.epoch
);
+ // A file-lock lease never expires (`u64::MAX`), so the raw
+ // value is no retry hint (and overflows a JSON consumer's
+ // safe integers); cap it.
Self {
status: 409,
message: PROFILE_HELD.to_string(),
held_by: Some(HeldBy {
- retry_after_ms: record.retry_after_ms(now_ms),
+ retry_after_ms: record.retry_after_ms(now_ms).min(MAX_RETRY_AFTER_MS),
owner: record.owner,
endpoint: record.endpoint,
}),
@@ -135,6 +138,9 @@ impl GatewayRefusal {
}
}
+/// The longest `retry_after_ms` a `409` reports.
+const MAX_RETRY_AFTER_MS: u64 = 60_000;
+
/// Where a gateway request runs.
#[derive(Debug)]
pub enum GatewayScope {
diff --git a/crates/openhuman-core/src/profiles/gateway_tests.rs b/crates/openhuman-core/src/profiles/gateway_tests.rs
index 5928f63800..b4194edd24 100644
--- a/crates/openhuman-core/src/profiles/gateway_tests.rs
+++ b/crates/openhuman-core/src/profiles/gateway_tests.rs
@@ -81,6 +81,19 @@ fn a_profile_held_elsewhere_is_a_409_naming_the_holder() {
);
}
+#[test]
+fn a_lease_that_never_expires_reports_a_capped_retry_hint() {
+ let record = crate::storage::lease::LeaseRecord {
+ owner: "node-a".into(),
+ endpoint: None,
+ epoch: 1,
+ expires_at_ms: u64::MAX,
+ released: false,
+ };
+ let refusal = GatewayRefusal::from_open_error(OpenError::HeldElsewhere(record), 4_000);
+ assert_eq!(refusal.held_by.unwrap().retry_after_ms, 60_000);
+}
+
#[test]
fn other_open_errors_keep_their_statuses() {
let alice = id("alice");
diff --git a/crates/openhuman-core/src/profiles/lease_tests.rs b/crates/openhuman-core/src/profiles/lease_tests.rs
index 96f0609c89..858607da05 100644
--- a/crates/openhuman-core/src/profiles/lease_tests.rs
+++ b/crates/openhuman-core/src/profiles/lease_tests.rs
@@ -194,11 +194,21 @@ async fn renewal_keeps_the_lease_and_a_lost_lease_fences_the_profile() {
.unwrap();
assert!(stolen.previous_unclean);
+ let mut events = crate::web_chat::subscribe_web_channel_events();
let report = renew_once(&a).await;
assert_eq!(report.fenced, vec![alice.clone()]);
assert!(state.is_fenced(), "the profile is fenced");
assert!(!a.is_open(&alice), "and closed");
assert!(turn.is_cancelled(), "its in-flight turns are stopped");
+ // The cancelled event goes to the client that started the turn, so its
+ // stream resolves rather than staying "running".
+ let mut cancelled_for = None;
+ while let Ok(event) = events.try_recv() {
+ if event.event == "chat_cancelled" && event.request_id == "req-1" {
+ cancelled_for = Some(event.client_id);
+ }
+ }
+ assert_eq!(cancelled_for.as_deref(), Some("test-client"));
}
#[tokio::test]