Skip to content

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

fix(rpc): stamp replay timestamps on the event context

Steven Enamakel2743dfc2986e
diff --git a/crates/openhuman-rpc/src/server/socketio.rs b/crates/openhuman-rpc/src/server/socketio.rs
index bf50c43e18..1a3c0bee66 100644
--- a/crates/openhuman-rpc/src/server/socketio.rs
+++ b/crates/openhuman-rpc/src/server/socketio.rs
@@ -1256,7 +1256,7 @@ fn replay_parked_approval(socket: &SocketRef, thread_id: &str) {
// Replay is a fresh emit to a newly-joined socket, not a resend of the
// original event, so stamp `ts` with "now" (same clock as
// `publish_web_channel_event`) rather than leaving it unset.
- event.ts = Some(crate::core_host::web_chat::unix_epoch_ms());
+ stamp_replay_timestamp(&mut event);
let Ok(payload) = serde_json::to_value(&event) else {
continue;
};
@@ -1289,7 +1289,7 @@ fn replay_parked_plan_review(socket: &SocketRef, thread_id: &str) {
row.tool_call_id.as_deref(),
row.expires_at.as_deref(),
);
- event.ts = Some(crate::core_host::web_chat::unix_epoch_ms());
+ stamp_replay_timestamp(&mut event);
let Ok(payload) = serde_json::to_value(&event) else {
return;
};
@@ -1307,6 +1307,10 @@ fn emit_with_aliases(socket: &SocketRef, name: &str, payload: &serde_json::Value
}
}
+fn stamp_replay_timestamp(event: &mut crate::core_host::web_chat::WebChannelEvent) {
+ event.context_mut().ts = Some(crate::core_host::web_chat::unix_epoch_ms());
+}
+
// Every test here names a gated fn (`channel_connection_update_payload`,
// `event_alias`, `origin_is_allowed`), so the module gates in lockstep (#5048).
#[cfg(test)]
diff --git a/crates/openhuman-rpc/src/server/socketio_tests.rs b/crates/openhuman-rpc/src/server/socketio_tests.rs
index cd6ae1d5e4..1338316088 100644
--- a/crates/openhuman-rpc/src/server/socketio_tests.rs
+++ b/crates/openhuman-rpc/src/server/socketio_tests.rs
@@ -1,6 +1,6 @@
use super::{
channel_connection_update_payload, event_alias, origin_is_allowed_with_extra,
- publish_companion_state_changed, subscribe_companion_state_changed,
+ publish_companion_state_changed, stamp_replay_timestamp, subscribe_companion_state_changed,
};
#[test]
@@ -15,6 +15,25 @@ fn companion_state_transport_delivers_payload_to_bridge() {
assert_eq!(rx.try_recv().expect("payload delivered"), payload);
}
+#[test]
+fn replay_timestamp_is_stored_in_the_typed_event_context() {
+ let mut event = crate::core_host::web_chat::approval_request_event(
+ "request-1",
+ "read_file",
+ "inspect the document",
+ &serde_json::json!({}),
+ "thread-1",
+ "client-1",
+ None,
+ None,
+ false,
+ );
+
+ stamp_replay_timestamp(&mut event);
+
+ assert!(event.context().ts.is_some());
+}
+
#[test]
fn channel_connection_update_payload_connected_omits_error() {
let payload = channel_connection_update_payload("discord", "connected", None);