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
Shanu335212d7b193
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;+}