Skip to content

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

fix(config): a snapshot reload opens sealed secrets; empty keys stay empty

M3gA-Mindf73b525233a2
diff --git a/crates/openhuman-core/src/config/schema/load/impl_load.rs b/crates/openhuman-core/src/config/schema/load/impl_load.rs
index 83a1cf0215..3d098adefe 100644
--- a/crates/openhuman-core/src/config/schema/load/impl_load.rs
+++ b/crates/openhuman-core/src/config/schema/load/impl_load.rs
@@ -356,6 +356,20 @@ impl Config {
let migration_raw = migration_source(&config_path, &raw).await;
apply_loaded_config_migrations(&mut config, &migration_raw);
config.apply_env_overrides_from(env);
+ // Hand callers the same plaintext secrets the first load does. All or
+ // nothing: callers reload, edit and save, so a field that cannot be
+ // opened must stay sealed rather than be cleared and saved as `None`.
+ if let Some(openhuman_dir) = config.config_path.parent().map(Path::to_path_buf) {
+ let mut opened = config.clone();
+ match decrypt_config_secrets_strict(&mut opened, &openhuman_dir) {
+ Ok(()) => config = opened,
+ Err(error) => tracing::warn!(
+ path = %config.config_path.display(),
+ %error,
+ "[config] snapshot reload keeps secrets sealed"
+ ),
+ }
+ }
if config_was_corrupted {
tracing::warn!(
diff --git a/crates/openhuman-core/src/config/schema/load/secrets.rs b/crates/openhuman-core/src/config/schema/load/secrets.rs
index eb3bf3ba40..c57d214598 100644
--- a/crates/openhuman-core/src/config/schema/load/secrets.rs
+++ b/crates/openhuman-core/src/config/schema/load/secrets.rs
@@ -99,7 +99,8 @@ fn encrypt_optional_secret(
field_name: &str,
) -> Result<()> {
if let Some(raw) = value.clone() {
- if !crate::security::secret_storage::SecretStore::is_encrypted(&raw) {
+ // An empty value means "no key"; sealing it would make it look set.
+ if !raw.is_empty() && !crate::security::secret_storage::SecretStore::is_encrypted(&raw) {
*value = Some(
store
.encrypt(&raw)
diff --git a/crates/openhuman-core/src/config/schema/load/secrets_tests.rs b/crates/openhuman-core/src/config/schema/load/secrets_tests.rs
index c3a5dca070..ae9dcb2548 100644
--- a/crates/openhuman-core/src/config/schema/load/secrets_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load/secrets_tests.rs
@@ -92,6 +92,35 @@ fn an_empty_hosting_key_stays_empty() {
config.config_path = dir.path().join("config.toml");
config.secrets.encrypt = true;
+ config.integrations.tinyfish.api_key = Some(String::new());
+
encrypt_config_secrets(&mut config).unwrap();
assert_eq!(config.hosting.api_key, "");
+ assert_eq!(config.integrations.tinyfish.api_key.as_deref(), Some(""));
+}
+
+/// A snapshot reload, which Composio tools run on every call, opens sealed
+/// secrets just as the first load does.
+#[tokio::test]
+async fn a_snapshot_reload_opens_sealed_secrets() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = Config::default();
+ config.config_path = dir.path().join("config.toml");
+ config.secrets.encrypt = true;
+ config.composio.api_key = Some("composio-sentinel".into());
+ encrypt_config_secrets(&mut config).unwrap();
+ std::fs::write(
+ &config.config_path,
+ toml::to_string_pretty(&config).unwrap(),
+ )
+ .unwrap();
+
+ let reloaded =
+ Config::load_from_config_path(&config.config_path, &dir.path().join("workspace"))
+ .await
+ .unwrap();
+ assert_eq!(
+ reloaded.composio.api_key.as_deref(),
+ Some("composio-sentinel")
+ );
}