Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: separate create and sign-in phases with accurate partial failure states
Miguelon Peluchon140218c0f0c4
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.cssindex b1d4613b2..5cb47c16e 100644--- a/control-ui/app/globals.css+++ b/control-ui/app/globals.css@@ -8597,7 +8597,7 @@ textarea.cu-input {.cu-device-setup__step {margin: 0;color: var(--cu-text-soft);- font-size: 0.8125rem;+ font-size: var(--cu-font-size-sm);}.cu-device-setup__link {@@ -8605,8 +8605,8 @@ textarea.cu-input {}.cu-device-setup__code {- font-size: 1.05rem;- font-weight: 600;+ font-size: var(--cu-font-size-xl);+ font-weight: var(--cu-font-weight-semibold);letter-spacing: 0.14em;text-align: center;}@@ -8614,7 +8614,7 @@ textarea.cu-input {.cu-device-setup__note {margin: 0;color: var(--cu-text-muted);- font-size: 0.75rem;+ font-size: var(--cu-font-size-xs);}/* Wrapper that keeps a tooltip available on a disabled button (disableddiff --git a/control-ui/components/CodexSubscriptionHub/index.tsx b/control-ui/components/CodexSubscriptionHub/index.tsxindex c54b5e320..91cf4da38 100644--- a/control-ui/components/CodexSubscriptionHub/index.tsx+++ b/control-ui/components/CodexSubscriptionHub/index.tsx@@ -76,6 +76,9 @@ export function CodexSubscriptionHub() {>([])const [userCode, setUserCode] = useState<string | null>(null)const [verificationUri, setVerificationUri] = useState<string | null>(null)+ // Only true when window.open failed for the sign-in tab, so the card claims+ // a new tab opened only when one actually did.+ const [deviceTabBlocked, setDeviceTabBlocked] = useState(false)// Ported from dev: bumps whenever the dialog closes/reopens or a new connect// starts, so a stale device-poll loop (closed dialog, switched row) can no// longer touch state after it was abandoned.@@ -132,6 +135,9 @@ export function CodexSubscriptionHub() {// sign-in right away — by the time the operator approves the code, the// catalog is already synced server-side (connect handshake) and the models// grid is populated.+ // Create is its own phase: once the grant exists, nothing below may report+ // "creation failed" — later failures (table refresh, sign-in) are reported+ // as their own partial outcomes, and sign-in always gets a chance to start.async function handleCreate() {const displayName = editName.trim()if (!displayName) {@@ -139,19 +145,24 @@ export function CodexSubscriptionHub() {return}setBusyKey('create')+ let created: CodexSubscriptionConnectionViewtry {- const created = await createCodexSubscriptionConnection({ displayName })- setError('')- openEdit(created)- setSetupNew(true)- await load()- showToast(`Subscription ${displayName} created.`, { tone: 'success' })- // Ownership of busyKey hands over to handleConnect; it clears it when- // the device flow settles. Only the failure path resets it here.- void handleConnect(created)+ created = await createCodexSubscriptionConnection({ displayName })} catch (err) {setError(err instanceof Error ? err.message : 'Could not create subscription')setBusyKey(null)+ return+ }+ setError('')+ openEdit(created)+ setSetupNew(true)+ setBusyKey(null)+ // Sign-in starts regardless of whether the table refresh succeeds.+ void handleConnect(created)+ try {+ await load()+ } catch {+ showToast('Subscription created, but the list could not be refreshed.', { tone: 'info' })}}@@ -164,6 +175,7 @@ export function CodexSubscriptionHub() {setSetupNew(false)setUserCode(null)setVerificationUri(null)+ setDeviceTabBlocked(false)setError('')}@@ -175,6 +187,7 @@ export function CodexSubscriptionHub() {setSetupNew(false)setUserCode(null)setVerificationUri(null)+ setDeviceTabBlocked(false)setError('')if (row.status === 'connected') {try {@@ -198,6 +211,7 @@ export function CodexSubscriptionHub() {setSetupNew(false)setUserCode(null)setVerificationUri(null)+ setDeviceTabBlocked(false)void load().catch(err => {setError(err instanceof Error ? err.message : 'Failed to load ChatGPT subscriptions')})@@ -216,7 +230,9 @@ export function CodexSubscriptionHub() {defaultModel: editDefault.trim() || null,})setEditing(updated)- await load()+ // A refresh failure after a successful patch is partial — the update+ // itself landed, so it must not surface as "update failed".+ await load().catch(() => {})showToast(setupNew? `Subscription ${grantLabel(updated)} is ready.`@@ -237,11 +253,14 @@ export function CodexSubscriptionHub() {// Open the verification page synchronously, inside the click handler and// before any await — popup blockers honour user activation here, so the// tab reliably appears. The device code lands in the card right after.+ // The card only claims the tab opened when open() actually returned one.+ let openedTab: Window | null = nulltry {- window.open(CODEX_DEVICE_VERIFICATION_URI, '_blank', 'noopener,noreferrer')+ openedTab = window.open(CODEX_DEVICE_VERIFICATION_URI, '_blank', 'noopener,noreferrer')} catch {- // Blocked or unavailable — the card's link is the manual fallback.+ openedTab = null}+ setDeviceTabBlocked(!openedTab)try {const started = await startCodexDeviceConnect(row.status === 'connected' ? 'reconnect' : 'connect',@@ -264,7 +283,9 @@ export function CodexSubscriptionHub() {const models = await listCodexConnectionModels(latest.connectionKey)if (epoch !== connectEpoch.current) returnsetEditModels(models)- await load()+ // A table refresh failure here is partial — connect itself worked,+ // so it must not surface as "sign-in failed".+ await load().catch(() => {})if (epoch !== connectEpoch.current) return// The backend syncs the catalog during connect — surface the outcome.if (latest.catalogStatus === 'ready') {@@ -600,7 +621,9 @@ export function CodexSubscriptionHub() {{userCode ? (<div className="cu-device-setup" data-testid="codex-device-code"><p className="cu-device-setup__step">- 1. ChatGPT opened in a new tab — if it did not, use this link:+ {deviceTabBlocked+ ? '1. Open the ChatGPT verification page:'+ : '1. ChatGPT opened in a new tab — if it did not, use this link:'}</p>{(() => {// Locked fallback (from dev): even if the backenddiff --git a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsxindex e19b2f917..4196260cb 100644--- a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx+++ b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'import type { CodexSubscriptionConnectionView } from '@lib/codexSubscription'import {+ CODEX_DEVICE_VERIFICATION_URI,createCodexSubscriptionConnection,listCodexConnectionModels,listCodexSubscriptionConnections,@@ -98,7 +99,7 @@ describe('CodexSubscriptionHub', () => {)vi.mocked(startCodexDeviceConnect).mockResolvedValue({userCode: 'ABCD-1234',- verificationUri: 'https://chatgpt.com/device',+ verificationUri: CODEX_DEVICE_VERIFICATION_URI,intervalSeconds: 0.3,state: 'state-1',intent: 'connect',@@ -149,6 +150,65 @@ describe('CodexSubscriptionHub', () => {expect(revokeCodexSubscription).not.toHaveBeenCalled()})+ it('reports partial success and still starts sign-in when the post-create reload fails', async () => {+ vi.stubGlobal(+ 'open',+ vi.fn(() => ({}))+ )+ const listMock = vi.mocked(listCodexSubscriptionConnections)+ listMock+ .mockResolvedValueOnce([connection({ connectionKey: 'codex-aaa', displayName: 'Team A' })])+ .mockRejectedValueOnce(new Error('refresh boom'))+ .mockResolvedValue([connection({ connectionKey: 'codex-aaa', displayName: 'Team A' })])+ vi.mocked(createCodexSubscriptionConnection).mockResolvedValue(+ connection({+ connectionKey: 'codex-bbb',+ displayName: 'New team',+ status: 'disconnected',+ defaultModel: null,+ })+ )+ vi.mocked(startCodexDeviceConnect).mockResolvedValue({+ userCode: 'ABCD-1234',+ verificationUri: CODEX_DEVICE_VERIFICATION_URI,+ intervalSeconds: 0.3,+ state: 'state-1',+ intent: 'connect',+ })+ vi.mocked(pollCodexDevice).mockResolvedValue({+ status: 'connected',+ connection: connection({ connectionKey: 'codex-bbb', displayName: 'New team' }),+ })+ render(+ <ToastProvider>+ <CodexSubscriptionHub />+ </ToastProvider>+ )+ expect(await screen.findByText('Team A')).toBeInTheDocument()+ fireEvent.click(screen.getByRole('button', { name: 'Add subscription' }))+ fireEvent.change(screen.getByRole('textbox', { name: 'Name' }), {+ target: { value: 'New team' },+ })+ fireEvent.click(screen.getByRole('button', { name: 'Create and set up' }))+ await waitFor(() => {+ expect(createCodexSubscriptionConnection).toHaveBeenCalledWith({ displayName: 'New team' })+ })+ // The reload failure must not prevent sign-in from starting.+ await waitFor(() => {+ expect(startCodexDeviceConnect).toHaveBeenCalledWith('connect', 'codex-bbb')+ })+ // …and must be reported as partial success, not as a creation failure.+ expect(+ await screen.findByText('Subscription created, but the list could not be refreshed.')+ ).toBeInTheDocument()+ expect(screen.queryByText('Could not create subscription')).not.toBeInTheDocument()+ expect(screen.queryByText('refresh boom')).not.toBeInTheDocument()+ // The setup flow still completes once the device connect settles.+ await waitFor(() => {+ expect(listCodexConnectionModels).toHaveBeenCalledWith('codex-bbb')+ })+ })+it('renders subscriptions as a Secrets table with a row actions menu', async () => {render(<ToastProvider>@@ -176,7 +236,7 @@ describe('CodexSubscriptionHub', () => {it('opens the grant modal for reconnect and model toggles without binding hosts', async () => {vi.mocked(startCodexDeviceConnect).mockResolvedValue({userCode: 'ABCD-1234',- verificationUri: 'https://chatgpt.com/device',+ verificationUri: CODEX_DEVICE_VERIFICATION_URI,intervalSeconds: 1,state: 'state-1',intent: 'reconnect',@@ -219,7 +279,7 @@ describe('CodexSubscriptionHub', () => {vi.stubGlobal('open', openMock)vi.mocked(startCodexDeviceConnect).mockResolvedValue({userCode: 'ABCD-1234',- verificationUri: 'https://chatgpt.com/device',+ verificationUri: CODEX_DEVICE_VERIFICATION_URI,// Long enough that the card is observable; short enough that the// auto-dismiss waitFor completes comfortably inside its timeout.intervalSeconds: 0.3,@@ -249,7 +309,7 @@ describe('CodexSubscriptionHub', () => {'noopener,noreferrer')const link = screen.getByTestId('codex-device-verification-link')- expect(link).toHaveAttribute('href', 'https://chatgpt.com/device')+ expect(link).toHaveAttribute('href', CODEX_DEVICE_VERIFICATION_URI)expect(link).toHaveAttribute('target', '_blank')expect(screen.getByRole('button', { name: 'Copy sign-in link' })).toBeInTheDocument()expect(screen.getByRole('button', { name: 'Copy code' })).toBeInTheDocument()diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 79d634013..a7870870c 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.483",+ "version": "0.1.484","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.483",+ "version": "0.1.484","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-ui/package.json b/control-ui/package.jsonindex aeb174a9b..ddc3b5e54 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.483",+ "version": "0.1.484","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",