Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

šŸ› fix(agent-quota): don't judge a bound device's Claude accounts by this desktop's logins (#21409)

Arvin Xuace77165bc50
diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/ClaudeCodeQuotaMenu.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/ClaudeCodeQuotaMenu.tsx
index 71b089159a0..9d100bb943e 100644
--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/ClaudeCodeQuotaMenu.tsx
+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/ClaudeCodeQuotaMenu.tsx
@@ -321,7 +321,12 @@ const ClaudeCodeQuotaMenu = memo<ClaudeCodeQuotaMenuProps>(({ deviceId, env }) =
title={t('heteroAgent.claudeQuota.title')}
tooltip={t('heteroAgent.claudeQuota.tooltip')}
renderHeader={(quota) => (
- <QuotaAccountSwitcher placement="top" provider="claude-code" snapshot={quota} />
+ <QuotaAccountSwitcher
+ deviceId={deviceId}
+ placement="top"
+ provider="claude-code"
+ snapshot={quota}
+ />
)}
/>
);
diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountManagerModal.test.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountManagerModal.test.tsx
index 5280d202fb0..d55d67e58e9 100644
--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountManagerModal.test.tsx
+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountManagerModal.test.tsx
@@ -14,6 +14,7 @@ import {
type QuotaAccount,
type QuotaBinding,
} from '@/store/agentQuota/projection';
+import { useElectronStore } from '@/store/electron';
import QuotaAccountManager from './QuotaAccountManagerModal';
import { isolateQuotaReplica } from './testUtils';
@@ -210,6 +211,7 @@ describe('QuotaAccountManager on the desktop', () => {
afterEach(() => {
desktop.value = false;
+ useElectronStore.setState({ gatewayDeviceInfo: undefined });
vi.restoreAllMocks();
});
@@ -222,6 +224,38 @@ describe('QuotaAccountManager on the desktop', () => {
expect(screen.getAllByText('heteroAgent.claudeQuota.manage.notSignedIn')).toHaveLength(1);
});
+ it('does not judge a remote device’s accounts by this desktop’s logins', async () => {
+ act(() =>
+ useElectronStore.setState({ gatewayDeviceInfo: { deviceId: 'this-desktop' } } as never),
+ );
+ renderWithFreshCache(<QuotaAccountManager agentId={'agent-1'} deviceId={'device-1'} />);
+
+ // The device holds its own logins: `away` may well be signed in there.
+ await screen.findByText('[email protected]');
+ await waitFor(() =>
+ expect(radioFor('[email protected]').getAttribute('aria-disabled')).not.toBe('true'),
+ );
+ expect(heterogeneousAgentService.listClaudeCodeAccounts).not.toHaveBeenCalled();
+ expect(screen.queryByText('heteroAgent.claudeQuota.manage.notSignedIn')).toBeNull();
+ expect(screen.queryByText('heteroAgent.claudeQuota.manage.signIn')).toBeNull();
+ // Signing in here would not reach the device, so no local sign-in entry either.
+ expect(
+ screen.queryByRole('button', { name: /heteroAgent\.claudeQuota\.manage\.add/ }),
+ ).toBeNull();
+ });
+
+ it('keeps local login checks when bound to this desktop’s own device', async () => {
+ act(() =>
+ useElectronStore.setState({ gatewayDeviceInfo: { deviceId: 'this-desktop' } } as never),
+ );
+ renderWithFreshCache(<QuotaAccountManager agentId={'agent-1'} deviceId={'this-desktop'} />);
+
+ // A gateway run on this device spawns on this desktop's logins.
+ await screen.findByText('heteroAgent.claudeQuota.manage.notSignedIn');
+ expect(radioFor('[email protected]').getAttribute('aria-disabled')).toBe('true');
+ expect(heterogeneousAgentService.listClaudeCodeAccounts).toHaveBeenCalled();
+ });
+
it('lists only Claude Code accounts, never another coding agent’s', async () => {
vi.mocked(agentQuotaService.listAccounts).mockResolvedValue([
account('here'),
diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountManagerModal.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountManagerModal.tsx
index af13c17043e..1af9b5b91e4 100644
--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountManagerModal.tsx
+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountManagerModal.tsx
@@ -35,6 +35,7 @@ import {
type QuotaLatestReading,
useAgentQuotaStore,
} from '@/store/agentQuota';
+import { useElectronStore } from '@/store/electron';
const styles = createStaticStyles(({ css }) => ({
footer: css`
@@ -118,7 +119,17 @@ const AccountReadingsSync = memo<{ accountId: string }>(({ accountId }) => {
AccountReadingsSync.displayName = 'AccountReadingsSync';
-const QuotaAccountManager = memo<{ agentId: string }>(({ agentId }) => {
+interface QuotaAccountManagerProps {
+ agentId: string;
+ /**
+ * Bound execution device the agent runs on. A remote device's logins live
+ * on that machine, not on the desktop showing this modal, so local sign-in
+ * state says nothing about which accounts it can run there.
+ */
+ deviceId?: string;
+}
+
+const QuotaAccountManager = memo<QuotaAccountManagerProps>(({ agentId, deviceId }) => {
const { t } = useTranslation('chat');
const [
useFetchQuotaAccounts,
@@ -144,8 +155,12 @@ const QuotaAccountManager = memo<{ agentId: string }>(({ agentId }) => {
const scope = cacheScope.use();
const { error: accountsError } = useFetchQuotaAccounts();
useFetchQuotaBindings(agentId);
- // Only the desktop runs Claude Code locally, so only it has logins to show.
- useFetchClaudeLocalAccounts(isDesktop);
+ // Only the desktop runs Claude Code locally, so only it has logins to show —
+ // and only when this agent runs here: in-process, or through the gateway on
+ // this desktop's own device row, which spawns on the same logins.
+ const currentDeviceId = useElectronStore((s) => s.gatewayDeviceInfo?.deviceId);
+ const managesLocalLogins = isDesktop && (!deviceId || deviceId === currentDeviceId);
+ useFetchClaudeLocalAccounts(managesLocalLogins);
const localAccounts = useAgentQuotaStore((s) => s.claudeLocalAccounts);
const loginPending = useAgentQuotaStore((s) => s.claudeLoginPending);
// A hydrated empty list may be an outdated snapshot: only the server's answer
@@ -213,14 +228,16 @@ const QuotaAccountManager = memo<{ agentId: string }>(({ agentId }) => {
);
/**
- * Whether a run on this desktop can use the account. Unknown (web, or the
- * logins not listed yet) counts as yes, so nothing is gated on a guess.
+ * Whether a run on this desktop can use the account. Unknown (web, a bound
+ * device, or the logins not listed yet) counts as yes, so nothing is gated
+ * on a guess.
*/
const signedInHere = useCallback(
(account: Account) =>
+ !managesLocalLogins ||
!localAccounts ||
localAccounts.some((l) => l.identity.externalAccountId === account.externalAccountId),
- [localAccounts],
+ [localAccounts, managesLocalLogins],
);
const pinnedId = bindings.find((b) => b.role === 'pinned')?.accountId;
@@ -500,7 +517,7 @@ const QuotaAccountManager = memo<{ agentId: string }>(({ agentId }) => {
{t('heteroAgent.claudeQuota.manage.confirmSwitch')}
</Button>
</Flexbox>
- ) : isDesktop ? (
+ ) : managesLocalLogins ? (
<Flexbox
horizontal
align={'center'}
@@ -540,9 +557,12 @@ const QuotaAccountManager = memo<{ agentId: string }>(({ agentId }) => {
QuotaAccountManager.displayName = 'QuotaAccountManager';
/** Calling this opens the modal — `createModal` mounts immediately. */
-export const openQuotaAccountManagerModal = (agentId: string): ModalInstance =>
+export const openQuotaAccountManagerModal = (
+ agentId: string,
+ options: { deviceId?: string } = {},
+): ModalInstance =>
createModal({
- content: <QuotaAccountManager agentId={agentId} />,
+ content: <QuotaAccountManager agentId={agentId} deviceId={options.deviceId} />,
footer: null,
title: i18nT('heteroAgent.claudeQuota.manage.title', { ns: 'chat' }),
width: 460,
diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountSwitcher.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountSwitcher.tsx
index 9693cc5166a..e089c43154f 100644
--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountSwitcher.tsx
+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaAccountSwitcher.tsx
@@ -29,17 +29,19 @@ const styles = createStaticStyles(({ css }) => ({
* per-account controls). The heavy lifting lives in QuotaAccountManagerModal.
*/
const QuotaAccountSwitcher = memo<{
+ /** Bound execution device the panel samples; the manager checks logins there, not here. */
+ deviceId?: string;
placement?: 'top' | 'bottom';
provider: QuotaCalendarProvider;
snapshot: { identity?: QuotaAccountIdentity | null };
-}>(({ snapshot, provider, placement = 'top' }) => {
+}>(({ deviceId, snapshot, provider, placement = 'top' }) => {
const { t } = useTranslation('chat');
const agentId = useAgentId();
const identity = snapshot.identity;
const openManager = useCallback(() => {
- if (agentId) openQuotaAccountManagerModal(agentId);
- }, [agentId]);
+ if (agentId) openQuotaAccountManagerModal(agentId, { deviceId });
+ }, [agentId, deviceId]);
if (!agentId) return null;