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(codex-oauth): add platform TLS client + fix session-expired test coverage\n\nUse platform TLS (reqwest tls_client_builder) for the Codex OAuth OpenAI\nmodel builder in crate_openai.rs so the client honours Windows schannel\nand corporate TLS proxy certificates. (#5869)\n\nUpdate flow_tests_part_02_tests.rs:\n- Fix blank-refresh test: was using expires_at -5 min (already past expiry)\n which now correctly triggers the session-expired path added in the prior\n commit; move expiry to +90 s so refresh is still attempted but the\n session-expired guard does not fire on a not-yet-expired token.\n- Add new test asserting that a nearly-expiring token with a failed refresh\n returns the cached token (not an error).\n
shanu613b62fff116
diff --git a/src/openhuman/inference/openai_oauth/flow_tests_part_02_tests.rs b/src/openhuman/inference/openai_oauth/flow_tests_part_02_tests.rsindex 144f773ae0..d5d96b7059 100644--- a/src/openhuman/inference/openai_oauth/flow_tests_part_02_tests.rs+++ b/src/openhuman/inference/openai_oauth/flow_tests_part_02_tests.rs@@ -32,7 +32,12 @@ fn lookup_key_for_slug_uses_legacy_openai_api_key_when_new_style_is_empty() {}#[test]-fn lookup_openai_bearer_token_keeps_expired_token_when_refresh_fails_without_runtime() {+fn lookup_openai_bearer_token_returns_session_expired_error_when_refresh_fails_on_expired_token() {+ // A token that is 5 minutes past expiry with a refresh token present but no+ // tokio runtime available (so try_refresh_oauth_token returns Err).+ // After the fix in store.rs: is_expiring_within(ZERO) returns true AND+ // refresh returned Err, so the function must return Err with a+ // "session expired" message rather than Ok(Some("expired-access")).let tmp = tempdir().unwrap();let config = test_config(&tmp);let store = AuthProfilesStore::new(tmp.path(), false);@@ -50,8 +55,45 @@ fn lookup_openai_bearer_token_keeps_expired_token_when_refresh_fails_without_run);store.upsert_profile(oauth_profile, true).unwrap();- let token = lookup_openai_bearer_token(&config).unwrap();- assert_eq!(token.as_deref(), Some("expired-access"));+ let result = lookup_openai_bearer_token(&config);+ let err = result.expect_err("expected Err for expired token with failed refresh");+ assert!(+ err.to_lowercase().contains("session expired"),+ "error message should contain 'session expired' to trigger the classifier, got: {err:?}"+ );+}++#[test]+fn lookup_openai_bearer_token_returns_ok_when_nearly_expiring_and_refresh_fails() {+ // A token expiring 30 seconds in the future — within the 2-minute warning+ // window but NOT yet expired. The refresh fails (no tokio runtime), but+ // since is_expiring_within(ZERO) is false the function must still return+ // Ok(Some(...)) so the caller can make one last inference call before the+ // token truly expires.+ let tmp = tempdir().unwrap();+ let config = test_config(&tmp);+ let store = AuthProfilesStore::new(tmp.path(), false);+ let oauth_profile = AuthProfile::new_oauth(+ OPENAI_PROVIDER_KEY,+ OPENAI_OAUTH_PROFILE_NAME,+ TokenSet {+ access_token: "nearly-expiring-access".into(),+ refresh_token: Some("refresh".into()),+ id_token: None,+ expires_at: Some(Utc::now() + Duration::seconds(30)),+ token_type: Some("Bearer".into()),+ scope: None,+ },+ );+ store.upsert_profile(oauth_profile, true).unwrap();++ let token = lookup_openai_bearer_token(&config)+ .expect("nearly-expiring token should be returned even when refresh fails");+ assert_eq!(+ token.as_deref(),+ Some("nearly-expiring-access"),+ "should return the existing token for one last inference call"+ );}#[tokio::test(flavor = "multi_thread")]@@ -69,7 +111,10 @@ async fn lookup_openai_bearer_token_does_not_persist_blank_refreshed_access_tokeaccess_token: "oauth-access".into(),refresh_token: Some("refresh-token".into()),id_token: None,- expires_at: Some(Utc::now() - Duration::minutes(5)),+ // Token is nearly-expiring (within 2-min skew) but NOT past expiry.+ // This ensures refresh is attempted while the session-expired path+ // (which fires only when expires_at <= now()) stays silent on failure.+ expires_at: Some(Utc::now() + Duration::seconds(90)),token_type: Some("Bearer".into()),scope: None,},@@ -97,7 +142,7 @@ async fn lookup_openai_bearer_token_does_not_persist_blank_refreshed_access_tokeassert_eq!(token.as_deref(),Some("oauth-access"),- "invalid refresh payload should not replace the last known good access token"+ "a failed refresh on a not-yet-expired token should return the cached token, not error");let reloaded = AuthProfilesStore::new(tmp.path(), false).load().unwrap();diff --git a/src/openhuman/inference/provider/crate_openai.rs b/src/openhuman/inference/provider/crate_openai.rsindex 09291c37a0..80f1cf053a 100644--- a/src/openhuman/inference/provider/crate_openai.rs+++ b/src/openhuman/inference/provider/crate_openai.rs@@ -95,12 +95,23 @@ pub(crate) struct CrateOpenAiConfig<'a> {/// Build a crate-native `OpenAiModel` (`ChatModel`) for the given OpenAI-compatible/// provider config.pub(crate) fn build_crate_openai_model(config: CrateOpenAiConfig<'_>) -> Arc<dyn ChatModel<()>> {+ // Use the platform-specific TLS backend so requests reach corporate+ // endpoints that sit behind TLS-inspection proxies. On Windows this means+ // schannel, which reads from the Windows certificate store; on macOS/Linux+ // rustls is preferred. The 30-second connect-timeout matches the+ // tinyinference default so behaviour is unchanged on non-Windows hosts.+ let http_client = crate::openhuman::util::tls::tls_client_builder()+ .connect_timeout(std::time::Duration::from_secs(30))+ .build()+ .expect("platform TLS reqwest client builds");+let mut model = OpenAiModel::compatible_provider(config.provider_name,config.api_key,config.endpoint,config.model,)+ .with_http_client(http_client).with_auth_style(map_auth_style(config.auth_style));if !config.temperature_unsupported_models.is_empty() {