Skip to content

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

fix(codex): scope Codex OAuth classifier to Codex-specific sentinel string\n\nReplace the broad is_openai_oauth_session_expired_message() predicate in\nweb_errors_part_02.rs with a check for the stable Codex sentinel\n"codex authentication token is expired" emitted by openai_oauth/store.rs.\nGeneric provider errors containing "token_expired" or "please try signing\nin again" (without the Codex prefix) no longer misclassify as Codex OAuth\nfailures. Regression test added.\n

shanub7b65bfaa2f1
diff --git a/src/openhuman/web_chat/web_errors_part_02.rs b/src/openhuman/web_chat/web_errors_part_02.rs
index a6adfee79a..415ee67f47 100644
--- a/src/openhuman/web_chat/web_errors_part_02.rs
+++ b/src/openhuman/web_chat/web_errors_part_02.rs
@@ -33,14 +33,18 @@ 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::openhuman::inference::provider::is_openai_oauth_session_expired_message(err) {
+ // Codex-specific sentinel emitted by `openai_oauth::store` on refresh
+ // failure. Checked before `is_session_expired_message` because the sentinel
+ // contains "authentication token is expired", which would also match the
+ // broader "session expired" substring test and route to the wrong sign-in
+ // flow. We require "codex" in the message so generic provider errors that
+ // happen to contain "token_expired" or "please try signing in again" are
+ // not misclassified as Codex OAuth failures. (#5869)
+ const CODEX_SENTINEL: &str = "codex authentication token is expired";
+ let classified = if err.to_ascii_lowercase().contains(CODEX_SENTINEL) {
// 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)
+ // Settings → Integrations, NOT sign into OpenHuman.
ClassifiedError {
error_type: "provider_error",
message: "Your Codex session has expired. Please reconnect it in \
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 f3d1bf4fc1..fc4da3bb30 100644
--- a/src/openhuman/web_chat/web_tests_part_02_tests.rs
+++ b/src/openhuman/web_chat/web_tests_part_02_tests.rs
@@ -648,3 +648,20 @@ fn codex_oauth_expiry_classifies_as_provider_error_not_session_expired() {
classified.message
);
}
+
+#[test]
+fn non_codex_token_expired_does_not_classify_as_codex_oauth() {
+ // A generic provider error containing "token_expired" (without the Codex
+ // sentinel prefix) must NOT be classified as a Codex OAuth expiry. Without
+ // the "codex authentication token is expired" guard, the old broad predicate
+ // would have matched. (#5869)
+ let err = "openai error 401: {\"error\":{\"code\":\"token_expired\",\
+ \"message\":\"Please try signing in again.\"}}";
+ let classified = classify_inference_error(err);
+ assert_ne!(
+ classified.provider.as_deref(),
+ Some("openai_codex"),
+ "generic token_expired error must not route to the Codex reconnect flow: {}",
+ classified.message
+ );
+}