Skip to content

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

refactor(app_state): simplify snapshot controller binding

Steven Enamakel9d3f38ec4bf2
diff --git a/crates/openhuman-core/src/desktop/app_state/mod.rs b/crates/openhuman-core/src/desktop/app_state/mod.rs
index 9e36fbc287..b123ca976c 100644
--- a/crates/openhuman-core/src/desktop/app_state/mod.rs
+++ b/crates/openhuman-core/src/desktop/app_state/mod.rs
@@ -6,6 +6,7 @@ mod schemas;
pub use ops::*;
pub use recovery_signal::{config_recovered_this_session, latch_from_config};
+pub(crate) use schemas::all_app_state_controller_entries;
pub use schemas::{
all_app_state_controller_schemas, all_app_state_registered_controllers, app_state_schemas,
};
diff --git a/crates/openhuman-core/src/desktop/app_state/schemas.rs b/crates/openhuman-core/src/desktop/app_state/schemas.rs
index 97ec077d98..81f6402b2c 100644
--- a/crates/openhuman-core/src/desktop/app_state/schemas.rs
+++ b/crates/openhuman-core/src/desktop/app_state/schemas.rs
@@ -116,11 +116,7 @@ fn handle_update_local_state(ctx: DispatchCtx, params: Map<String, Value>) -> Co
}
fn snapshot_controller() -> BoundRegisteredController {
- BoundRegisteredController::typed(
- app_state_schemas("snapshot"),
- parse_snapshot,
- run_snapshot,
- )
+ BoundRegisteredController::typed(app_state_schemas("snapshot"), parse_snapshot, run_snapshot)
}
fn update_local_state_controller() -> BoundRegisteredController {
diff --git a/crates/openhuman-core/src/desktop/app_state/schemas_tests.rs b/crates/openhuman-core/src/desktop/app_state/schemas_tests.rs
index f9779ef46f..58e57e0864 100644
--- a/crates/openhuman-core/src/desktop/app_state/schemas_tests.rs
+++ b/crates/openhuman-core/src/desktop/app_state/schemas_tests.rs
@@ -3,6 +3,7 @@ use crate::core::all::{
assert_schema_controller_parity, expect_schema_identity, ControllerHandler,
ControllerParamContract,
};
+use serde_json::json;
#[test]
fn legacy_handlers_keep_their_identity_and_order() {
@@ -203,6 +204,49 @@ fn update_local_state_patch_preserves_array_to_struct_defaults() {
assert_eq!(consent.consented_at_ms, None);
}
+async fn runtime_app_state_entries() -> Vec<crate::core::all::ControllerEntry> {
+ use crate::core::runtime::{CoreContext, DomainSet};
+
+ CoreContext::scope(CoreContext::for_test(DomainSet::full(), None), async {
+ crate::core::all::all_registered_controllers()
+ .into_iter()
+ .filter(|entry| entry.schema.namespace == "app_state")
+ .collect()
+ })
+ .await
+}
+
+#[tokio::test]
+async fn update_local_state_rejects_malformed_params_before_loading_config() {
+ use crate::config::test_env::EnvVarGuard;
+ use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
+
+ let tmp = tempfile::tempdir().unwrap();
+ std::fs::create_dir(tmp.path().join("config.toml")).unwrap();
+ let _env = EnvVarGuard::workspace_async(tmp.path()).await;
+ let entries = runtime_app_state_entries().await;
+ let update = entries
+ .iter()
+ .find(|entry| entry.schema.method_name() == "app_state.update_local_state")
+ .expect("runtime app_state.update_local_state entry");
+
+ let error = update
+ .invoke(
+ DispatchCtx::new(CoreContext::for_test(DomainSet::full(), None)),
+ Map::from_iter([("encryptionKey".into(), json!(false))]),
+ )
+ .await
+ .expect_err("malformed parameters stop before app-state persistence loads config");
+ assert!(
+ error.starts_with("invalid params:"),
+ "update parser error takes precedence over config loading: {error}"
+ );
+ assert!(
+ !error.contains("config.toml"),
+ "the operation config loader was not reached: {error}"
+ );
+}
+
fn parse_update(value: serde_json::Value) -> Result<StoredAppStatePatch, String> {
parse_update_local_state(
value