Skip to content

fix(accounts): a server's late account result stays with that server - #27262

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/d4-d4-v5c
Oct 10, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/d4-d4-v5c

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​26 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​22

ELI5

The AI Provider Accounts settings can show either this desktop's accounts or a Remote Orca Server's accounts. If you clicked an account on one server and switched the default runtime to another server before that click finished, the first server's account list could appear under the second server's name. Now each account owner gets its own fresh view, so a late answer from the old owner is thrown away.

What Changed

  • Before: the accounts pane kept a single roster across changes of the default runtime. A select or remove still in flight on server A (these can take up to 30 seconds while the server refreshes usage) wrote server A's account list into the pane after it had already switched to server B. The user then saw A's accounts labelled as B's, and clicking one sent A's account id to B.
  • After: each Claude/Codex account action remembers the owner it was sent to (getProviderAccountsOwnerKey, the same key the shared snapshot read already uses). When it returns, its account list is written into the pane only if the pane still shows that owner; otherwise the new owner's live list stays. The toast, the settings refresh and the restart prompt still run, because they describe what really happened on the owner the action went to. Coming back to the original owner before the result arrives still applies it.

Why

Both action runners funnel every select, remove and add through one place, so a single owner check at the one place they write the list covers them all. I first tried remounting the pane per owner; that dropped an in-progress local sign-in's spinner and Cancel button and hid an account added after switching back, so the check is on the result instead. The owner key already existed for the shared snapshot read; this reuses it rather than adding a second notion of "owner".

Design adaptation (D4-V5c). The plan also expected "Add account" on a Remote Orca Server to work through the existing Claude sign-in link RPCs. Checking the code, that flow does not exist over the wire: accounts.beginClaudeSignIn/finishClaudeSignIn refuse paired clients and expect the caller to run claude auth login itself in a terminal, and the copied link calls back to localhost on the machine running Claude, which a desktop browser cannot reach for a remote server. Making remote add work needs a new capability-negotiated RPC (a pasted-code Claude flow, a device-code Codex flow), which is a wire change and out of scope here. The other parts of the plan are already true on main: list, subscribe, select and remove go to the server (#7999, #27135); remote Add and Sign in again are disabled with the reason "Add or re-authenticate accounts on that server"; a WSL lane on the web client uses accounts.selectCodexForTarget; the pane never targets an SSH host. So #20009 (remote add) stays open.

Linked Issue

Refs #20009 (not fixed by this PR; see the design adaptation above).

Visual Proof

N/A — no new UI. The visible difference is that the wrong server's accounts no longer appear after switching the default runtime mid-action; covered by the acceptance test below.

Testing

  • New AccountsPane.owner-scope.test.tsx: starts a select on server A, switches the pane to server B, then resolves A's result. It fails on main (A's [email protected] replaces B's roster) and passes with this change. A second test switches A → B → A and checks the late result is still applied.

  • pnpm test src/renderer/src/components/settings src/renderer/src/components/status-bar src/renderer/src/runtime/runtime-provider-accounts-client.test.ts (291 files pass), pnpm tc:web, oxlint, pnpm run check:code-quality:changed.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Renderer-only; no RPC or wire change. Local, WSL, Remote Orca Server and web client scopes all key the same way; SSH hosts never own this pane.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

m4air and others added 2 commits October 10, 2026 07:49
The Accounts pane kept one roster across default-runtime changes, so a
select or remove still in flight on the previous server overwrote the new
owner's roster when it returned. Key the pane by its account owner so
rosters, account ids and in-flight results are scoped to one owner.

Co-Authored-By: Claude <[email protected]>
…pane

Remounting lost an in-progress local login's spinner and Cancel button and
hid an account added after returning to the same owner. Guard each action's
result by the owner it was sent to instead.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

AccountsPane now tracks the provider-account owner key and passes an ownership check to the Codex and Claude account-action runners. The runners update the displayed roster only when the pane still shows the targeted owner. The owner-key helper is exported. Tests cover deferred Claude account selection across runtime environment changes.








Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 268ba

A narrowly timed account action can show the previous owner's roster after switching owners. Close that timing window before merging, or explicitly accept the bounded risk.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title is concise and clearly describes the main fix: preventing a late account result from one server from replacing another server's account roster.
Description check Passed The description is mostly complete. It explains the user impact, implementation, rationale, scope, linked issue, testing, visual proof, and compatibility considerations. The manual-testing checkbox an…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR







  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The toast, settings refresh and restart prompt describe what happened on
the owner the action went to; only the roster belongs to the shown owner.

Co-Authored-By: Claude <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c5b81ae3-822c-4b80-9668-c736929a7294
📥 Commits

Reviewing files that changed from the base of the PR and between 6cbbe45 and 268ba35.

📒 Files selected for processing (5)
  • src/renderer/src/components/settings/AccountsPane.owner-scope.test.tsx
  • src/renderer/src/components/settings/AccountsPane.section-lifetime.test.tsx
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/settings/accounts-pane-account-actions.ts
  • src/renderer/src/runtime/runtime-provider-accounts-client.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

Comment on lines +117 to +121
const currentAccountOwnerKeyRef = useRef(accountOwnerKey)
useEffect(() => {
currentAccountOwnerKeyRef.current = accountOwnerKey
}, [accountOwnerKey])
const isCurrentAccountOwner = (): boolean => currentAccountOwnerKeyRef.current === accountOwnerKey

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Update the owner ref in a layout effect, not a passive effect.

currentAccountOwnerKeyRef.current changes only inside useEffect. That effect runs after commit and paint. If a pending account action resolves between the commit for the new owner and that effect, isCurrentAccountOwner() still sees the old key. The stale roster is then applied to the new owner's pane. The new test does not expose this window, because act() flushes effects before the deferred promise resolves.

Use useLayoutEffect so the ref changes during the commit phase. Add a regression test that resolves the old action immediately after the rerender, before passive effects flush.

Proposed fix
-  useEffect(() => {
+  useLayoutEffect(() => {
     currentAccountOwnerKeyRef.current = accountOwnerKey
   }, [accountOwnerKey])

Also add useLayoutEffect to the react import.

Source: Learnings

@OrcaWin
OrcaWin merged commit ec1a01a into main Oct 10, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant