openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

SessionExpired clears the session for unrelated backend 401s

Open Al629176 opened this issue 6 months ago • 1 comments

Summary

The core SessionExpired cascade is too aggressive because any backend 401 from any RPC can clear the local session and force the user back to sign-in.

Problem

src/core/jsonrpc.rs treats backend 401s broadly through is_session_expired_error, publishes SessionExpired, and the credentials subscriber clears the local token. This means one unauthorized downstream call can nuke the entire app session.

Expected behavior: OpenHuman should distinguish between the user’s actual OpenHuman auth session expiring and a downstream provider or scoped request returning unauthorized.

Actual behavior: any qualifying 401 can trigger a global SessionExpired teardown. This can happen for unrelated paths, including BYO-key provider failures and channel/integration calls.

Impact: high-severity session stability issue. A single 401 from a non-auth-critical path can log users out, interrupt workflows, and make connected-channel/integration screens unsafe to open.

Steps to reproduce:

  1. Start the desktop app on latest upstream/main.
  2. Trigger any RPC path that receives a backend/downstream 401 that is not truly an expired OpenHuman user session.
  3. Observe that is_session_expired_error classifies the error as session expiry.
  4. Observe SessionExpired being published.
  5. Observe the credentials subscriber clearing the local token and the UI returning to Welcome / sign-in.

Version / platform: verified against latest upstream/main. Same root-cause pattern reported for asura.zhou on May 16 and for Claudy when clicking the Discord channel card.

Solution (optional)

Narrow SessionExpired classification so it only fires for explicit OpenHuman session-auth failures. Downstream provider 401s, BYO-key provider errors, integration authorization failures, billing/team fetch failures, and scoped channel failures should become typed recoverable errors instead of clearing the whole session.

Potential direction:

  • Require a specific error code/source that means OpenHuman user session expired.
  • Preserve 401 details from downstream providers as typed provider/integration errors.
  • Add method/path context to logs before publishing SessionExpired.
  • Avoid publishing SessionExpired from generic backend 401s.

Acceptance criteria

  • [ ] Session expiry narrowed — SessionExpired is only published for confirmed OpenHuman user-session expiry, not generic downstream/provider 401s.
  • [ ] Downstream 401s recover — BYO-key provider failures, integration/provider authorization errors, and channel status fetch 401s surface as recoverable typed errors.
  • [ ] No token wipe on unrelated 401 — A non-session 401 no longer clears the local token or sends the user to Welcome/sign-in.
  • [ ] Logging improved — Logs include method/path/source context before any SessionExpired publish.
  • [ ] Discord regression protected — The Discord card-click 401 path no longer logs the user out once reproduced.
  • [ ] Regression safety — Tests cover true session expiry, downstream provider 401, integration 401, and channel/card-open 401 behavior.
  • [ ] Diff coverage ≥ 80% — the fix PR meets the changed-lines coverage gate (Vitest + cargo-llvm-cov, enforced by .github/workflows/coverage.yml).

Related

  • src/core/jsonrpc.rs
  • Claudy Discord card logout report.
  • asura.zhou May 16 session-expired cascade report.

Al629176 avatar May 20 '26 06:05 Al629176

Picking this one up. Plan to narrow the 401 classifier so only real OpenHuman backend session expiry signs the user out, and tag those 401s at the backend API boundary so BYO-key and integration auth failures stay recoverable.

obchain avatar May 20 '26 07:05 obchain