Skip to content

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

refactor(medulla): rename client EventEnvelope to WireEventEnvelope

shanuc373d49a2aad
diff --git a/src/embed/medulla.rs b/src/embed/medulla.rs
index 58cc2a695e..b6bd35c3a5 100644
--- a/src/embed/medulla.rs
+++ b/src/embed/medulla.rs
@@ -23,8 +23,8 @@ use super::error::CoreError;
use crate::core::runtime::CoreRuntime;
pub use crate::openhuman::medulla::client::{
- AbortResult, EventEnvelope, Message, RosterWorker, SendResult, SessionCreated, SessionDetail,
- SessionSummary,
+ AbortResult, Message, RosterWorker, SendResult, SessionCreated, SessionDetail, SessionSummary,
+ WireEventEnvelope,
};
pub use crate::openhuman::medulla::ops::MedullaStatus;
@@ -141,7 +141,7 @@ impl Medulla<'_> {
&self,
session_id: &str,
after: Option<i64>,
- ) -> Result<Vec<EventEnvelope>, CoreError> {
+ ) -> Result<Vec<WireEventEnvelope>, CoreError> {
call(
self.0,
"openhuman.medulla_list_events",
diff --git a/src/embed/mod.rs b/src/embed/mod.rs
index be244b4d3d..3b660b9d7e 100644
--- a/src/embed/mod.rs
+++ b/src/embed/mod.rs
@@ -68,8 +68,8 @@ pub use harness::{Access, Harness, HarnessBuilder, HarnessError, Provider, Works
pub use harness::{HttpHeader, McpAuthConfig, McpServer};
#[cfg(feature = "medulla")]
pub use medulla::{
- AbortResult, EventEnvelope, Medulla, MedullaStatus, Message, RosterWorker, SendResult,
- SessionCreated, SessionDetail, SessionSummary,
+ AbortResult, Medulla, MedullaStatus, Message, RosterWorker, SendResult, SessionCreated,
+ SessionDetail, SessionSummary, WireEventEnvelope,
};
use std::sync::Arc;
diff --git a/src/openhuman/medulla/client/sessions.rs b/src/openhuman/medulla/client/sessions.rs
index 5ee0149d15..63943032fa 100644
--- a/src/openhuman/medulla/client/sessions.rs
+++ b/src/openhuman/medulla/client/sessions.rs
@@ -100,7 +100,7 @@ impl MedullaClient {
&self,
session_id: &str,
after: Option<i64>,
- ) -> Result<Vec<EventEnvelope>> {
+ ) -> Result<Vec<WireEventEnvelope>> {
let mut req = self
.http
.get(self.url(&format!("/medulla/v1/sessions/{session_id}/events")));
@@ -129,7 +129,7 @@ impl MedullaClient {
&self,
session_id: &str,
last_event_id: Option<u64>,
- ) -> impl Stream<Item = Result<EventEnvelope>> {
+ ) -> impl Stream<Item = Result<WireEventEnvelope>> {
let url = format!(
"{}/medulla/v1/sessions/{}/stream?token={}",
self.base_url,
diff --git a/src/openhuman/medulla/client/sse/mod.rs b/src/openhuman/medulla/client/sse/mod.rs
index 4c65b2c0bc..1fcbdc1db4 100644
--- a/src/openhuman/medulla/client/sse/mod.rs
+++ b/src/openhuman/medulla/client/sse/mod.rs
@@ -11,7 +11,7 @@
//! ```
//!
//! `id:` sets the replay cursor (persisted events only; deltas omit it),
-//! `data:` carries the JSON [`EventEnvelope`], comment lines (`: ping`) are
+//! `data:` carries the JSON [`WireEventEnvelope`], comment lines (`: ping`) are
//! ignored, and a blank line terminates the current frame.
use std::collections::VecDeque;
@@ -19,7 +19,7 @@ use std::collections::VecDeque;
use futures::stream::{Stream, StreamExt};
use crate::openhuman::medulla::client::error::{ClientError, Result};
-use crate::openhuman::medulla::client::types::EventEnvelope;
+use crate::openhuman::medulla::client::types::WireEventEnvelope;
impl SseParser {
/// Create an empty parser.
@@ -151,7 +151,7 @@ impl StreamState {
if trimmed.is_empty() {
return;
}
- match serde_json::from_str::<EventEnvelope>(trimmed) {
+ match serde_json::from_str::<WireEventEnvelope>(trimmed) {
Ok(env) => self.pending.push_back(Ok(env)),
Err(e) => self
.pending
@@ -162,7 +162,7 @@ impl StreamState {
/// Produce the next stream item, reconnecting as needed. Returns `None`
/// only when the stream is permanently exhausted (never, in practice —
/// it reconnects on end-of-body).
- async fn next(&mut self) -> Option<Result<EventEnvelope>> {
+ async fn next(&mut self) -> Option<Result<WireEventEnvelope>> {
loop {
if let Some(item) = self.pending.pop_front() {
return Some(item);
@@ -196,7 +196,7 @@ impl StreamState {
}
}
-/// Build a reconnecting SSE stream of [`EventEnvelope`]s.
+/// Build a reconnecting SSE stream of [`WireEventEnvelope`]s.
///
/// `url` must already include auth (`?token=<jwt>`). The stream reconnects with
/// the `Last-Event-ID` header and de-duplicates replayed frames by seq. Drop
@@ -205,7 +205,7 @@ pub fn event_stream(
http: reqwest::Client,
url: String,
last_event_id: Option<u64>,
-) -> impl Stream<Item = Result<EventEnvelope>> {
+) -> impl Stream<Item = Result<WireEventEnvelope>> {
let state = StreamState {
http,
url,
diff --git a/src/openhuman/medulla/client/sse/types.rs b/src/openhuman/medulla/client/sse/types.rs
index 09de3aec1a..b0e6564196 100644
--- a/src/openhuman/medulla/client/sse/types.rs
+++ b/src/openhuman/medulla/client/sse/types.rs
@@ -35,7 +35,7 @@ pub(super) struct StreamState {
pub(super) url: String,
pub(super) parser: SseParser,
pub(super) dedup: SeqDedup,
- pub(super) pending: VecDeque<Result<EventEnvelope>>,
+ pub(super) pending: VecDeque<Result<WireEventEnvelope>>,
pub(super) body: Option<futures::stream::BoxStream<'static, reqwest::Result<Vec<u8>>>>,
pub(super) first_connect: bool,
}
diff --git a/src/openhuman/medulla/client/tests/decode_tests.rs b/src/openhuman/medulla/client/tests/decode_tests.rs
index df9dc96e62..21cdabe83a 100644
--- a/src/openhuman/medulla/client/tests/decode_tests.rs
+++ b/src/openhuman/medulla/client/tests/decode_tests.rs
@@ -8,7 +8,7 @@ use serde_json::{json, Value};
// Event envelope / kind decode fixtures
// ---------------------------------------------------------------------------
-fn envelope(event: Value) -> EventEnvelope {
+fn envelope(event: Value) -> WireEventEnvelope {
let raw = json!({
"seq": 5,
"at": 1234,
@@ -19,6 +19,36 @@ fn envelope(event: Value) -> EventEnvelope {
serde_json::from_value(raw).unwrap()
}
+#[test]
+fn wire_envelope_carries_session_and_cycle_ids() {
+ // The wire type is what `ops::list_events` returns; it must decode the
+ // `sessionId` / `cycleId` fields the in-process contract type lacks. This
+ // pins the distinction from `events::EventEnvelope` so a future edit cannot
+ // silently reintroduce the naming ambiguity (#6078).
+ let env: WireEventEnvelope = serde_json::from_value(json!({
+ "at": 42,
+ "sessionId": "sess-1",
+ "event": {"kind": "user", "body": "hi"},
+ }))
+ .unwrap();
+ assert_eq!(env.session_id, "sess-1");
+ assert_eq!(env.at, 42);
+ // `seq` and `cycleId` are optional on the wire.
+ assert_eq!(env.seq, None);
+ assert_eq!(env.cycle_id, None);
+
+ let with_optionals: WireEventEnvelope = serde_json::from_value(json!({
+ "seq": 7,
+ "at": 43,
+ "sessionId": "sess-1",
+ "cycleId": "cyc-9",
+ "event": {"kind": "assistant", "body": "yo"},
+ }))
+ .unwrap();
+ assert_eq!(with_optionals.seq, Some(7));
+ assert_eq!(with_optionals.cycle_id, Some("cyc-9".into()));
+}
+
#[test]
fn decodes_user_and_assistant() {
assert_eq!(
diff --git a/src/openhuman/medulla/client/types/event.rs b/src/openhuman/medulla/client/types/event.rs
index c5e105c873..217b61d75b 100644
--- a/src/openhuman/medulla/client/types/event.rs
+++ b/src/openhuman/medulla/client/types/event.rs
@@ -9,10 +9,16 @@ use serde_json::Value;
/// Envelope wrapping every event on the session stream.
///
-/// `event` retains the raw JSON payload; [`EventEnvelope::kind`] parses it into
-/// a typed [`EventKind`].
+/// This is the **wire** shape: it carries `sessionId` / `cycleId` and matches
+/// what `ops::list_events` returns over the RPC surface. Distinct from the
+/// in-process contract type `events::EventEnvelope`, which has neither field —
+/// the two are named apart so a consumer cannot build one where the other is
+/// expected (see #6078).
+///
+/// `event` retains the raw JSON payload; [`WireEventEnvelope::kind`] parses it
+/// into a typed [`EventKind`].
#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct EventEnvelope {
+pub struct WireEventEnvelope {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub seq: Option<u64>,
pub at: u64,
@@ -24,14 +30,14 @@ pub struct EventEnvelope {
pub event: Value,
}
-impl EventEnvelope {
+impl WireEventEnvelope {
/// Parse the raw `event` payload into a typed [`EventKind`].
pub fn kind(&self) -> EventKind {
EventKind::from_value(&self.event)
}
}
-/// Typed event payload parsed from [`EventEnvelope::event`].
+/// Typed event payload parsed from [`WireEventEnvelope::event`].
///
/// `Unknown` preserves the raw value for forward-compatibility with event
/// kinds this client does not yet model.
diff --git a/src/openhuman/medulla/client/types/mod.rs b/src/openhuman/medulla/client/types/mod.rs
index 3a09846fe5..6ed7d907a3 100644
--- a/src/openhuman/medulla/client/types/mod.rs
+++ b/src/openhuman/medulla/client/types/mod.rs
@@ -12,7 +12,7 @@ mod reward;
mod run;
mod session;
-pub use event::{EventEnvelope, EventKind};
+pub use event::{EventKind, WireEventEnvelope};
pub use reward::{
HistoryRewardBreakdown, HistoryRewardClaim, HistoryRewardStatus, HistoryUploadResult,
};
diff --git a/src/openhuman/medulla/ops.rs b/src/openhuman/medulla/ops.rs
index d25d078ab4..df34cfee4e 100644
--- a/src/openhuman/medulla/ops.rs
+++ b/src/openhuman/medulla/ops.rs
@@ -11,8 +11,8 @@ use crate::openhuman::config::Config;
use crate::rpc::{RpcOutcome, StructuredRpcError};
use super::client::{
- AbortResult, ClientError, EventEnvelope, MedullaClient, Message, RosterWorker, SendResult,
- SessionCreated, SessionDetail, SessionSummary,
+ AbortResult, ClientError, MedullaClient, Message, RosterWorker, SendResult, SessionCreated,
+ SessionDetail, SessionSummary, WireEventEnvelope,
};
use super::resolve::{self, NotConfigured};
@@ -163,7 +163,7 @@ pub async fn list_events(
config: &Config,
session_id: &str,
after: Option<i64>,
-) -> Result<RpcOutcome<Vec<EventEnvelope>>, String> {
+) -> Result<RpcOutcome<Vec<WireEventEnvelope>>, String> {
let client = resolved(config)?;
let events = call(
client.list_events(session_id, after).await,