Skip to content

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

fix(session): correct credential expiry handling in cache and manager

Steven Enamakel59e13241dd1d
diff --git a/crates/openhuman-tinyhumans/src/session/cache.rs b/crates/openhuman-tinyhumans/src/session/cache.rs
index d8fc581329..f8044c7a02 100644
--- a/crates/openhuman-tinyhumans/src/session/cache.rs
+++ b/crates/openhuman-tinyhumans/src/session/cache.rs
@@ -13,8 +13,8 @@ use std::time::{Duration, Instant};
use serde_json::Value;
-use crate::client::{FetchMeError, SessionClient};
-use crate::credential::Credential;
+use crate::session::client::{FetchMeError, SessionClient};
+use crate::session::credential::Credential;
const LOG_PREFIX: &str = "[session][cache]";
diff --git a/crates/openhuman-tinyhumans/src/session/cache_tests.rs b/crates/openhuman-tinyhumans/src/session/cache_tests.rs
index 866fcc8577..766f87a8f7 100644
--- a/crates/openhuman-tinyhumans/src/session/cache_tests.rs
+++ b/crates/openhuman-tinyhumans/src/session/cache_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use crate::client::ClientHeaders;
-use crate::test_support::{me_user, Backend, MeAnswer, LIVE_JWT};
+use crate::session::client::ClientHeaders;
+use crate::session::test_support::{me_user, Backend, MeAnswer, LIVE_JWT};
use serde_json::json;
fn client(backend: &Backend) -> SessionClient {
diff --git a/crates/openhuman-tinyhumans/src/session/client.rs b/crates/openhuman-tinyhumans/src/session/client.rs
index e35a54bea6..8b78f4abb2 100644
--- a/crates/openhuman-tinyhumans/src/session/client.rs
+++ b/crates/openhuman-tinyhumans/src/session/client.rs
@@ -9,7 +9,7 @@ use serde_json::Value;
use tinyhumans_sdk::api::types::LoginTokenRequest;
use tinyhumans_sdk::TinyHumansClient;
-use crate::credential::{Credential, CredentialKind};
+use crate::session::credential::{Credential, CredentialKind};
const LOG_PREFIX: &str = "[session][client]";
@@ -251,7 +251,7 @@ impl SessionClient {
base.set_query(None);
base.set_fragment(None);
- let http = crate::tls::client_builder()
+ let http = openhuman_core::util::tls::tls_client_builder()
.http1_only()
.timeout(REQUEST_TIMEOUT)
.connect_timeout(CONNECT_TIMEOUT)
diff --git a/crates/openhuman-tinyhumans/src/session/client_tests.rs b/crates/openhuman-tinyhumans/src/session/client_tests.rs
index 266b6749af..dc08ad8987 100644
--- a/crates/openhuman-tinyhumans/src/session/client_tests.rs
+++ b/crates/openhuman-tinyhumans/src/session/client_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::test_support::{me_user, Backend, MeAnswer, ENV_LOCK, LIVE_JWT};
+use crate::session::test_support::{me_user, Backend, MeAnswer, ENV_LOCK, LIVE_JWT};
use serde_json::json;
fn headers() -> ClientHeaders {
diff --git a/crates/openhuman-tinyhumans/src/session/credential_tests.rs b/crates/openhuman-tinyhumans/src/session/credential_tests.rs
index 8a3b27e86f..923be93133 100644
--- a/crates/openhuman-tinyhumans/src/session/credential_tests.rs
+++ b/crates/openhuman-tinyhumans/src/session/credential_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::test_support::{EXPIRED_JWT, LIVE_JWT, LIVE_JWT_NO_SUB, LOCAL_TOKEN, OPAQUE_TOKEN};
+use crate::session::test_support::{EXPIRED_JWT, LIVE_JWT, LIVE_JWT_NO_SUB, LOCAL_TOKEN, OPAQUE_TOKEN};
use serde_json::json;
#[test]
diff --git a/crates/openhuman-tinyhumans/src/session/link.rs b/crates/openhuman-tinyhumans/src/session/link.rs
index def625ca80..5085164992 100644
--- a/crates/openhuman-tinyhumans/src/session/link.rs
+++ b/crates/openhuman-tinyhumans/src/session/link.rs
@@ -6,7 +6,7 @@ use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
-use crate::credential::{Credential, CredentialKind};
+use crate::session::credential::{Credential, CredentialKind};
const LOG_PREFIX: &str = "[session][link]";
diff --git a/crates/openhuman-tinyhumans/src/session/link_tests.rs b/crates/openhuman-tinyhumans/src/session/link_tests.rs
index 147fbc6202..94d18422d2 100644
--- a/crates/openhuman-tinyhumans/src/session/link_tests.rs
+++ b/crates/openhuman-tinyhumans/src/session/link_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::test_support::FakeCore;
+use crate::session::test_support::FakeCore;
#[test]
fn unwrap_envelope_walks_result_and_data() {
diff --git a/crates/openhuman-tinyhumans/src/session/manager.rs b/crates/openhuman-tinyhumans/src/session/manager.rs
index b36ac562b2..e906a48785 100644
--- a/crates/openhuman-tinyhumans/src/session/manager.rs
+++ b/crates/openhuman-tinyhumans/src/session/manager.rs
@@ -13,14 +13,14 @@ use serde_json::{json, Value};
use tokio::sync::broadcast;
use tokio::task::JoinHandle;
-use crate::cache::{CachedUser, CurrentUserCache};
-use crate::client::{ClientHeaders, FetchMeError, SessionClient};
-use crate::credential::{
+use crate::session::cache::{CachedUser, CurrentUserCache};
+use crate::session::client::{ClientHeaders, FetchMeError, SessionClient};
+use crate::session::credential::{
decode_jwt_exp, jwt_is_live, user_id_from_jwt_claims, user_id_from_profile_payload, Credential,
CredentialKind,
};
-use crate::identity;
-use crate::link::{self, CoreAuthState, CoreLink};
+use crate::session::identity;
+use crate::session::link::{self, CoreAuthState, CoreLink};
const LOG_PREFIX: &str = "[session][manager]";
diff --git a/crates/openhuman-tinyhumans/src/session/manager_tests.rs b/crates/openhuman-tinyhumans/src/session/manager_tests.rs
index a11719d618..ea0633cacb 100644
--- a/crates/openhuman-tinyhumans/src/session/manager_tests.rs
+++ b/crates/openhuman-tinyhumans/src/session/manager_tests.rs
@@ -1,7 +1,7 @@
use super::*;
-use crate::client::ClientHeaders;
-use crate::test_support::ENV_LOCK;
-use crate::test_support::{
+use crate::session::client::ClientHeaders;
+use crate::session::test_support::ENV_LOCK;
+use crate::session::test_support::{
me_user, Backend, FakeCore, MeAnswer, StoredCredential, EXPIRED_JWT, LIVE_JWT, LIVE_JWT_NO_SUB,
LOCAL_TOKEN, OPAQUE_TOKEN,
};
@@ -344,7 +344,7 @@ async fn current_user_serves_the_stored_user_stale_while_the_backend_is_down() {
async fn current_user_confirms_a_pending_session_once_the_backend_answers() {
let backend = Backend::start(vec![MeAnswer::Ok(me_user())]).await;
let core = FakeCore::new(&backend.url);
- *core.session.lock().unwrap() = Some(crate::test_support::StoredCredential {
+ *core.session.lock().unwrap() = Some(crate::session::test_support::StoredCredential {
kind: "session".into(),
token: LIVE_JWT.clone(),
user_id: Some("user-123".into()),
@@ -380,9 +380,9 @@ async fn rejection_of_a_superseded_token_leaves_the_new_session_alone() {
tokio::spawn(async move { m.current_user(true).await })
};
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
- let replacement = crate::test_support::StoredCredential {
+ let replacement = crate::session::test_support::StoredCredential {
kind: "session".into(),
- token: crate::test_support::LIVE_JWT_NO_SUB.clone(),
+ token: crate::session::test_support::LIVE_JWT_NO_SUB.clone(),
user_id: Some("user-456".into()),
user: Some(serde_json::json!({ "_id": "user-456" })),
};
@@ -434,7 +434,7 @@ async fn state_retries_its_core_snapshot_after_a_superseded_refresh() {
async fn pending_confirmation_after_logout_does_not_restore_the_session() {
let backend = Backend::start(vec![MeAnswer::Slow(300)]).await;
let core = FakeCore::new(&backend.url);
- *core.session.lock().unwrap() = Some(crate::test_support::StoredCredential {
+ *core.session.lock().unwrap() = Some(crate::session::test_support::StoredCredential {
kind: "session".into(),
token: LIVE_JWT.clone(),
user_id: Some("user-123".into()),
diff --git a/crates/openhuman-tinyhumans/src/session/mod.rs b/crates/openhuman-tinyhumans/src/session/mod.rs
index b046a8216b..d457aa1c38 100644
--- a/crates/openhuman-tinyhumans/src/session/mod.rs
+++ b/crates/openhuman-tinyhumans/src/session/mod.rs
@@ -16,8 +16,11 @@
//! * [`SessionManager`] — the host-facing orchestration on top of the three:
//! login, store, logout, current user, state and change events.
//!
-//! No `openhuman` dependency: this crate must stay buildable from the Tauri
-//! shell's own Cargo world and must never pull the core's policy back in.
+//! Invariant kept from the standalone `openhuman-session` crate this module
+//! absorbed: it may use core *utilities* (`util::tls`, `api::product`,
+//! `openhuman_rpc::unwrap_rpc`) but must never call `openhuman_core::security::*`
+//! or dispatch into a core except through [`CoreLink`] — the host owns the
+//! login, the core only takes the credential.
pub mod cache;
pub mod client;
@@ -25,7 +28,6 @@ pub mod credential;
pub mod identity;
pub mod link;
pub mod manager;
-mod tls;
#[cfg(test)]
pub(crate) mod test_support;
diff --git a/crates/openhuman-tinyhumans/src/session/test_support.rs b/crates/openhuman-tinyhumans/src/session/test_support.rs
index dfd3a30bb8..9ab8420605 100644
--- a/crates/openhuman-tinyhumans/src/session/test_support.rs
+++ b/crates/openhuman-tinyhumans/src/session/test_support.rs
@@ -15,7 +15,7 @@ use axum::{Json, Router};
use serde_json::{json, Value};
use tokio::sync::Mutex as AsyncMutex;
-use crate::link::{self, CoreLink};
+use crate::session::link::{self, CoreLink};
/// Serialises tests that touch process-global state (environment variables,
/// the `identity` slot).
diff --git a/crates/openhuman-tinyhumans/src/session/tls.rs b/crates/openhuman-tinyhumans/src/session/tls.rs
deleted file mode 100644
index 2207dfbdc8..0000000000
--- a/crates/openhuman-tinyhumans/src/session/tls.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-//! Platform-conditional TLS backend selection, mirroring the core's
-//! `util::tls::tls_client_builder`: Windows uses schannel (`native-tls`) so the
-//! OS certificate store — including corporate CAs installed by TLS-inspecting
-//! proxies — is honoured; everywhere else uses `rustls` + webpki roots.
-
-pub(crate) fn client_builder() -> reqwest::ClientBuilder {
- let b = reqwest::Client::builder();
- #[cfg(target_os = "windows")]
- let b = b.use_native_tls();
- #[cfg(not(target_os = "windows"))]
- let b = b.use_rustls_tls();
- b
-}