Skip to content

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

feat(tinymemes): build-time default, bridge helper, coverage row

killbillbf9081f82175
diff --git a/crates/openhuman-core/src/tinymemes/arm.rs b/crates/openhuman-core/src/tinymemes/arm.rs
index 55765d72a9..e9ee5c5e5b 100644
--- a/crates/openhuman-core/src/tinymemes/arm.rs
+++ b/crates/openhuman-core/src/tinymemes/arm.rs
@@ -10,9 +10,18 @@
//! Assignment is by a stable hash of the thread id, so a thread keeps its arm
//! for its whole life and across restarts. The flag is read on every turn, so
//! it can change without a restart.
+//!
+//! A build can ship with a different default: set `OPENHUMAN_TINYMEMES_DEFAULT`
+//! (same values) in the environment of the `cargo build` that produces the
+//! release, and it is baked in. The runtime `OPENHUMAN_TINYMEMES` still wins
+//! whenever it is set, so a deployment can always be switched back off.
pub(crate) const FLAG_ENV: &str = "OPENHUMAN_TINYMEMES";
+/// Default baked in at build time (`OPENHUMAN_TINYMEMES_DEFAULT` during
+/// `cargo build`); `None` means off.
+const BUILD_DEFAULT: Option<&str> = option_env!("OPENHUMAN_TINYMEMES_DEFAULT");
+
/// Parsed flag value.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Mode {
@@ -63,7 +72,15 @@ pub(crate) fn mode_from(value: Option<&str>) -> Mode {
}
pub(crate) fn mode() -> Mode {
- mode_from(std::env::var(FLAG_ENV).ok().as_deref())
+ resolve_mode(std::env::var(FLAG_ENV).ok().as_deref(), BUILD_DEFAULT)
+}
+
+/// The runtime value when set, else the build-time default, else off.
+pub(crate) fn resolve_mode(runtime: Option<&str>, build_default: Option<&str>) -> Mode {
+ match runtime {
+ Some(value) => mode_from(Some(value)),
+ None => mode_from(build_default),
+ }
}
/// Stable 0..100 bucket for a thread (FNV-1a, so it does not change between
diff --git a/crates/openhuman-core/src/tinymemes/arm_tests.rs b/crates/openhuman-core/src/tinymemes/arm_tests.rs
index 51da0d392f..6cf0e7b814 100644
--- a/crates/openhuman-core/src/tinymemes/arm_tests.rs
+++ b/crates/openhuman-core/src/tinymemes/arm_tests.rs
@@ -39,3 +39,16 @@ fn bucket_is_fixed_across_builds() {
assert_eq!(bucket("thread-abc"), bucket("thread-abc"));
assert_eq!(bucket(""), (0xcbf2_9ce4_8422_2325_u64 % 100) as u8);
}
+
+#[test]
+fn runtime_flag_overrides_the_build_default() {
+ assert_eq!(resolve_mode(None, None), Mode::Off);
+ assert_eq!(resolve_mode(None, Some("on")), Mode::On);
+ assert_eq!(resolve_mode(None, Some("ab:30")), Mode::Ab { percent: 30 });
+ // A deployment can always switch a shipped default back off.
+ assert_eq!(resolve_mode(Some("off"), Some("on")), Mode::Off);
+ assert_eq!(
+ resolve_mode(Some("ab"), Some("on")),
+ Mode::Ab { percent: 50 }
+ );
+}
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rs
index 71868350d9..896b1345bd 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs
@@ -14,6 +14,8 @@ use super::types::ChatRequestMetadata;
#[path = "progress_bridge_subagent_events.rs"]
mod subagent_events;
+#[path = "progress_bridge_text_events.rs"]
+mod text_events;
use subagent_events::BridgeCtx;
/// Cadence of the `inference_heartbeat` liveness beat the bridge emits while a
@@ -333,22 +335,16 @@ pub(crate) fn spawn_progress_bridge(
std::sync::Mutex<Option<super::turn_timing::TurnTimingSnapshot>>,
> = std::sync::Arc::new(std::sync::Mutex::new(None));
let timing_snapshot_for_task = timing_snapshot.clone();
- let hold_text_stream = metadata.hold_text_stream;
crate::core::runtime::spawn_scoped(async move {
- if hold_text_stream {
- log::debug!(
- "[web_channel][bridge] holding text_delta stream (reply is post-processed) request_id={}",
- request_id
- );
- }
log::debug!(
- "[web_channel][bridge] spawned client_id={} thread_id={} request_id={} speak_reply={:?} source={:?} session_id={:?}",
+ "[web_channel][bridge] spawned client_id={} thread_id={} request_id={} speak_reply={:?} source={:?} session_id={:?} hold_text_stream={}",
client_id,
thread_id,
request_id,
metadata.speak_reply,
metadata.source,
metadata.session_id,
+ metadata.hold_text_stream,
);
let mut round: u32 = 0;
let mut parent_max_iterations: u32 = 0;
@@ -1035,19 +1031,14 @@ pub(crate) fn spawn_progress_bridge(
// Buffer the round's narration so it can be flushed as an
// interim bubble if a tool call closes this round.
pending_narration.push_str(&delta);
- if !hold_text_stream {
- publish_seq_stamped(
+ if !metadata.hold_text_stream {
+ text_events::publish_text_delta(
&mut emit_seq,
- WebChannelEvent {
- event: "text_delta".to_string(),
- client_id: client_id.clone(),
- thread_id: thread_id.clone(),
- request_id: request_id.clone(),
- round: Some(iteration),
- delta: Some(delta),
- delta_kind: Some("text".to_string()),
- ..Default::default()
- },
+ &client_id,
+ &thread_id,
+ &request_id,
+ iteration,
+ delta,
);
}
}
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge_text_events.rs b/crates/openhuman-core/src/web_chat/progress_bridge_text_events.rs
new file mode 100644
index 0000000000..8e7d88f81c
--- /dev/null
+++ b/crates/openhuman-core/src/web_chat/progress_bridge_text_events.rs
@@ -0,0 +1,29 @@
+//! The parent agent's streamed answer text, as `text_delta` socket events.
+//!
+//! Kept out of the bridge loop so a held stream (`hold_text_stream`, set for
+//! threads whose final reply is post-processed) is a one-line guard there.
+
+use crate::web_chat::WebChannelEvent;
+
+pub(super) fn publish_text_delta(
+ emit_seq: &mut u64,
+ client_id: &str,
+ thread_id: &str,
+ request_id: &str,
+ round: u32,
+ delta: String,
+) {
+ super::publish_seq_stamped(
+ emit_seq,
+ WebChannelEvent {
+ event: "text_delta".to_string(),
+ client_id: client_id.to_string(),
+ thread_id: thread_id.to_string(),
+ request_id: request_id.to_string(),
+ round: Some(round),
+ delta: Some(delta),
+ delta_kind: Some("text".to_string()),
+ ..Default::default()
+ },
+ );
+}
diff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.md
index 56799b7f3f..912c69794f 100644
--- a/docs/TEST-COVERAGE-MATRIX.md
+++ b/docs/TEST-COVERAGE-MATRIX.md
@@ -197,6 +197,7 @@ Local inference runs against a runtime the user installs, starts, and pulls mode
| 4.2.10 | Durable agent reply (core stores it before announcing `chat_done`) | RU+VU | `crates/openhuman-core/src/web_chat/reply_persistence_tests.rs`, `crates/openhuman-core/src/web_chat/presentation_tests.rs`, `app/src/providers/__tests__/ChatRuntimeProvider.test.tsx` | ✅ | `deliver_response` persists an unsegmented reply under `agent:<request_id>` before publishing the terminal event, so a dropped socket, a failed `threads_message_append` or a reloaded webview costs a repaint rather than the answer; the client's append collapses onto that row by id. RU covers the write, its idempotency, the empty-reply and missing-thread paths, and that delivery still announces when the store refuses. VU covers the mirrored id, the segmented exception, the refetch that recovers a failed append, and the reconnect that rejoins orphaned thread rooms. WD E2E (kill the append mid-turn) is a follow-up |
| 4.2.11 | Links open in the default browser; the main webview never loads a remote page | RU+VU+MS | `crates/openhuman-app/src/external_navigation_tests.rs`, `app/src/utils/openUrl.test.ts`, `app/src/utils/externalLinkGuard.test.ts`, `app/src/components/Announcement/AnnouncementModal.test.tsx`, release-manual-smoke | 🟡 | RU covers the shell's navigation policy: remote http(s) navigation of `main` is cancelled and handed to the OS opener; `tauri://localhost`, `tauri.localhost`, `about:`/`data:`/`blob:` and the `tauri dev` server stay in the webview; other webviews are untouched. VU covers `openUrl` never falling back to `window.open` in the desktop shell (including the IPC bridge bootstrap gap) and the click guard. Real macOS click verified manually; automated desktop E2E is a follow-up (the WDIO desktop runner still assumes CEF) |
| 4.2.12 | Live stream renders like the reopened thread (parity, append-only, atomic settle) | VU+WD | `app/src/providers/__tests__/liveHistoryParity.test.tsx`, `app/src/store/__tests__/chatRuntimeSlice.liveParity.test.ts`, `app/src/features/conversations/derived/mapDisplayItems.test.ts`, `app/src/services/chatDeltaCoalescer.test.ts`, `app/src/features/conversations/components/AssistantUiToolCall.disclosure.test.tsx`, `app/src/components/assistant-ui/elements/reasoning-panel.test.tsx`, `app/src/components/assistant-ui/thread.followBottom.test.tsx`, `chat-live-history-parity.spec.ts` | ✅ | One scripted turn (`app/src/test/fixtures/streamedTurn.ts`) is told as socket events and as the core transcript. VU drives it through the real socket handlers: the settled reply equals the reload projection, the tail is append-only while it streams, and `chat_done` swaps tail for reply in one store update at one index. Also covered: in-place sub-agent promotion on both sides, args-delta row adoption, a superseded settle, frame-coalesced deltas, disclosure state across remounts, and following that survives a collapse. WD samples the real DOM while streaming, checks the viewport still follows, and compares with the reopened thread |
+| 4.2.13 | Final-reply remix with region slang and memes (TinyMemes, `OPENHUMAN_TINYMEMES` off/on/ab) | RU+VU | `crates/openhuman-core/src/tinymemes/arm_tests.rs`, `crates/openhuman-core/src/tinymemes/host_tests.rs`, `crates/openhuman-core/src/tinymemes/inference_tests.rs`, `crates/openhuman-core/src/web_chat/progress_bridge_tests.rs::hold_text_stream_suppresses_text_delta_but_keeps_interim`, `app/src/components/markdown/MarkdownImage.test.tsx` | 🟡 | Off by default. RU covers the flag (runtime value over the build-time default), stable per-thread A/B buckets, delivered-history conversion with remixed turns tagged, OpenRouter reasoning-off routing, and that treatment threads hold `text_delta` while interim narration still flushes. VU covers capped, lazy, no-referrer meme images. The engine itself (Jev reading, rating, rewrite, meme and slang vetting) is tested in `tinyhumansai/tinymemes`. WD E2E of a remixed turn is a follow-up |
### 4.3 Tool Invocation
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index cf3c9a9005..030e09426d 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -47,7 +47,7 @@ const LEGACY_LIMIT_ENTRIES = [
["crates/openhuman-core/src/agent/subagent_host/lifecycle.rs", 1309],
["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 1150],
["crates/openhuman-core/src/tools/ops.rs", 1209],
- ["crates/openhuman-core/src/web_chat/progress_bridge.rs", 1304],
+ ["crates/openhuman-core/src/web_chat/progress_bridge.rs", 1299],
// These established external test modules grew with upstream coverage. Pin
// their current sizes while follow-up work separates their test concerns.
// `core/` was pruned from the line limit by name until these pins; its