Skip to content

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

fix(web_chat): correct turn timing to use wall clock instead of monotonic time

Steven Enamakel59c871d56263
diff --git a/crates/openhuman-core/src/commands/mod.rs b/crates/openhuman-core/src/commands/mod.rs
new file mode 100644
index 0000000000..e44c908c1b
--- /dev/null
+++ b/crates/openhuman-core/src/commands/mod.rs
@@ -0,0 +1,25 @@
+//! `commands` — read-only command-palette listing for the chat composer's
+//! slash-command menu (assistant-ui `composer-trigger-popover`, C5 of the
+//! `assistant-ui-elements` plan).
+//!
+//! `commands.list` merges the fixed built-in slash commands with the live
+//! skill and workflow catalogs (`skills.list` / `flows.list`), so the
+//! frontend has one call to populate the menu instead of three. It is
+//! deliberately read-only: naming a command here does not run it — a
+//! built-in still dispatches through whatever RPC the frontend already uses
+//! for it (`/plan` → `agent.set_run_mode`, etc.), and a skill/workflow
+//! dispatches through `skills.run` / `flows.run` as it always did.
+
+pub mod ops;
+pub mod schemas;
+pub mod types;
+
+pub use schemas::{all_controller_schemas as all_commands_controller_schemas, schemas};
+pub use types::{CommandEntry, CommandKind};
+
+use crate::core::all::RegisteredController;
+
+/// Registers `commands.list` with the controller registry (`core/all.rs`).
+pub fn all_commands_registered_controllers() -> Vec<RegisteredController> {
+ schemas::all_registered_controllers()
+}
diff --git a/crates/openhuman-core/src/web_chat/turn_timing.rs b/crates/openhuman-core/src/web_chat/turn_timing.rs
index 3cbafc3f18..fe746c55ee 100644
--- a/crates/openhuman-core/src/web_chat/turn_timing.rs
+++ b/crates/openhuman-core/src/web_chat/turn_timing.rs
@@ -108,3 +108,35 @@ impl TurnTimingSnapshot {
}
}
}
+
+/// Rate-limits the live `turn_cost` socket event the bridge emits on every
+/// `AgentProgress::TurnCostUpdated`: a multi-round turn can report one per
+/// model call, and a fast-tool-calling round can do that several times a
+/// second — far more often than a cost readout needs to repaint.
+pub(super) struct TurnCostThrottle {
+ last_emit: Option<std::time::Instant>,
+}
+
+/// Minimum spacing between live `turn_cost` emissions for one turn.
+const TURN_COST_EMIT_MIN_INTERVAL: std::time::Duration = std::time::Duration::from_millis(750);
+
+impl TurnCostThrottle {
+ pub(super) fn new() -> Self {
+ Self { last_emit: None }
+ }
+
+ /// Whether the caller should emit now. Unconditionally `true` on the
+ /// first call for a turn (`last_emit` still `None`) so the *first* cost
+ /// update always reaches the client immediately rather than waiting out
+ /// the interval. Advances `last_emit` on every `true` return.
+ pub(super) fn should_emit(&mut self) -> bool {
+ let should = self
+ .last_emit
+ .map(|at| at.elapsed() >= TURN_COST_EMIT_MIN_INTERVAL)
+ .unwrap_or(true);
+ if should {
+ self.last_emit = Some(std::time::Instant::now());
+ }
+ should
+ }
+}