Skip to content

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

fix(web_chat): publish late sub-agent events without a sequence

M3gA-Mindb947a901bf89
diff --git a/crates/openhuman-core/src/web_chat/surface.rs b/crates/openhuman-core/src/web_chat/surface.rs
index 49e316c075..e8bd8d7351 100644
--- a/crates/openhuman-core/src/web_chat/surface.rs
+++ b/crates/openhuman-core/src/web_chat/surface.rs
@@ -39,6 +39,7 @@ pub(crate) struct Surface {
ctx: DispatchCtx,
scope_key: String,
ids: TurnIds,
+ sequenced: bool,
}
impl Surface {
@@ -74,9 +75,19 @@ impl Surface {
ctx: ctx.clone(),
scope_key,
ids,
+ sequenced: true,
}
}
+ /// Publish this surface's projections without the module's `seq`. A late
+ /// event projected after the turn's own projection closed gets a fresh
+ /// module handle whose sequence restarts, and clients drop an event whose
+ /// `seq` is not above the last one they saw for the request.
+ pub(crate) fn unsequenced(mut self) -> Self {
+ self.sequenced = false;
+ self
+ }
+
/// A host-authored terminal event does not need a module handle when the
/// turn never started canonical progress.
pub(crate) fn host_only(ctx: &DispatchCtx, ids: TurnIds) -> Self {
@@ -100,6 +111,7 @@ impl Surface {
ctx: ctx.clone(),
scope_key,
ids,
+ sequenced: true,
}
}
@@ -234,7 +246,10 @@ impl Surface {
}
};
let terminal = projected.events.iter().any(is_terminal);
- for event in projected.events {
+ for mut event in projected.events {
+ if !self.sequenced {
+ event.context_mut().seq = None;
+ }
self.publish(event, interim_round, true);
}
if terminal {
diff --git a/crates/openhuman-core/src/web_chat/turn_host_progress.rs b/crates/openhuman-core/src/web_chat/turn_host_progress.rs
index 99c3a1549e..53cbcc9318 100644
--- a/crates/openhuman-core/src/web_chat/turn_host_progress.rs
+++ b/crates/openhuman-core/src/web_chat/turn_host_progress.rs
@@ -150,7 +150,8 @@ impl LateSubagentSink {
};
// The turn's own projection is closed, so the event gets a projection
// turn of its own: the module still owns the wire form, including the
- // child's output and spend a detached completion carries.
+ // child's output and spend a detached completion carries. Its restarted
+ // sequence would fall below the turn's, so it is published without one.
let surface = super::super::surface::Surface::new(
ctx,
super::super::surface::TurnIds {
@@ -160,7 +161,8 @@ impl LateSubagentSink {
},
self.config.clone(),
)
- .await;
+ .await
+ .unsequenced();
surface.output(output).await;
surface.close().await;
}
diff --git a/crates/openhuman-core/src/web_chat/turn_host_tests.rs b/crates/openhuman-core/src/web_chat/turn_host_tests.rs
index a6cf909429..00def0657a 100644
--- a/crates/openhuman-core/src/web_chat/turn_host_tests.rs
+++ b/crates/openhuman-core/src/web_chat/turn_host_tests.rs
@@ -179,6 +179,7 @@ async fn a_late_subagent_failure_is_published_after_the_runner_is_gone() {
let wire = serde_json::to_value(&event).expect("wire event");
assert_eq!(wire["skill_id"], "task-late");
assert_eq!(wire["success"], false);
+ assert_eq!(event.context().seq, None);
}
/// A child's completion can queue behind a backlog the runner never reads: at
@@ -244,6 +245,8 @@ async fn a_completion_queued_behind_a_full_runner_channel_is_still_published() {
assert_eq!(wire["skill_id"], "task-late-done");
assert_eq!(wire["success"], true);
assert_eq!(wire["subagent"]["output"], "final answer");
+ // Unsequenced, so a client that saw the turn's higher seq does not drop it.
+ assert_eq!(event.context().seq, None);
}
#[tokio::test]