The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(app_state): an empty backend answer is not a refresh\n\nCodeRabbit review on #5950.\n\n`note_current_user_success` ran whenever `auth_get_me` returned without an\nerror, including the case where the backend answers 200 carrying no user at\nall. The snapshot caller falls back to `stored_user` on that path\n(`Ok(Ok(None))`), so the stamp claimed a ~0s age for data that was never\nreplaced — the staleness signal wrong in the one direction that defeats it,\nsince the field exists to warn that data is out of date.\n\nGated on `fetched.is_some()`. Two notes:\n\n- `clear_current_user_failure` still runs unconditionally. An empty answer is\n the backend being healthy but unhelpful, not an availability failure, and\n holding the backoff window open on it would be wrong for its own reasons.\n Only the freshness claim was unearned.\n\n- Gated before taking the cache lock rather than inside the `Some(user)` arm,\n so this never nests `LAST_CURRENT_USER_SUCCESS` inside `CURRENT_USER_CACHE`.\n No path takes those two in the opposite order today, so it would not\n deadlock, but the ordering hazard buys nothing.\n\nThe doc comment is corrected too, since it is what let this through: it said\n"when the backend last answered `auth_get_me` successfully", which made\nstamping an empty 200 look right. It now describes when the displayed data was\nlast replaced, and `note_current_user_success` states the caller's obligation.\n\nCovered by `an_empty_user_response_is_not_counted_as_a_refresh` against a new\n`auth_me_empty_user_server`: the stored user survives and\n`current_user_stale_seconds` is `None` rather than `0`.\n
Shanue83c2932e6f7
diff --git a/src/openhuman/desktop/app_state/ops_part_02.rs b/src/openhuman/desktop/app_state/ops_part_02.rsindex e9140fdf0f..ad48396c3e 100644--- a/src/openhuman/desktop/app_state/ops_part_02.rs+++ b/src/openhuman/desktop/app_state/ops_part_02.rs@@ -236,7 +236,18 @@ async fn fetch_current_user_cached(}};clear_current_user_failure();- note_current_user_success(&api_base, token);+ // Only a *refreshed user* makes the displayed data fresh. The backend can+ // answer 200 with no user at all, and the snapshot caller then falls back+ // to `stored_user` — so stamping success here would report an age of ~0s+ // for data that was never replaced. `clear_current_user_failure` still runs+ // either way: an empty answer is the backend being healthy, just not+ // useful, and it should not keep the backoff window open.+ //+ // Read before the cache lock rather than inside the `Some` arm below, so+ // this never nests `LAST_CURRENT_USER_SUCCESS` inside `CURRENT_USER_CACHE`.+ if fetched.is_some() {+ note_current_user_success(&api_base, token);+ }let mut cache = CURRENT_USER_CACHE.lock();match fetched.clone() {diff --git a/src/openhuman/desktop/app_state/ops_staleness.rs b/src/openhuman/desktop/app_state/ops_staleness.rsindex 47562b7ec3..a39cc84027 100644--- a/src/openhuman/desktop/app_state/ops_staleness.rs+++ b/src/openhuman/desktop/app_state/ops_staleness.rs@@ -8,7 +8,12 @@//// `include!`d into `ops.rs`, so everything here shares that module's scope.-/// When the backend last answered `auth_get_me` successfully in this process.+/// When the backend last returned an actual user for `auth_get_me` in this+// process — i.e. when the data the snapshot displays was last replaced.+//+// Deliberately not "when the backend was last healthy": a 200 carrying no user+// leaves the caller on `stored_user`, so counting it as a success would report+// a ~0s age for data that never changed.////// Neither existing cache can answer "how old is the user data we are showing":/// [`CURRENT_USER_FAILURE`] only knows about failures, and@@ -34,8 +39,9 @@ struct CurrentUserSuccess {at: Instant,}-/// Stamp a successful backend answer, so the snapshot can report how old the-/// data it is serving has become.+/// Stamp a refreshed user, so the snapshot can report how old the data it is+/// serving has become. Callers must not invoke this for an answer that carried+/// no user — see [`LAST_CURRENT_USER_SUCCESS`].fn note_current_user_success(api_base: &str, token: &str) {*LAST_CURRENT_USER_SUCCESS.lock() = Some(CurrentUserSuccess {api_base: api_base.to_string(),diff --git a/tests/raw_coverage/app_state_credentials_raw_coverage_e2e.rs b/tests/raw_coverage/app_state_credentials_raw_coverage_e2e.rsindex dcfbcad98b..4e9e871aaa 100644--- a/tests/raw_coverage/app_state_credentials_raw_coverage_e2e.rs+++ b/tests/raw_coverage/app_state_credentials_raw_coverage_e2e.rs@@ -252,6 +252,41 @@ async fn auth_me_failing_server() -> ((url, task, shutdown_tx)}+/// Answers `/auth/me` 200 with an empty object — the backend is healthy but+/// carries no user, so the snapshot falls back to the stored one (#5930).+async fn auth_me_empty_user_server() -> (+ String,+ tokio::task::JoinHandle<()>,+ tokio::sync::oneshot::Sender<()>,+) {+ let listener = tokio::net::TcpListener::bind(("127.0.0.1", 0))+ .await+ .expect("bind empty-user auth/me listener");+ let url = format!("http://{}", listener.local_addr().expect("listener addr"));+ let (shutdown_tx, mut shutdown_rx) = tokio::sync::oneshot::channel::<()>();+ let task = tokio::spawn(async move {+ loop {+ tokio::select! {+ _ = &mut shutdown_rx => break,+ accepted = listener.accept() => {+ let Ok((mut stream, _)) = accepted else { break; };+ let mut req = [0_u8; 2048];+ let _ = stream.read(&mut req).await;+ let body = "{}";+ let response = format!(+ "HTTP/1.1 200 OK\r\ncontent-type: application/json\r\ncontent-length: {}\r\nconnection: close\r\n\r\n{}",+ body.len(),+ body+ );+ let _ = stream.write_all(response.as_bytes()).await;+ let _ = stream.shutdown().await;+ }+ }+ }+ });+ (url, task, shutdown_tx)+}+async fn auth_me_rejected_server() -> (String,tokio::task::JoinHandle<()>,@@ -1487,3 +1522,53 @@ async fn round14_credentials_prefix_listing_and_composio_direct_edges() {.expect("clear composio key idempotent");assert_eq!(cleared_again.value["removed"], false);}++/// A 200 that carries no user must not be counted as a refresh (#5930).+///+/// The backend is healthy, so the failure backoff is cleared — but the caller+/// falls back to `stored_user`, and reporting a ~0s age for data that was never+/// replaced is exactly the staleness signal being wrong in the direction that+/// matters: it would tell the app the snapshot is fresh when it is not.+#[tokio::test]+async fn an_empty_user_response_is_not_counted_as_a_refresh() {+ let _lock = env_lock();+ let (api_url, server_task, shutdown_tx) = auth_me_empty_user_server().await;+ let harness = setup(&api_url);+ let config = harness.config().await;++ let mut metadata = HashMap::new();+ metadata.insert("user_id".to_string(), "empty-user-round".to_string());+ metadata.insert(+ "user_json".to_string(),+ json!({ "id": "empty-user-round", "email": "[email protected]" }).to_string(),+ );+ AuthService::from_config(&config)+ .store_provider_token(+ APP_SESSION_PROVIDER,+ DEFAULT_AUTH_PROFILE_NAME,+ "round.empty.user",+ metadata,+ true,+ )+ .expect("seed app session");++ let snap = snapshot()+ .await+ .expect("snapshot with an empty backend user")+ .value;++ // The stored identity is still what the app shows.+ assert!(+ snap.current_user.is_some(),+ "an empty backend answer must leave the stored user in place"+ );+ // And its age is unknown rather than zero: nothing was refreshed, so there+ // is no successful refresh to measure from.+ assert_eq!(+ snap.current_user_stale_seconds, None,+ "an empty answer must not stamp a refresh age for data it did not replace"+ );++ let _ = shutdown_tx.send(());+ let _ = server_task.await;+}