Skip to content

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

chore(config): migrate legacy config schema on load

Steven Enamakel160566acb474
diff --git a/crates/openhuman-core/src/config/schema/load/migrate.rs b/crates/openhuman-core/src/config/schema/load/migrate.rs
index a8cb802e83..df89487550 100644
--- a/crates/openhuman-core/src/config/schema/load/migrate.rs
+++ b/crates/openhuman-core/src/config/schema/load/migrate.rs
@@ -337,6 +337,25 @@ pub(crate) fn migrate_components_with(config: &mut Config, raw: &str, tinymemes:
// The old tool-output compaction master switch, `[tokenjuice]
// router_enabled = false`, becomes `[components] juice = false`. The
// switch stays as a sub-setting of the on state.
+ // Voice had three independent switches (`[dictation] enabled`,
+ // `[voice_server] auto_start`, `always_on_enabled`). Only a config that
+ // names all three and has every one off says "no voice at all"; any other
+ // mix keeps the component on, so the old keys keep working for a release.
+ let voice_flag = |table: &str, key: &str| {
+ value
+ .as_ref()
+ .and_then(|v| v.get(table))
+ .and_then(|t| t.get(key))
+ .and_then(toml::Value::as_bool)
+ };
+ let voice_flags = [
+ voice_flag("dictation", "enabled"),
+ voice_flag("voice_server", "auto_start"),
+ voice_flag("voice_server", "always_on_enabled"),
+ ];
+ if voice_flags.iter().all(|f| *f == Some(false)) {
+ disable(config, "voice", Some(false));
+ }
let router_enabled = value
.as_ref()
.and_then(|v| v.get("tokenjuice"))
diff --git a/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs b/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs
index 37769adcfa..1457fffcc9 100644
--- a/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_components_migration_tests.rs
@@ -132,3 +132,33 @@ fn juice_migration_round_trip_is_idempotent() {
assert!(!second.components.juice);
assert_eq!(saved, toml::to_string(&second).unwrap());
}
+
+#[test]
+fn voice_switches_all_explicitly_off_disable_the_voice_component() {
+ let c = migrated(
+ "[dictation]\nenabled = false\n[voice_server]\nauto_start = false\nalways_on_enabled = false\n",
+ None,
+ );
+ assert!(!c.components.voice);
+ assert!(c.components.flows, "others stay on");
+}
+
+#[test]
+fn voice_stays_on_when_any_legacy_voice_switch_is_on_or_unset() {
+ let c = migrated(
+ "[dictation]\nenabled = true\n[voice_server]\nauto_start = false\nalways_on_enabled = false\n",
+ None,
+ );
+ assert!(c.components.voice);
+ let c = migrated("[voice_server]\nauto_start = false\n", None);
+ assert!(c.components.voice, "unset keys are not an opt-out");
+}
+
+#[test]
+fn explicit_components_voice_wins_over_legacy_voice_switches() {
+ let c = migrated(
+ "[components]\nvoice = true\n[dictation]\nenabled = false\n[voice_server]\nauto_start = false\nalways_on_enabled = false\n",
+ None,
+ );
+ assert!(c.components.voice);
+}
diff --git a/crates/openhuman-core/src/security/credentials/ops/gated_services.rs b/crates/openhuman-core/src/security/credentials/ops/gated_services.rs
index 07233600ee..e6d6b358e2 100644
--- a/crates/openhuman-core/src/security/credentials/ops/gated_services.rs
+++ b/crates/openhuman-core/src/security/credentials/ops/gated_services.rs
@@ -132,7 +132,7 @@ pub async fn start_credential_gated_services(config: &Config) {
tokio::spawn(async move {
let step = std::time::Instant::now();
crate::voice::server::start_if_enabled(&config).await;
- if !config.voice_server.auto_start {
+ if !config.voice_server.auto_start && config.components.voice {
crate::voice::dictation_listener::start_if_enabled(&config).await;
}
log::debug!(
diff --git a/crates/openhuman-core/src/voice/always_on/processor.rs b/crates/openhuman-core/src/voice/always_on/processor.rs
index 29bbaabe2f..942d6bbdfb 100644
--- a/crates/openhuman-core/src/voice/always_on/processor.rs
+++ b/crates/openhuman-core/src/voice/always_on/processor.rs
@@ -72,6 +72,11 @@ const MAX_UTTERANCE_SAMPLES: usize = TARGET_SAMPLE_RATE as usize * 60;
/// routes each finished utterance through STT and the dictation delivery bus (so
/// it reaches the agent exactly like a hotkey dictation, and lights up the notch).
pub async fn start_if_enabled(app_config: &Config) {
+ if !app_config.components.voice {
+ log::info!("{LOG_PREFIX} [components].voice is off — always-on stays down");
+ shutdown().await;
+ return;
+ }
if !app_config.voice_server.always_on_enabled {
shutdown().await;
return;
diff --git a/crates/openhuman-core/src/voice/dictation_listener.rs b/crates/openhuman-core/src/voice/dictation_listener.rs
index 463133f5be..b88872ed30 100644
--- a/crates/openhuman-core/src/voice/dictation_listener.rs
+++ b/crates/openhuman-core/src/voice/dictation_listener.rs
@@ -107,6 +107,10 @@ pub fn publish_transcription(text: String) -> usize {
/// (main-thread-safe) and emits `dictation://toggle` to the frontend, making
/// the core-side rdev listener redundant on macOS. (#2677)
pub async fn start_if_enabled(config: &Config) {
+ if !config.components.voice {
+ log::info!("{LOG_PREFIX} [components].voice is off, skipping hotkey listener");
+ return;
+ }
if !config.dictation.enabled {
log::info!("{LOG_PREFIX} dictation disabled in config, skipping hotkey listener");
return;
diff --git a/crates/openhuman-core/src/voice/server/singleton.rs b/crates/openhuman-core/src/voice/server/singleton.rs
index 6128ee742e..321c6e3590 100644
--- a/crates/openhuman-core/src/voice/server/singleton.rs
+++ b/crates/openhuman-core/src/voice/server/singleton.rs
@@ -33,6 +33,10 @@ pub fn try_global_server() -> Option<Arc<VoiceServer>> {
/// and reuses the process-global singleton so RPC status/stop calls continue to
/// operate on the same instance.
pub async fn start_if_enabled(app_config: &Config) {
+ if !app_config.components.voice {
+ info!("{LOG_PREFIX} [components].voice is off, skipping embedded voice server");
+ return;
+ }
if !app_config.voice_server.auto_start {
info!("{LOG_PREFIX} auto-start disabled in config, skipping embedded voice server");
return;