From c28b8befe150de312431de49a03c999a801a28db Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Tue, 13 Oct 2026 19:54:19 +0200 Subject: [PATCH 1/2] fix(platform): keep a sandbox row menu open while the page re-renders useMutation returns a new object on every render, and the table's column definitions depended on those objects. TanStack renders a cell function as a component type, so a new definition remounted every cell: an open row menu closed and focus went to the page whenever the component re-rendered, for instance when the reconcile request settled just after the menu opened. The columns now depend on the stable async triggers. The stop-task suite hit it on loaded runners: it failed about half the runs of UI shard 3/4 in CI, and 12 of 12 when twelve copies ran at once locally (the trigger was gone from the page, the menu never opened). Its query mock also built new data on every call, which a cache never does; each read now keeps one identity. The same twelve copies pass. --- .../sandboxes-settings.stop-task.test.tsx | 80 +++++++++++-------- .../settings/sandboxes/sandboxes-settings.tsx | 21 ++++- 2 files changed, 66 insertions(+), 35 deletions(-) diff --git a/services/platform/app/features/settings/sandboxes/sandboxes-settings.stop-task.test.tsx b/services/platform/app/features/settings/sandboxes/sandboxes-settings.stop-task.test.tsx index f55d6e7134..39f2f9a279 100644 --- a/services/platform/app/features/settings/sandboxes/sandboxes-settings.stop-task.test.tsx +++ b/services/platform/app/features/settings/sandboxes/sandboxes-settings.stop-task.test.tsx @@ -38,43 +38,59 @@ vi.mock('@tanstack/react-router', async (importOriginal) => ({ {children} ), })); +// Each read keeps one identity across renders, as the cache's own data does: a +// fresh object per call would change the table's column definitions on every +// render, and a changed definition remounts every cell under an open row menu. +const reads = vi.hoisted(() => { + const refetch = vi.fn(); + const read = (data: unknown) => ({ + data, + isLoading: false, + isFetching: false, + isError: false, + refetch, + }); + return { + sessions: read({ + sessions: [ + { + sessionId: 'owned', + ownerType: 'project_agent', + ownerId: 'agent-alice', + ownerLabel: 'Alice', + worker: { number: 1, scope: 'agent' }, + createdBy: 'system:task-agent', + status: 'active', + createdAt: 1_750_000_000_000, + pinned: false, + busy: true, + totalSpentCents: 0, + currentOp: null, + runningOps: [], + }, + ], + waitingRuns: { total: 0, byReason: {} }, + }), + limits: read({ status: 'available', maxSessions: 16 }), + usage: read([]), + devices: read({ devices: [], hub: 'available', serverVersion: '0.5.60' }), + policy: read(null), + other: read({ status: 'unavailable', reason: 'not_configured' }), + }; +}); vi.mock('@/app/hooks/use-backend-query', () => ({ - useBackendQuery: (name: string) => ({ - data: name.endsWith(':listSandboxesForOrg') - ? { - sessions: [ - { - sessionId: 'owned', - ownerType: 'project_agent', - ownerId: 'agent-alice', - ownerLabel: 'Alice', - worker: { number: 1, scope: 'agent' }, - createdBy: 'system:task-agent', - status: 'active', - createdAt: 1_750_000_000_000, - pinned: false, - busy: true, - totalSpentCents: 0, - currentOp: null, - runningOps: [], - }, - ], - waitingRuns: { total: 0, byReason: {} }, - } + useBackendQuery: (name: string) => + name.endsWith(':listSandboxesForOrg') + ? reads.sessions : name.endsWith(':getSandboxDeploymentLimits') - ? { status: 'available', maxSessions: 16 } + ? reads.limits : name.endsWith(':getSandboxQuotaUsage') - ? [] + ? reads.usage : name === 'sandbox_devices/queries:list' - ? { devices: [], hub: 'available', serverVersion: '0.5.60' } + ? reads.devices : name === 'governance/queries:getPolicy' - ? null - : { status: 'unavailable', reason: 'not_configured' }, - isLoading: false, - isFetching: false, - isError: false, - refetch: vi.fn(), - }), + ? reads.policy + : reads.other, })); const refusalCopy = { diff --git a/services/platform/app/features/settings/sandboxes/sandboxes-settings.tsx b/services/platform/app/features/settings/sandboxes/sandboxes-settings.tsx index 3b585c85d0..26536fdcaa 100644 --- a/services/platform/app/features/settings/sandboxes/sandboxes-settings.tsx +++ b/services/platform/app/features/settings/sandboxes/sandboxes-settings.tsx @@ -100,6 +100,12 @@ export function SandboxesSettings({ organizationId }: SandboxesSettingsProps) { 'node_only/sandbox/session_admin_actions:setSandboxPinned', { errorToast: false }, ); + // `useMutation` returns a new object on every render, but its async trigger + // stays the same. The column definitions below depend on the triggers, not + // the objects: a changed definition remounts every cell, and an open row + // menu closes with it. + const stopTask = stop.mutateAsync; + const setSandboxPinned = setPinned.mutateAsync; // Reconcile business allocation records on mount. Physical runtime state // comes from the separate infrastructure snapshot below. @@ -371,7 +377,7 @@ export function SandboxesSettings({ organizationId }: SandboxesSettingsProps) { void run( s.sessionId, () => - stop.mutateAsync({ + stopTask({ organizationId, sessionId: s.sessionId, }), @@ -390,7 +396,7 @@ export function SandboxesSettings({ organizationId }: SandboxesSettingsProps) { void run( s.sessionId, () => - setPinned.mutateAsync({ + setSandboxPinned({ organizationId, sessionId: s.sessionId, pinned: !s.pinned, @@ -415,7 +421,16 @@ export function SandboxesSettings({ organizationId }: SandboxesSettingsProps) { }, }, ], - [t, organizationId, pendingId, stop, setPinned, run, snapshot, devicesView], + [ + t, + organizationId, + pendingId, + stopTask, + setSandboxPinned, + run, + snapshot, + devicesView, + ], ); if ((canManage && data === null) || (!abilityLoading && !canRead)) { From 66eb956963302339e9f39814fca8c235fe6f2de2 Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Tue, 13 Oct 2026 19:54:26 +0200 Subject: [PATCH 2/2] test(platform): wait for the connect dialog to fade in before its audit axe skips a fully transparent dialog and fails a nearly transparent one. CI starts the audit a few frames into the dialog's fade, so it judged the text at a few percent (1.07:1) in the connected case, in both themes. Locally the audit starts at the first frame and passes. With the fade stretched and the audit started 60 ms in, the old test fails all four cases with the same reading. Wait for the animations that end; the waiting dot pulses for good and would never settle. --- .../connect-agent-dialog.browser.test.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/services/platform/app/features/coding-agent/components/connect-agent-dialog.browser.test.tsx b/services/platform/app/features/coding-agent/components/connect-agent-dialog.browser.test.tsx index 6eac5caef4..2f627245d6 100644 --- a/services/platform/app/features/coding-agent/components/connect-agent-dialog.browser.test.tsx +++ b/services/platform/app/features/coding-agent/components/connect-agent-dialog.browser.test.tsx @@ -145,6 +145,19 @@ describe('the connect dialog in both themes', () => { await i18n.changeLanguage('en'); renderDialog(); const dialog = await screen.findByRole('dialog'); + // The dialog and its overlay fade in, and axe reads the opacity of + // every ancestor: an audit that starts a few frames in judges the text + // at a few percent. The waiting dot pulses for good, so only the + // animations that end are awaited. + await Promise.allSettled( + document + .getAnimations() + .filter( + (animation) => + animation.effect?.getComputedTiming().iterations !== Infinity, + ) + .map((animation) => animation.finished), + ); const result = await axe.run(dialog, { runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21aa'] }, });