Repository navigation
fix(accounts): a server's late account result stays with that server - #27262
Conversation
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]>
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to 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 |
|
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]>
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c5b81ae3-822c-4b80-9668-c736929a7294
📒 Files selected for processing (5)
src/renderer/src/components/settings/AccountsPane.owner-scope.test.tsxsrc/renderer/src/components/settings/AccountsPane.section-lifetime.test.tsxsrc/renderer/src/components/settings/AccountsPane.tsxsrc/renderer/src/components/settings/accounts-pane-account-actions.tssrc/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.
| const currentAccountOwnerKeyRef = useRef(accountOwnerKey) | ||
| useEffect(() => { | ||
| currentAccountOwnerKeyRef.current = accountOwnerKey | ||
| }, [accountOwnerKey]) | ||
| const isCurrentAccountOwner = (): boolean => currentAccountOwnerKeyRef.current === accountOwnerKey |
There was a problem hiding this comment.
🎯 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
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
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/finishClaudeSignInrefuse paired clients and expect the caller to runclaude auth loginitself in a terminal, and the copied link calls back tolocalhoston 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 usesaccounts.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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)