Skip to content

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

fix(codex-oauth): route Codex token expiry to provider_error, not session_expired\n\nThe error from store.rs previously said 'Codex session expired' which\nmatches is_session_expired_message's broad 'session expired' substring,\nrouting the user to the OpenHuman sign-in flow instead of\nSettings → Integrations where they can reconnect Codex.\n\nFix the sentinel to 'Codex authentication token is expired' (an existing\nis_openai_oauth_session_expired_message marker) and add a dedicated arm\nin classify_inference_error before is_session_expired_message. The Codex\narm returns error_type 'provider_error' with a Settings → Integrations\nremedy message, leaving the OpenHuman sign-in path untouched.\n\nTest codex_oauth_expiry_classifies_as_provider_error_not_session_expired\npins the corrected routing. (#5869)\n

shanu7913b2f65dd0
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.rs
index d5d96b7059..c1c576d562 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
@@ -58,8 +58,9 @@ fn lookup_openai_bearer_token_returns_session_expired_error_when_refresh_fails_o
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:?}"
+ err.to_lowercase().contains("authentication token is expired"),
+ "error message should contain 'authentication token is expired' to trigger \
+ is_openai_oauth_session_expired_message (not the app-session classifier), got: {err:?}"
);
}
diff --git a/src/openhuman/inference/openai_oauth/store.rs b/src/openhuman/inference/openai_oauth/store.rs
index 2a9923b1ca..c3a4e994d5 100644
--- a/src/openhuman/inference/openai_oauth/store.rs
+++ b/src/openhuman/inference/openai_oauth/store.rs
@@ -335,13 +335,15 @@ pub fn lookup_openai_oauth_credentials(
// If the token has already passed its expiry there is no
// point proceeding — the next inference call will hit 401
// and the user sees a generic error with no remedy.
- // Surface it as a session-expired error so the classifier
- // routes the user to sign in again rather than showing
- // "Something went wrong". (#5869)
+ // Return a string that `is_openai_oauth_session_expired_message`
+ // recognises ("authentication token is expired") so
+ // `classify_inference_error` routes to the Codex reconnect
+ // message (Settings → Integrations), not the OpenHuman
+ // app-session sign-in flow. (#5869)
if token_set.is_expiring_within(std::time::Duration::ZERO) {
return Err(format!(
- "Codex session expired — token refresh failed: {e}. \
- Please sign in to Codex again in Settings → Integrations."
+ "Codex authentication token is expired — refresh failed: {e}. \
+ Please reconnect Codex in Settings → Integrations."
));
}
}
diff --git a/src/openhuman/web_chat/web_errors_part_02.rs b/src/openhuman/web_chat/web_errors_part_02.rs
index b637e84297..a6adfee79a 100644
--- a/src/openhuman/web_chat/web_errors_part_02.rs
+++ b/src/openhuman/web_chat/web_errors_part_02.rs
@@ -33,12 +33,33 @@ pub(crate) fn classify_inference_error(err: &str) -> ClassifiedError {
// before the generic provider-429 branch — otherwise users see
// a confusing "your AI provider is rate-limiting you" message
// for limits OpenHuman itself enforced (issue #2364).
- let classified = if crate::core::observability::is_session_expired_message(err) {
+ let classified = if crate::openhuman::inference::provider::is_openai_oauth_session_expired_message(err) {
+ // The Codex OAuth token has expired and the refresh failed. This is a
+ // provider-specific re-auth — the user must reconnect Codex in
+ // Settings → Integrations, NOT sign into OpenHuman. Checked BEFORE
+ // `is_session_expired_message` because our error string contains
+ // "authentication token is expired" which would also match the broader
+ // "session expired" substring test and route to the wrong sign-in flow.
+ // (#5869)
+ ClassifiedError {
+ error_type: "provider_error",
+ message: "Your Codex session has expired. Please reconnect it in \
+ Settings → Integrations."
+ .to_string(),
+ source: "auth",
+ retryable: false,
+ retry_after_ms: None,
+ provider: Some("openai_codex".to_string()),
+ fallback_available: None,
+ }
+ } else if crate::core::observability::is_session_expired_message(err) {
// The OpenHuman app-session JWT expired (or the scheduler gate flagged
// signed-out / `SESSION_EXPIRED` sentinel). There is NO client-side
// refresh — recovery is an interactive re-auth only — so this is
- // non-retryable and must route the user to sign-in. Checked FIRST so the
- // `auth_error` arm below can't claim the backend's `401 "Invalid token"`
+ // non-retryable and must route the user to sign-in. Checked after the
+ // Codex OAuth arm because "authentication token is expired" would also
+ // match `is_session_expired_message`'s broad "session expired" substring.
+ // The `auth_error` arm below can't claim the backend's `401 "Invalid token"`
// envelope (it contains "401") and mislead managed-backend users with
// "check your API key". `is_session_expired_message` is conjunctively
// scoped to the OpenHuman/Embedding "Invalid token" envelopes + the
diff --git a/src/openhuman/web_chat/web_tests_part_02_tests.rs b/src/openhuman/web_chat/web_tests_part_02_tests.rs
index 3c5140ed3c..f3d1bf4fc1 100644
--- a/src/openhuman/web_chat/web_tests_part_02_tests.rs
+++ b/src/openhuman/web_chat/web_tests_part_02_tests.rs
@@ -618,3 +618,33 @@ fn classify_inference_error_empty_response_is_actionable_and_retryable() {
classified.message
);
}
+
+#[test]
+fn codex_oauth_expiry_classifies_as_provider_error_not_session_expired() {
+ // The error from store.rs contains "authentication token is expired" (an
+ // is_openai_oauth_session_expired_message marker) wrapped in the factory
+ // chain prefix. Verify it routes to `provider_error` (Codex reconnect),
+ // NOT `session_expired` (OpenHuman sign-in), so the user gets the correct
+ // remedy. (#5869)
+ let err = "[chat-factory] openai oauth lookup failed: \
+ Codex authentication token is expired — refresh failed: \
+ Token exchange failed: HTTP 401 Unauthorized: \
+ {\"error\":{\"message\":\"Could not validate your token. \
+ Please try signing in again.\",\"code\":\"token_expired\"}}. \
+ Please reconnect Codex in Settings \u{2192} Integrations.";
+ let classified = classify_inference_error(err);
+ assert_eq!(
+ classified.error_type, "provider_error",
+ "Codex OAuth expiry must not route to the OpenHuman sign-in flow"
+ );
+ assert!(
+ classified.message.contains("Integrations"),
+ "must surface the Settings → Integrations remedy: {}",
+ classified.message
+ );
+ assert!(
+ !classified.message.contains("Your OpenHuman session has expired"),
+ "must not show the app-session copy: {}",
+ classified.message
+ );
+}