Skip to content

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

feat(session): add session management module

Steven Enamakela9666b1b626d
diff --git a/crates/openhuman-app/Cargo.toml b/crates/openhuman-app/Cargo.toml
index f27282e59a..9f05457331 100644
--- a/crates/openhuman-app/Cargo.toml
+++ b/crates/openhuman-app/Cargo.toml
@@ -35,6 +35,9 @@ serde_json = "1"
[dependencies]
openhuman-rpc = { path = "../openhuman-rpc", features = ["http-client"] }
+# The desktop session owner (login-token exchange, /auth/me, current-user
+# cache). No core dependency of its own; see crates/openhuman-session/README.md.
+openhuman-session = { path = "../openhuman-session" }
# Tauri core and plugins. Use upstream Tauri's native WebView runtime (Wry),
# rather than the removed Chromium/CEF fork.
tauri = { version = "2.11", default-features = false, features = [
diff --git a/crates/openhuman-app/src/lib.rs b/crates/openhuman-app/src/lib.rs
index 0e4ad76bcb..8d9403a772 100644
--- a/crates/openhuman-app/src/lib.rs
+++ b/crates/openhuman-app/src/lib.rs
@@ -97,6 +97,7 @@ mod ptt_hotkeys;
mod ptt_overlay;
#[cfg(target_os = "windows")]
mod reset_reboot_schedule;
+mod session;
mod stderr_panic_hook;
mod window_state;
mod workspace_paths;
@@ -2574,20 +2575,17 @@ pub fn run() {
//
// Issue #3135: the primary source for `event.user` is now the
// Sentry scope, bound proactively at session boundaries
- // (credentials::store_session / clear_session) and at server boot
- // (run_server_inner). The `app_state_snapshot` cache is kept as a
- // fallback for legacy cache-warming paths, but we only consult it
- // when the scope hasn't already bound a user — otherwise we'd
- // silently clobber the scope binding when the cache is empty
- // (the original userCount=0 root cause).
+ // (credentials::set_credential / clear_credential) and at server
+ // boot (run_server_inner). The shell's session owner mirrors the
+ // signed-in user id for this fallback, consulted only when the
+ // scope hasn't already bound a user — otherwise we'd silently
+ // clobber the scope binding when the slot is empty (the original
+ // userCount=0 root cause).
if event.user.is_none() {
- event.user =
- openhuman_core::desktop::app_state::peek_cached_current_user_identity()
- .and_then(|identity| identity.id)
- .map(|id| sentry::User {
- id: Some(id),
- ..Default::default()
- });
+ event.user = session::peek_user_id().map(|id| sentry::User {
+ id: Some(id),
+ ..Default::default()
+ });
}
Some(event)
})),
@@ -3196,6 +3194,9 @@ pub fn run() {
std::env::remove_var("OPENHUMAN_CEF_COOKIES_DB");
app.manage(core_handle.clone());
+ // The desktop session owner (login, /auth/me, current user) talks
+ // to whichever core `active_rpc_endpoint` resolves to.
+ session::install(app.handle(), core_handle.clone());
// NOTE: the core is NOT auto-spawned here. The BootCheckGate UI
// calls `start_core_process` (Local mode) after the user picks a
// mode, which lets the frontend surface startup failures and
@@ -3440,6 +3441,11 @@ pub fn run() {
app_quit,
restart_app,
get_active_user_id,
+ session::auth_login_with_token,
+ session::auth_store_session,
+ session::auth_logout,
+ session::auth_state,
+ session::auth_current_user,
register_dictation_hotkey,
unregister_dictation_hotkey,
register_ptt_hotkey,
diff --git a/crates/openhuman-app/src/session/mod.rs b/crates/openhuman-app/src/session/mod.rs
index cdb72be52d..730f6487a4 100644
--- a/crates/openhuman-app/src/session/mod.rs
+++ b/crates/openhuman-app/src/session/mod.rs
@@ -38,8 +38,10 @@ pub struct SessionHost {
impl SessionHost {
pub fn new(desktop: CoreProcessHandle) -> Self {
+ // The shell and the core ship as one release, so one version answers
+ // for both `x-core-version` and `x-tauri-version`.
let headers = ClientHeaders::new(openhuman_core::api::product_identity().as_str())
- .with_core_version(openhuman_core::CORE_VERSION)
+ .with_core_version(env!("CARGO_PKG_VERSION"))
.with_tauri_version(env!("CARGO_PKG_VERSION"));
let link = Arc::new(HttpCoreLink::new(desktop));
Self {