fix(observability): classify OpenHuman embedding 401 'Invalid token' as SessionExpired (TAURI-RUST-4K5)#2867
Conversation
…as SessionExpired (TAURI-RUST-4K5)
The 4K5 wire shape `Embedding API error (401 …): {"error":"Invalid token"}`
was claimed by two contradictory matchers: PR tinyhumansai#2786 added an
`is_session_expired_message` arm + test expecting `SessionExpired`, but the
older `is_embedding_backend_auth_failure` (tinyhumansai#2830) caught the identical string
first and returned `BackendUserError`. `expected_error_kind` ran the embedding
matcher before the session matcher, so tinyhumansai#2786's own test failed on `main` —
turning the Rust CI red on every open PR.
Run `is_session_expired_message` before `is_embedding_backend_auth_failure` so
the parenthesised OpenHuman-backend envelope classifies as `SessionExpired`
(recoverable re-auth signal). The session matcher's `(401` anchor leaves the
bare-status `Embedding API error 401 …` shape and BYO-key 401s untouched —
they still fall through to `BackendUserError` / Sentry respectively. Amends
tinyhumansai#2830's `classifies_embedding_backend_auth_failure` test to drop the now
session-owned parenthesised case.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR fixes error classification precedence in ChangesSession-Expired Classification Precedence
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
Actionable comments posted: 0 |
graycyrus
left a comment
There was a problem hiding this comment.
@CodeGhost21 hey! the code looks good to me, but CI is still pending so i'll hold off on approving until those checks clear.
The fix is correct and well-reasoned. Moving is_session_expired_message before is_embedding_backend_auth_failure is exactly the right call — the parenthesised (401 + "error":"Invalid token" envelope is unambiguously a session expiry signal, and the comment you added documenting the ownership boundary between the two matchers is exactly the kind of thing that prevents this regression from recurring.
The test amendment is accurate too — pulling the parenthesised case out of classifies_embedding_backend_auth_failure and leaving only the bare-status shape there correctly reflects what each matcher now owns.
One thing worth confirming once CI runs: is_session_expired_message uses the original-case message argument while the surrounding checks use &lower. That's carry-over from before the move, so it should be fine, but worth a quick sanity check that the session matcher's string comparisons are case-insensitive or otherwise correctly anchored.
Once the Rust CI jobs go green, i'll come back and approve this.
… so embedding 401 'Invalid token' classifies as SessionExpired (TAURI-RUST-4K5) The merge surfaced a pre-existing main contradiction (tinyhumansai#2786 vs tinyhumansai#2830): the embedding 401 "Invalid token" envelope was shadowed by the broader is_embedding_backend_auth_failure matcher (BackendUserError) before reaching is_session_expired_message. Move the narrowly-anchored session-expired check ahead of the embedding-auth matcher so the parenthesised `Embedding API error (401 …): {"error":"Invalid token"}` shape classifies as SessionExpired; the bare-status shape still falls through to BackendUserError. Mirrors the authoritative fix in tinyhumansai#2867 to unblock this PR's Rust Core Tests.
|
Closing as superseded by #2869, which resolved the same TAURI-RUST-4K5 regression via a different approach: instead of moving |
Summary
main: the embedding-401 wire shapeEmbedding API error (401 …): {"error":"Invalid token"}was asserted to be two different buckets by two merged PRs, leaving the Rust test suite red onmain(and therefore on every open PR).expected_error_kindnow runsis_session_expired_messagebeforeis_embedding_backend_auth_failure, so the OpenHuman-backend embedding 401 "Invalid token" envelope classifies asSessionExpired(recoverable re-auth signal) instead ofBackendUserError.classifies_embedding_backend_auth_failuretest to drop the parenthesised case now owned by the session matcher; the bare-status shape still classifies asBackendUserError.Problem
PR #2786 (TAURI-RUST-4K5, current
maintip14ff92b2) added anis_session_expired_messagearm + the testclassifies_embedding_api_invalid_token_401_as_session_expired, asserting thatEmbedding API error (401 Unauthorized): {"success":false,"error":"Invalid token"}→SessionExpired.The older PR #2830 (TAURI-RUST-T) had already added
is_embedding_backend_auth_failure, which matches the identical string and returnsBackendUserError, and runs earlier inexpected_error_kind. Its testclassifies_embedding_backend_auth_failureassertsBackendUserErrorfor that same string.The two are mutually exclusive. Because the embedding matcher ran first, #2786's own test fails on
main:This turns the Rust CI job red on
mainand on every PR that merges currentmain.Solution
is_session_expired_messagecheck to immediately afteris_backend_user_error_messageand beforeis_embedding_backend_auth_failureinexpected_error_kind.is_backend_user_error_messageonly matches the literal"backend returned <status>"substring (which this wire shape lacks), so the new placement is the earliest point that can intercept the embedding 401 envelope.(401prefix and the"error":"Invalid token"envelope. Therefore:SessionExpired(fixed).Embedding API error 401 …→ still falls through tois_embedding_backend_auth_failure→BackendUserError(unchanged).invalid_api_key,authentication_error, no"Invalid token"envelope) → stillNone/actionable in Sentry (unchanged; guarded bydoes_not_classify_embedding_byo_key_401_as_session_expired).Design decision: SessionExpired is the more specific and more recent intent (#2786 deliberately covers 4P0 + 4K5 + 1EE with BYO-key guards), and a "401 Invalid token" from the OpenHuman backend genuinely is an expired user session that should drive re-auth rather than a generic backend error.
Submission Checklist
classifies_embedding_backend_auth_failure; theSessionExpiredhappy path (classifies_embedding_api_invalid_token_401_as_session_expired) and the negative guards (does_not_classify_embedding_byo_key_401_as_session_expired,does_not_classify_unrelated_invalid_token_messages) now all pass.is_session_expired_messagebranch (exercised by the 4K5 test) and the amended test body; all are covered.N/A: behaviour-only change(re-buckets one already-tracked error classification; no feature row added/removed/renamed).## Related—N/A: no matrix feature IDs affected.docs/RELEASE-MANUAL-SMOKE.md) —N/A: observability classification only, no user-facing surface.Closes #NNNin the## Relatedsection —N/A: no tracked issue; this fixes a regression introduced by #2786 vs #2830 racing on main.Impact
src/core/observability.rs) only; no UI, mobile, or CLI changes.SessionExpiredinstead ofBackendUserError. Both are Sentry-suppressed "expected" buckets, so Sentry volume is unchanged; the difference is the downstream re-auth signal.mainand unblocks all open PRs that were failing on the pre-existing contradiction.Related
N/AAI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
Commit & Branch
fix/observability-embedding-401-session-precedenceed9c9704Validation Run
pnpm --filter openhuman-app format:check—N/A: Rust-only change, no app/ files touchedpnpm typecheck—N/A: Rust-only change, no TypeScript touchedcargo test --manifest-path Cargo.toml --lib core::observability→ 118 passed, 0 failedcargo fmt --checkclean; lib compiles undercargo testN/A: app/src-tauri not touchedValidation Blocked
command:pnpm test:coverage/pnpm typecheckerror:worktree lacksnode_modules(prettier: command not found); not installed for this Rust-only fiximpact:none — change is confined to the Rust core classifier; Rust fmt + focused tests verifiedBehavior Changes
BackendUserErrortoSessionExpired.SessionExpiredcan now treat the embedding 401 as a recoverable re-auth event.Parity Contract
Embedding API error 401 …→BackendUserError; BYO-key embedding 401s →None/actionable; non-embedding session shapes (4P0 OpenHuman, 1EE streaming) unchanged.does_not_classify_embedding_byo_key_401_as_session_expiredanddoes_not_classify_unrelated_invalid_token_messagesstill pass.Duplicate / Superseded PR Handling
Summary by CodeRabbit