Plex pin flow reports connected but strands authorized accounts with no servers #345

Closed
opened 2026-07-13 22:48:23 +02:00 by timothy · 2 comments
Owner

Summary

A real Plex pin-flow run for #333 reached the valid API state isAuthorized: true, isLocked: false, servers: []. The SPA then displayed mutually contradictory state:

  • pin-flow status: Connected to Plex.
  • Connection card: Not signed in.
  • Sign in to Plex remained available
  • Sign out of Plex was unavailable, so the stored Plex authorization could not be removed through the UI

No matching open or closed issue was found with searches for “Plex sign out”, “Connected to Plex”, and “Plex servers”.

Reproduction

  1. Start Plex sign-in from /app/libraries/plex.
  2. Authorize an account for which discovery returns no owned servers.
  3. Wait for the lock to release.
  4. Observe GET /api/v1/media-sources/plex returns authorized/unlocked with an empty server list.
  5. Compare the pin status, Connection card, and available actions.

This was reproduced against the disposable ersatztv-test deployment on 2026-07-13. Server logs showed successful authentication and no server-discovery exception. Cleanup required POST /api/v1/media-sources/plex/sign-out outside the SPA; afterward the API and SPA both returned to a clean signed-out state.

Root cause evidence

  • web/src/mediaSources/pinFlowPoll.ts treats unlocked + authorized as terminal success and always emits “Connected to Plex.”
  • web/src/screens/PlexSourceScreen.tsx defines connected solely as servers.length > 0.
  • The Connection subtitle and sign-in/sign-out actions are gated by that server-count value rather than authorization state.
  • Existing tests cover successful discovery only when a server appears and sign-out only when a server exists; authorized/unlocked/empty is untested.

Expected

The authorized-zero-server state is coherent and recoverable: it must not claim a server connection, it should explain that the Plex account is authorized but no eligible servers were discovered, and it must offer sign-out.

Done-when

  • Pin-flow messaging distinguishes account authorization from successful server discovery.
  • An authorized account can sign out even when servers is empty.
  • The Connection card and available actions agree for authorized/unlocked/empty state.
  • Regression tests cover the authorized/unlocked/empty transition and sign-out action.
  • Relevant SPA quality gates pass.
  • #333 live validation is repeated or explicitly linked as the validation evidence. — satisfied via the "explicitly linked" branch: the #333 live repro (this issue's Reproduction section, ersatztv-test, 2026-07-13) is the validation evidence. A fresh live repro requires a Plex account with zero eligible servers, which can't be synthesized on demand; the state transition + sign-out are covered deterministically by the new regression tests (finalizing/terminal/budget-exhausted cells + sign-out from the empty state).

adversarial review passed — two cold-context passes; the initial diff BLOCKED on a real High (locked-state contradiction), fix re-review MERGEABLE @ 6532929c.

## Summary A real Plex pin-flow run for #333 reached the valid API state `isAuthorized: true`, `isLocked: false`, `servers: []`. The SPA then displayed mutually contradictory state: - pin-flow status: **Connected to Plex.** - Connection card: **Not signed in.** - **Sign in to Plex** remained available - **Sign out of Plex** was unavailable, so the stored Plex authorization could not be removed through the UI No matching open or closed issue was found with searches for “Plex sign out”, “Connected to Plex”, and “Plex servers”. ## Reproduction 1. Start Plex sign-in from `/app/libraries/plex`. 2. Authorize an account for which discovery returns no owned servers. 3. Wait for the lock to release. 4. Observe `GET /api/v1/media-sources/plex` returns authorized/unlocked with an empty server list. 5. Compare the pin status, Connection card, and available actions. This was reproduced against the disposable `ersatztv-test` deployment on 2026-07-13. Server logs showed successful authentication and no server-discovery exception. Cleanup required `POST /api/v1/media-sources/plex/sign-out` outside the SPA; afterward the API and SPA both returned to a clean signed-out state. ## Root cause evidence - `web/src/mediaSources/pinFlowPoll.ts` treats unlocked + authorized as terminal success and always emits “Connected to Plex.” - `web/src/screens/PlexSourceScreen.tsx` defines `connected` solely as `servers.length > 0`. - The Connection subtitle and sign-in/sign-out actions are gated by that server-count value rather than authorization state. - Existing tests cover successful discovery only when a server appears and sign-out only when a server exists; authorized/unlocked/empty is untested. ## Expected The authorized-zero-server state is coherent and recoverable: it must not claim a server connection, it should explain that the Plex account is authorized but no eligible servers were discovered, and it must offer sign-out. ## Done-when - [x] Pin-flow messaging distinguishes account authorization from successful server discovery. - [x] An authorized account can sign out even when `servers` is empty. - [x] The Connection card and available actions agree for authorized/unlocked/empty state. - [x] Regression tests cover the authorized/unlocked/empty transition and sign-out action. - [x] Relevant SPA quality gates pass. - [x] #333 live validation is repeated or explicitly linked as the validation evidence. — satisfied via the "explicitly linked" branch: the #333 live repro (this issue's Reproduction section, `ersatztv-test`, 2026-07-13) is the validation evidence. A fresh live repro requires a Plex account with zero eligible servers, which can't be synthesized on demand; the state transition + sign-out are covered deterministically by the new regression tests (finalizing/terminal/budget-exhausted cells + sign-out from the empty state). adversarial review passed — two cold-context passes; the initial diff BLOCKED on a real High (locked-state contradiction), fix re-review MERGEABLE @ 6532929c.
timothy added the bugpriority: highfrontend labels 2026-07-13 22:48:23 +02:00
timothy added the in-progress label 2026-07-16 14:07:20 +02:00
Author
Owner

Claiming (Claude Code / Opus 4.8 orchestrator session).

Context: arc tracker #237 is closed and no open frontier/milestone/review items remain, so this is a backlog pickup. #345 is the highest-priority unclaimed available issue (the other priority: high, #357, is being worked under PR #358 + active worktrees). Working it as a self-contained SPA fix off the localized root cause in the body (pinFlowPoll.ts + PlexSourceScreen.tsx).

Plan: distinguish account-authorization from server-discovery in the pin-flow terminal state; make sign-out available for the authorized/unlocked/empty-servers state; align the Connection card + actions with authorization state; add regression tests for the authorized/unlocked/empty transition and sign-out; run SPA quality gates. Will verify against the localized code before treating the body's root-cause as ground truth.

Claiming (Claude Code / Opus 4.8 orchestrator session). Context: arc tracker #237 is closed and no open frontier/milestone/`review` items remain, so this is a backlog pickup. #345 is the highest-priority unclaimed available issue (the other `priority: high`, #357, is being worked under PR #358 + active worktrees). Working it as a self-contained SPA fix off the localized root cause in the body (`pinFlowPoll.ts` + `PlexSourceScreen.tsx`). Plan: distinguish account-authorization from server-discovery in the pin-flow terminal state; make sign-out available for the authorized/unlocked/empty-servers state; align the Connection card + actions with authorization state; add regression tests for the authorized/unlocked/empty transition and sign-out; run SPA quality gates. Will verify against the localized code before treating the body's root-cause as ground truth.
timothy removed the in-progress label 2026-07-16 14:37:13 +02:00
Author
Owner

Closed — fixed in PR #366 (merged to main @ ee044ab2)

What was done
Separated Plex authorization (a stored token, isAuthorized) from connection (discovered servers, servers.length > 0) in the SPA. The authorized/unlocked/empty-servers state is now coherent and recoverable: it no longer claims "Connected to Plex.", it explains that the account is authorized but no eligible servers were discovered, and it offers Sign out.

Root cause
PlexSourceScreen derived every affordance (subtitle, Sign-in visibility, Sign-out visibility, Servers card) from connected = serverList.length > 0, and evaluatePinFlow returned success ("Connected to Plex.") for any released-lock + authorized observation regardless of server count. So isAuthorized:true, isLocked:false, servers:[] produced connected=false → "Not signed in." + Sign in shown + Sign out hidden, while the pin-flow status simultaneously claimed a connection — leaving the stored authorization unremovable via the UI.

Fix (pure SPA — no API change; the sign-out endpoint already works with empty servers)

  • web/src/mediaSources/pinFlowPoll.ts: new authorized-no-servers terminal status + a hasServers observation field; the released-lock branch yields success only when a server was discovered, else the honest empty-servers terminal.
  • web/src/screens/PlexSourceScreen.tsx: hasPlexAccount = isAuthorized || hasServers gates Sign in vs Sign out; a four-way Connection subtitle; an explanatory summary; the Servers card stays gated on real servers. The empty-servers presentation is gated on !isLocked so it never fires during the in-flight finalizing/budget-exhausted windows (caught in review — see below).
  • Tests: PlexSourceScreen.test.tsx (pin-flow terminal, finalizing/budget-exhausted guards, fresh-reload sign-out) + pinFlowPoll.test.ts (new machine case).

Files changed: the 4 files above (+29/−1 in the review fix commit).

Review: two cold-context adversarial passes. The initial diff was BLOCKED on a real High — the empty-servers messaging ignored isLocked and would render during discovery, even urging a sign-out mid-sync; fixed and re-reviewed MERGEABLE @ 6532929c. Both regression guards were negative-control-proven.

Verification: npm test 780/780, npm run lint clean, npm run build clean; CI green on the PR head.

Deferred / follow-up: filed #367 (priority: low) for a pre-existing, orthogonal gap the review surfaced — the budget-exhausted message says "Use Refresh to check again," but there's no global Refresh control when zero servers exist.

Docs: no doc update required — no route added/redirected, no /api/* endpoint change, no SPA convention changed, no decision reversed (per the docs-update table).

## Closed — fixed in PR #366 (merged to `main` @ `ee044ab2`) **What was done** Separated Plex **authorization** (a stored token, `isAuthorized`) from **connection** (discovered servers, `servers.length > 0`) in the SPA. The authorized/unlocked/empty-servers state is now coherent and recoverable: it no longer claims "Connected to Plex.", it explains that the account is authorized but no eligible servers were discovered, and it offers Sign out. **Root cause** `PlexSourceScreen` derived every affordance (subtitle, Sign-in visibility, Sign-out visibility, Servers card) from `connected = serverList.length > 0`, and `evaluatePinFlow` returned `success` ("Connected to Plex.") for any released-lock + authorized observation regardless of server count. So `isAuthorized:true, isLocked:false, servers:[]` produced `connected=false` → "Not signed in." + Sign in shown + Sign out hidden, while the pin-flow status simultaneously claimed a connection — leaving the stored authorization unremovable via the UI. **Fix (pure SPA — no API change; the sign-out endpoint already works with empty servers)** - `web/src/mediaSources/pinFlowPoll.ts`: new `authorized-no-servers` terminal status + a `hasServers` observation field; the released-lock branch yields `success` only when a server was discovered, else the honest empty-servers terminal. - `web/src/screens/PlexSourceScreen.tsx`: `hasPlexAccount = isAuthorized || hasServers` gates Sign in vs Sign out; a four-way Connection subtitle; an explanatory summary; the Servers card stays gated on real servers. The empty-servers presentation is gated on `!isLocked` so it never fires during the in-flight `finalizing`/`budget-exhausted` windows (caught in review — see below). - Tests: `PlexSourceScreen.test.tsx` (pin-flow terminal, finalizing/budget-exhausted guards, fresh-reload sign-out) + `pinFlowPoll.test.ts` (new machine case). **Files changed:** the 4 files above (+29/−1 in the review fix commit). **Review:** two cold-context adversarial passes. The initial diff was **BLOCKED** on a real High — the empty-servers messaging ignored `isLocked` and would render during discovery, even urging a sign-out mid-sync; fixed and re-reviewed **MERGEABLE @ 6532929c**. Both regression guards were negative-control-proven. **Verification:** `npm test` 780/780, `npm run lint` clean, `npm run build` clean; CI green on the PR head. **Deferred / follow-up:** filed **#367** (`priority: low`) for a pre-existing, orthogonal gap the review surfaced — the `budget-exhausted` message says "Use Refresh to check again," but there's no global Refresh control when zero servers exist. **Docs:** no doc update required — no route added/redirected, no `/api/*` endpoint change, no SPA convention changed, no decision reversed (per the docs-update table).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#345