Skip to content

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

fix(memory): read a free-period answer still in its envelope

M3gA-Mindeafd7988ff73
diff --git a/crates/openhuman-core/src/memory/billing.rs b/crates/openhuman-core/src/memory/billing.rs
index 4f2cee7b34..752d660f91 100644
--- a/crates/openhuman-core/src/memory/billing.rs
+++ b/crates/openhuman-core/src/memory/billing.rs
@@ -92,9 +92,13 @@ async fn fetch(credential: &BackendCredential, backend: &str) -> Result<bool, St
parse_active(&data)
}
-/// `active` from the route's answer; anything else is an error.
+/// `active` from the route's answer; anything else is an error. The
+/// transport unwraps the `{success, data}` envelope, but an answer that
+/// still carries it is read the same way.
fn parse_active(data: &serde_json::Value) -> Result<bool, String> {
- data.get("active")
+ data.get("data")
+ .unwrap_or(data)
+ .get("active")
.and_then(serde_json::Value::as_bool)
.ok_or_else(|| "free-period answer has no boolean `active`".to_string())
}
diff --git a/crates/openhuman-core/src/memory/billing_tests.rs b/crates/openhuman-core/src/memory/billing_tests.rs
index 40037a4696..0bec73cb88 100644
--- a/crates/openhuman-core/src/memory/billing_tests.rs
+++ b/crates/openhuman-core/src/memory/billing_tests.rs
@@ -16,6 +16,12 @@ fn parse_active_reads_the_flag_and_refuses_anything_else() {
);
assert!(parse_active(&json!({"active": "yes"})).is_err());
assert!(parse_active(&json!({})).is_err());
+ assert_eq!(
+ parse_active(&json!({"success": true, "data": {"active": true}})),
+ Ok(true),
+ "an answer still in its envelope reads the same"
+ );
+ assert!(parse_active(&json!({"success": true, "data": {}})).is_err());
}
#[tokio::test]
@@ -143,7 +149,11 @@ fn credential(config: &Config) -> BackendCredential {
fn keyed_config(tmp: &tempfile::TempDir) -> Config {
let mut config = crate::memory::test_fixtures::config_in(tmp);
config.secrets.encrypt = false;
- crate::security::credentials::api_key::store_api_key(&config, "th_test_key").unwrap();
+ // A key of its own: the answer cache is process-wide and keyed by
+ // backend and credential, and a mock server may reuse a port another
+ // test's server held a moment ago.
+ let key = format!("th_test_{}", tmp.path().display()).replace(['/', '.'], "_");
+ crate::security::credentials::api_key::store_api_key(&config, &key).unwrap();
config
}