From d1502d1d53cc2f373283fbfc13e6bd06dd317002 Mon Sep 17 00:00:00 2001 From: Merge Sim Date: Fri, 11 Sep 2026 00:42:34 -0700 Subject: [PATCH 1/6] fix(mobile): stop a created tab from jumping when the host snapshot lands Creating a tab from the mobile session strip painted the new tab at the end of the strip and then visibly jumped it to a different slot a beat later. The client asked the host to insert the tab after the active tab, but then predicted a different placement for its own optimistic paint: afterTabId: activeSessionTabId ?? undefined // host: splice(insertAfter + 1) ... return [...prev, { ...created, isActive: true }] // client: append Two independent placements that disagree, so the optimistic frame is wrong by construction and the tab snaps to its real slot on the next published snapshot. The disagreement dates to 57a70d2ac0 ("Fix mobile session tab authority"), which introduced afterTabId and left the append in place. Before that the client used terminal.create with no anchor, so both sides appended and agreed. Rather than teach the client to re-derive the host's rule, both sides now call one shared placeCreatedSessionTab, and the client captures a single afterTabId for the request and the paint so they cannot drift apart again. The host change is a pure refactor onto the shared helper; the 1260-test runtime characterization suite is unchanged. The mobile route-parity hash pin moves once because handleCreateTerminal's body changed - it is the only one of the 12 extracted functions that differs. --- .../mobile-session-route-parity.test.ts | 5 +- ...le-session-terminal-create-actions.test.ts | 75 +++++++++++++++++++ ...-mobile-session-terminal-create-actions.ts | 8 +- ...e-runtime-owned-mobile-session-terminal.ts | 17 ++--- src/shared/session-tab-placement.test.ts | 47 ++++++++++++ src/shared/session-tab-placement.ts | 22 ++++++ 6 files changed, 161 insertions(+), 13 deletions(-) create mode 100644 src/shared/session-tab-placement.test.ts create mode 100644 src/shared/session-tab-placement.ts diff --git a/mobile/src/session/mobile-session-route-parity.test.ts b/mobile/src/session/mobile-session-route-parity.test.ts index 3a6b04661dec..e315b353ee35 100644 --- a/mobile/src/session/mobile-session-route-parity.test.ts +++ b/mobile/src/session/mobile-session-route-parity.test.ts @@ -69,8 +69,11 @@ const HEAD_CALLBACK_IDENTITY_SHA256 = const HEAD_CALLBACK_BODY_SHA256 = 'af7f3c62954250d4be7ee432ecd10dc2689792aad8230fed2d1d68bbc892d776' const HEAD_EFFECT_SHA256 = 'd9ebfaabc1e79773cdada7ab370b20459ed972f1f8edce1652199f4d0391cd13' const HEAD_CONTENT_HOOK_SHA256 = '9c3b612fef3f370d66873aefdbe1d701f20cb64ded31fef5cc45fde6f8189581' +// Moved once for the create-tab placement fix: handleCreateTerminal now paints the created tab +// after the anchor it sent the host instead of appending. Only that body changed; the other 11 +// extracted functions are byte-identical. const HEAD_NESTED_FUNCTION_SHA256 = - 'fde6679349ab2b8c30c7e627841ff99bd1dd24441ee95323d0aa70230422ae24' + '90b88dfc168c664d87b240af14f6c4e19fa506a3d1005fcd9ef29df1befc810c' const HEAD_NATIVE_REGISTRATION_SHA256 = 'cab85e4e4a3f43289ba93ddea9ccce57aea83e0bf14fd1620a965aad0c1cb49e' const HEAD_NATIVE_REMOVAL_SHA256 = diff --git a/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts b/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts index e46bf087f386..847ad1316c0e 100644 --- a/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts +++ b/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts @@ -262,3 +262,78 @@ describe('mobile + Codex tab creation routing', () => { } ) }) + +describe('optimistic placement of a created tab', () => { + let renderer: ReactTestRenderer | undefined + afterEach(() => renderer?.unmount()) + + async function createLegacyTerminal(scope: ReturnType) { + let actions: ReturnType | undefined + function Harness() { + actions = useMobileSessionTerminalCreateActions(scope as never) + return null + } + await act(async () => { + renderer = create(createElement(Harness)) + }) + await act(async () => { + await actions?.handleCreateTerminal() + }) + } + + function tabIdsAfterCreate( + scope: ReturnType, + prior: { id: string }[] + ): string[] { + const updater = (scope.setSessionTabs as ReturnType).mock.calls.at(-1)?.[0] as ( + prev: { id: string }[] + ) => { id: string }[] + return updater(prior).map((tab) => tab.id) + } + + it('paints the created tab after the anchor it asked the host for, not at the end', async () => { + const scope = createScope(clientReturning(terminalCreateResponse())) + await createLegacyTerminal(scope) + + expect(scope.setSessionTabs).toHaveBeenCalled() + // The request anchored on the active tab, so the paint must land in the same slot the host + // splices into; appending here is what made the tab jump on the next snapshot. + expect(tabIdsAfterCreate(scope, [{ id: 'existing-tab' }, { id: 'trailing-tab' }])).toEqual([ + 'existing-tab', + 'terminal-tab-1', + 'trailing-tab' + ]) + }) + + it('sends the same anchor it paints with', async () => { + const scope = createScope(clientReturning(terminalCreateResponse())) + await createLegacyTerminal(scope) + + expect(scope.client.sendRequest).toHaveBeenCalledWith( + 'session.tabs.createTerminal', + expect.objectContaining({ afterTabId: 'existing-tab' }) + ) + }) + + it('appends when the anchor is not in the client list, matching the host fallback', async () => { + const scope = createScope(clientReturning(terminalCreateResponse())) + await createLegacyTerminal(scope) + + expect(tabIdsAfterCreate(scope, [{ id: 'unrelated-tab' }])).toEqual([ + 'unrelated-tab', + 'terminal-tab-1' + ]) + }) + + it('leaves the list alone when the host snapshot already placed the tab', async () => { + const scope = createScope(clientReturning(terminalCreateResponse())) + await createLegacyTerminal(scope) + + const prior = [{ id: 'existing-tab' }, { id: 'terminal-tab-1' }, { id: 'trailing-tab' }] + expect(tabIdsAfterCreate(scope, prior)).toEqual([ + 'existing-tab', + 'terminal-tab-1', + 'trailing-tab' + ]) + }) +}) diff --git a/mobile/src/session/use-mobile-session-terminal-create-actions.ts b/mobile/src/session/use-mobile-session-terminal-create-actions.ts index cf6e9441d100..11548876f60f 100644 --- a/mobile/src/session/use-mobile-session-terminal-create-actions.ts +++ b/mobile/src/session/use-mobile-session-terminal-create-actions.ts @@ -12,6 +12,7 @@ import type { Terminal, TerminalCreateResult } from './mobile-session-route-type import type { MobileSessionAttachmentsModel } from './use-mobile-session-attachments' import { isAgentSessionHandleProvider } from '../../../src/shared/agent-session-provider-handle' import { createMobileStructuredAgentSession } from './mobile-structured-agent-session-launch' +import { placeCreatedSessionTab } from '../../../src/shared/session-tab-placement' export function useMobileSessionTerminalCreateActions(scope: MobileSessionAttachmentsModel) { const { @@ -93,9 +94,12 @@ export function useMobileSessionTerminalCreateActions(scope: MobileSessionAttach return } } + // Why: one anchor for both the request and the optimistic paint below; when they disagreed the + // new tab painted at the end and jumped to its real slot on the next host snapshot. + const afterTabId = activeSessionTabId ?? undefined const response = await client.sendRequest('session.tabs.createTerminal', { worktree: `id:${worktreeId}`, - afterTabId: activeSessionTabId ?? undefined, + afterTabId, clientMutationId, ...(options?.startupCommand ? { command: options.startupCommand } : {}), ...(options?.startupCommandDelivery @@ -123,7 +127,7 @@ export function useMobileSessionTerminalCreateActions(scope: MobileSessionAttach if (prev.some((tab) => tab.id === created.id)) { return prev } - return [...prev, { ...created, isActive: true }] + return placeCreatedSessionTab(prev, { ...created, isActive: true }, afterTabId) }) if (typeof created.terminal === 'string') { const createdHandle = created.terminal diff --git a/src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts b/src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts index 1bb45f838e0f..49c7bbf766cc 100644 --- a/src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts +++ b/src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts @@ -10,6 +10,7 @@ import type { } from '../../shared/runtime-types' import { randomUUID } from 'node:crypto' import { parsePaneKey } from '../../shared/stable-pane-id' +import { placeCreatedSessionTab } from '../../shared/session-tab-placement' import { buildHeadlessMobileSessionTabGroups, buildMaterializedHeadlessParentLayout, @@ -103,21 +104,17 @@ export class OrcaRuntimeWithCreateRuntimeOwnedMobileSessionTerminal extends Orca parentLayout, isActive: activate } - const tabs = (existing?.tabs ?? []) - .filter((candidate) => candidate.id !== tab.id) - .map((candidate) => ({ + const tabs = placeCreatedSessionTab( + (existing?.tabs ?? []).map((candidate) => ({ ...candidate, ...(candidate.type === 'terminal' && candidate.parentTabId === parentTabId ? { parentLayout } : {}), isActive: activate ? false : candidate.isActive - })) - const insertAfter = afterTabId ? tabs.findIndex((candidate) => candidate.id === afterTabId) : -1 - if (insertAfter >= 0) { - tabs.splice(insertAfter + 1, 0, tab) - } else { - tabs.push(tab) - } + })), + tab, + afterTabId + ) const next: RuntimeMobileSessionTabsSnapshot = { worktree: worktreeId, // Why: a fresh epoch retires the current publisher, so clients drop its later tab updates. diff --git a/src/shared/session-tab-placement.test.ts b/src/shared/session-tab-placement.test.ts new file mode 100644 index 000000000000..f57d2ebf9cba --- /dev/null +++ b/src/shared/session-tab-placement.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, it } from 'vitest' +import { placeCreatedSessionTab } from './session-tab-placement' + +const created = { id: 'new' } + +describe('placeCreatedSessionTab', () => { + it('inserts directly after the anchor', () => { + expect( + placeCreatedSessionTab([{ id: 'a' }, { id: 'b' }, { id: 'c' }], created, 'a').map((t) => t.id) + ).toEqual(['a', 'new', 'b', 'c']) + }) + + it('appends when the anchor is the last tab', () => { + expect( + placeCreatedSessionTab([{ id: 'a' }, { id: 'b' }], created, 'b').map((t) => t.id) + ).toEqual(['a', 'b', 'new']) + }) + + it('appends when the anchor is absent', () => { + expect( + placeCreatedSessionTab([{ id: 'a' }, { id: 'b' }], created, 'missing').map((t) => t.id) + ).toEqual(['a', 'b', 'new']) + }) + + it('appends when no anchor is given', () => { + for (const anchor of [undefined, null, '']) { + expect(placeCreatedSessionTab([{ id: 'a' }], created, anchor).map((t) => t.id)).toEqual([ + 'a', + 'new' + ]) + } + }) + + it('re-places a tab that is already in the list instead of duplicating it', () => { + expect( + placeCreatedSessionTab([{ id: 'a' }, { id: 'new' }, { id: 'b' }], created, 'b').map( + (t) => t.id + ) + ).toEqual(['a', 'b', 'new']) + }) + + it('does not mutate the input list', () => { + const tabs = [{ id: 'a' }, { id: 'b' }] + placeCreatedSessionTab(tabs, created, 'a') + expect(tabs.map((t) => t.id)).toEqual(['a', 'b']) + }) +}) diff --git a/src/shared/session-tab-placement.ts b/src/shared/session-tab-placement.ts new file mode 100644 index 000000000000..7409414daf36 --- /dev/null +++ b/src/shared/session-tab-placement.ts @@ -0,0 +1,22 @@ +/** + * Where a newly created session tab lands in a tab list. + * + * Shared because a client that optimistically paints a created tab and the host that publishes + * the authoritative snapshot must agree. When they disagreed — the client appending while the + * host spliced after `afterTabId` — the new tab painted at the end and then visibly jumped to its + * real slot as soon as the host frame landed. + */ +export function placeCreatedSessionTab( + tabs: readonly T[], + created: T, + afterTabId: string | null | undefined +): T[] { + const next = tabs.filter((tab) => tab.id !== created.id) + const anchor = afterTabId ? next.findIndex((tab) => tab.id === afterTabId) : -1 + if (anchor < 0) { + next.push(created) + return next + } + next.splice(anchor + 1, 0, created) + return next +} From ff8ebfb43856b7dbdcc4aafe4019ac7b0d88a44d Mon Sep 17 00:00:00 2001 From: Merge Sim Date: Fri, 11 Sep 2026 10:11:20 -0700 Subject: [PATCH 2/6] fix(mobile): keep split terminal placement stable --- ...le-session-terminal-create-actions.test.ts | 14 +++++ .../mobile-session-tabs-part-03.spec.ts | 58 +++++++++++++++++++ src/shared/session-tab-placement.test.ts | 14 +++++ src/shared/session-tab-placement.ts | 23 ++++---- 4 files changed, 99 insertions(+), 10 deletions(-) diff --git a/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts b/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts index 847ad1316c0e..89a9074fa88f 100644 --- a/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts +++ b/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts @@ -305,6 +305,20 @@ describe('optimistic placement of a created tab', () => { ]) }) + it('paints after the active split parent, matching headed host placement', async () => { + const scope = createScope(clientReturning(terminalCreateResponse())) + scope.activeSessionTabId = 'existing-tab::left' + await createLegacyTerminal(scope) + + expect( + tabIdsAfterCreate(scope, [ + { id: 'existing-tab::left', parentTabId: 'existing-tab' }, + { id: 'existing-tab::right', parentTabId: 'existing-tab' }, + { id: 'trailing-tab' } + ]) + ).toEqual(['existing-tab::left', 'existing-tab::right', 'terminal-tab-1', 'trailing-tab']) + }) + it('sends the same anchor it paints with', async () => { const scope = createScope(clientReturning(terminalCreateResponse())) await createLegacyTerminal(scope) diff --git a/src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-03.spec.ts b/src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-03.spec.ts index 55c3aae41707..e3aa0774fa5b 100644 --- a/src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-03.spec.ts +++ b/src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-03.spec.ts @@ -303,6 +303,64 @@ describe('OrcaRuntimeService', () => { ]) }) + it('places a runtime-owned terminal after every leaf in the anchored split parent', async () => { + const runtime = new OrcaRuntimeService(store) + runtime.setPtyController({ + spawn: vi.fn().mockResolvedValue({ id: 'pty-created-after-split' }), + write: () => true, + kill: () => true, + getForegroundProcess: async () => null + }) + runtime.syncWindowGraph(0, { + tabs: [], + leaves: [], + mobileSessionTabs: [ + { + worktree: TEST_WORKTREE_ID, + publicationEpoch: 'headless:split-placement', + snapshotVersion: 1, + activeGroupId: 'group-1', + activeTabId: 'split::left', + activeTabType: 'terminal', + tabs: [ + { + type: 'terminal', + id: 'split::left', + parentTabId: 'split', + leafId: 'left', + title: 'Split', + isActive: true + }, + { + type: 'terminal', + id: 'split::right', + parentTabId: 'split', + leafId: 'right', + title: 'Split', + isActive: false + }, + { + type: 'terminal', + id: 'trailing::leaf', + parentTabId: 'trailing', + leafId: 'leaf', + title: 'Trailing', + isActive: false + } + ] + } + ] + }) + + const created = await runtime.createMobileSessionTerminal(`id:${TEST_WORKTREE_ID}`, { + afterTabId: 'split::left' + }) + + expect( + (await runtime.listMobileSessionTabs(`id:${TEST_WORKTREE_ID}`)).tabs.map((tab) => tab.id) + ).toEqual(['split::left', 'split::right', created.tab.id, 'trailing::leaf']) + }) + it('leases renderer publication for a paired create and preserves host-owned inventory', async () => { const leafId = '91919191-9191-4919-8919-919191919191' const spawn = vi.fn() diff --git a/src/shared/session-tab-placement.test.ts b/src/shared/session-tab-placement.test.ts index f57d2ebf9cba..8ce0cd8c0f8d 100644 --- a/src/shared/session-tab-placement.test.ts +++ b/src/shared/session-tab-placement.test.ts @@ -10,6 +10,20 @@ describe('placeCreatedSessionTab', () => { ).toEqual(['a', 'new', 'b', 'c']) }) + it('inserts after all leaves of a split parent', () => { + expect( + placeCreatedSessionTab( + [ + { id: 'split::left', parentTabId: 'split' }, + { id: 'split::right', parentTabId: 'split' }, + { id: 'trailing' } + ], + { id: 'new' }, + 'split::left' + ).map((tab) => tab.id) + ).toEqual(['split::left', 'split::right', 'new', 'trailing']) + }) + it('appends when the anchor is the last tab', () => { expect( placeCreatedSessionTab([{ id: 'a' }, { id: 'b' }], created, 'b').map((t) => t.id) diff --git a/src/shared/session-tab-placement.ts b/src/shared/session-tab-placement.ts index 7409414daf36..dd810424c4e0 100644 --- a/src/shared/session-tab-placement.ts +++ b/src/shared/session-tab-placement.ts @@ -1,12 +1,5 @@ -/** - * Where a newly created session tab lands in a tab list. - * - * Shared because a client that optimistically paints a created tab and the host that publishes - * the authoritative snapshot must agree. When they disagreed — the client appending while the - * host spliced after `afterTabId` — the new tab painted at the end and then visibly jumped to its - * real slot as soon as the host frame landed. - */ -export function placeCreatedSessionTab( +/** Places a created tab after the anchor's top-level terminal group, or appends when unanchored. */ +export function placeCreatedSessionTab( tabs: readonly T[], created: T, afterTabId: string | null | undefined @@ -17,6 +10,16 @@ export function placeCreatedSessionTab( next.push(created) return next } - next.splice(anchor + 1, 0, created) + let insertAfter = anchor + const anchorParentTabId = next[anchor].parentTabId + if (anchorParentTabId) { + while ( + insertAfter + 1 < next.length && + next[insertAfter + 1].parentTabId === anchorParentTabId + ) { + insertAfter += 1 + } + } + next.splice(insertAfter + 1, 0, created) return next } From 37568ef72952ef5847fd8eb34b6325928892a4ce Mon Sep 17 00:00:00 2001 From: Merge Sim Date: Fri, 11 Sep 2026 10:30:44 -0700 Subject: [PATCH 3/6] fix(mobile): negotiate split tab placement --- .../mobile-session-route-parity.test.ts | 8 ++-- .../session/use-mobile-session-foundation.ts | 3 ++ ...le-session-terminal-create-actions.test.ts | 17 ++++++++ ...-mobile-session-terminal-create-actions.ts | 8 +++- ...mobile-runtime-client-capabilities.test.ts | 4 +- .../mobile-runtime-client-capabilities.ts | 2 + ...-runtime-create-mobile-session-terminal.ts | 3 ++ ...e-runtime-owned-mobile-session-terminal.ts | 4 +- ...time-run-create-mobile-session-terminal.ts | 22 +++++++--- .../runtime-availability.spec.ts | 1 + .../runtime/rpc/methods/session-tabs.test.ts | 40 ++++++++++++++++++- src/main/runtime/rpc/methods/session-tabs.ts | 14 ++++++- src/shared/protocol-version.ts | 6 +++ src/shared/session-tab-placement.test.ts | 32 ++++++++++++++- src/shared/session-tab-placement.ts | 20 ++++++---- 15 files changed, 161 insertions(+), 23 deletions(-) diff --git a/mobile/src/session/mobile-session-route-parity.test.ts b/mobile/src/session/mobile-session-route-parity.test.ts index e315b353ee35..4bf325a930c3 100644 --- a/mobile/src/session/mobile-session-route-parity.test.ts +++ b/mobile/src/session/mobile-session-route-parity.test.ts @@ -62,8 +62,8 @@ const HOST_COMPONENT_NAMES = new Set([ 'View' ]) -const HEAD_MAIN_HOOK_SHA256 = '10071240ef9edafc2b9c8bed73be83dceaf7828e3b29f17dab55da020a7697a6' -const HEAD_HOOK_BINDING_SHA256 = '1dadb8c3dc0573ea20659ce7251629669e618dd0effaeac3a4536b29c2e865a1' +const HEAD_MAIN_HOOK_SHA256 = '5c18b82b70218f71ea9eff5316ee2e1e9b6555bc1ea2f19f24ede519a5933857' +const HEAD_HOOK_BINDING_SHA256 = '9ee9c7d7d651e001499d906428a0987994a291517911cef7d529d41e4c61cb62' const HEAD_CALLBACK_IDENTITY_SHA256 = '2a9e4825df007f6ef53b81aa5004991d6318eee7507b44d625c07e630be432eb' const HEAD_CALLBACK_BODY_SHA256 = 'af7f3c62954250d4be7ee432ecd10dc2689792aad8230fed2d1d68bbc892d776' @@ -73,7 +73,7 @@ const HEAD_CONTENT_HOOK_SHA256 = '9c3b612fef3f370d66873aefdbe1d701f20cb64ded31fe // after the anchor it sent the host instead of appending. Only that body changed; the other 11 // extracted functions are byte-identical. const HEAD_NESTED_FUNCTION_SHA256 = - '90b88dfc168c664d87b240af14f6c4e19fa506a3d1005fcd9ef29df1befc810c' + 'e54db6971e298dc27b59da9cbb2c455b85f0e1224cdf00482410ac43d179b02d' const HEAD_NATIVE_REGISTRATION_SHA256 = 'cab85e4e4a3f43289ba93ddea9ccce57aea83e0bf14fd1620a965aad0c1cb49e' const HEAD_NATIVE_REMOVAL_SHA256 = @@ -475,7 +475,7 @@ describe('mobile session route extraction parity', () => { const contentBindings = CONTENT_COMPONENT_NAMES.flatMap( (name) => readHookFacts(name, definitions).bindings ) - expect(main.hooks).toHaveLength(266) + expect(main.hooks).toHaveLength(267) expect(hash(main.hooks)).toBe(HEAD_MAIN_HOOK_SHA256) expect(hash(main.bindings)).toBe(HEAD_HOOK_BINDING_SHA256) expect(main.callbacks).toHaveLength(77) diff --git a/mobile/src/session/use-mobile-session-foundation.ts b/mobile/src/session/use-mobile-session-foundation.ts index fa2f9607bbc1..80a67a357020 100644 --- a/mobile/src/session/use-mobile-session-foundation.ts +++ b/mobile/src/session/use-mobile-session-foundation.ts @@ -14,6 +14,7 @@ import { isFloatingWorkspaceWorktreeId } from './floating-workspace' import { useLiveWorktreeName } from './use-live-worktree-name' import { useMissingWorktreeBounce } from './use-missing-worktree-bounce' import { hostRouteWithNotice } from '../host-route-notice' +import { useHostProtocolGates } from '../components/HostProtocolGate' export function useMobileSessionFoundation() { const { @@ -36,6 +37,7 @@ export function useMobileSessionFoundation() { const insets = useSafeAreaInsets() // Why: shared client per host owned by RpcClientProvider (docs/mobile-shared-client-per-host.md). const { client, clientId, state: connState } = useHostClient(hostId) + const { hostCapabilities } = useHostProtocolGates() const reconnectAttempts = useReconnectAttempt(hostId) const lastConnectedAt = useLastConnectedAt(hostId) const forceReconnectHost = useForceReconnect() @@ -98,6 +100,7 @@ export function useMobileSessionFoundation() { client, clientId, connState, + hostCapabilities, reconnectAttempts, lastConnectedAt, forceReconnectHost, diff --git a/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts b/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts index 89a9074fa88f..4e097a1fc1cf 100644 --- a/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts +++ b/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts @@ -4,6 +4,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import type { RpcClient } from '../transport/rpc-client' import { markRpcDeliveryUnknown } from '../transport/rpc-delivery-ambiguity' import { useMobileSessionTerminalCreateActions } from './use-mobile-session-terminal-create-actions' +import { SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY } from '../../../src/shared/protocol-version' vi.mock('../platform/haptics', () => ({ triggerSuccess: vi.fn(), @@ -36,6 +37,7 @@ function createScope(client: RpcClient) { return { worktreeId: 'workspace-1', client, + hostCapabilities: [], connState: 'connected', setTerminals: vi.fn(), terminalsRef: { current: [] }, @@ -307,6 +309,7 @@ describe('optimistic placement of a created tab', () => { it('paints after the active split parent, matching headed host placement', async () => { const scope = createScope(clientReturning(terminalCreateResponse())) + scope.hostCapabilities = [SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY] scope.activeSessionTabId = 'existing-tab::left' await createLegacyTerminal(scope) @@ -319,6 +322,20 @@ describe('optimistic placement of a created tab', () => { ).toEqual(['existing-tab::left', 'existing-tab::right', 'terminal-tab-1', 'trailing-tab']) }) + it('keeps legacy leaf placement for an older host', async () => { + const scope = createScope(clientReturning(terminalCreateResponse())) + scope.activeSessionTabId = 'existing-tab::left' + await createLegacyTerminal(scope) + + expect( + tabIdsAfterCreate(scope, [ + { id: 'existing-tab::left', parentTabId: 'existing-tab' }, + { id: 'existing-tab::right', parentTabId: 'existing-tab' }, + { id: 'trailing-tab' } + ]) + ).toEqual(['existing-tab::left', 'terminal-tab-1', 'existing-tab::right', 'trailing-tab']) + }) + it('sends the same anchor it paints with', async () => { const scope = createScope(clientReturning(terminalCreateResponse())) await createLegacyTerminal(scope) diff --git a/mobile/src/session/use-mobile-session-terminal-create-actions.ts b/mobile/src/session/use-mobile-session-terminal-create-actions.ts index 11548876f60f..a3d61f9ca328 100644 --- a/mobile/src/session/use-mobile-session-terminal-create-actions.ts +++ b/mobile/src/session/use-mobile-session-terminal-create-actions.ts @@ -13,11 +13,13 @@ import type { MobileSessionAttachmentsModel } from './use-mobile-session-attachm import { isAgentSessionHandleProvider } from '../../../src/shared/agent-session-provider-handle' import { createMobileStructuredAgentSession } from './mobile-structured-agent-session-launch' import { placeCreatedSessionTab } from '../../../src/shared/session-tab-placement' +import { SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY } from '../../../src/shared/protocol-version' export function useMobileSessionTerminalCreateActions(scope: MobileSessionAttachmentsModel) { const { worktreeId, client, + hostCapabilities, connState, setTerminals, terminalsRef, @@ -127,7 +129,11 @@ export function useMobileSessionTerminalCreateActions(scope: MobileSessionAttach if (prev.some((tab) => tab.id === created.id)) { return prev } - return placeCreatedSessionTab(prev, { ...created, isActive: true }, afterTabId) + return placeCreatedSessionTab(prev, { ...created, isActive: true }, afterTabId, { + afterParentGroup: hostCapabilities?.includes( + SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY + ) + }) }) if (typeof created.terminal === 'string') { const createdHandle = created.terminal diff --git a/mobile/src/transport/mobile-runtime-client-capabilities.test.ts b/mobile/src/transport/mobile-runtime-client-capabilities.test.ts index bdd1330de1df..b4baa0780caf 100644 --- a/mobile/src/transport/mobile-runtime-client-capabilities.test.ts +++ b/mobile/src/transport/mobile-runtime-client-capabilities.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest' import { AGENT_SESSION_TURN_ITEM_CAPABILITY, CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY, + SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY, STRUCTURED_AGENT_SESSION_HOLD_RUNTIME_CAPABILITY, STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY } from '../../../src/shared/protocol-version' @@ -20,7 +21,8 @@ describe('mobile runtime client capabilities', () => { STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY, STRUCTURED_AGENT_SESSION_HOLD_RUNTIME_CAPABILITY, CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY, - AGENT_SESSION_TURN_ITEM_CAPABILITY + AGENT_SESSION_TURN_ITEM_CAPABILITY, + SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY ]) ) }) diff --git a/mobile/src/transport/mobile-runtime-client-capabilities.ts b/mobile/src/transport/mobile-runtime-client-capabilities.ts index 30b627a9ef38..226f0098460e 100644 --- a/mobile/src/transport/mobile-runtime-client-capabilities.ts +++ b/mobile/src/transport/mobile-runtime-client-capabilities.ts @@ -2,6 +2,7 @@ import { AGENT_SESSION_PENDING_SEND_RESULT_RUNTIME_CAPABILITY, AGENT_SESSION_TURN_ITEM_CAPABILITY, CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY, + SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY, STRUCTURED_AGENT_SESSION_HOLD_RUNTIME_CAPABILITY, STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY } from '../../../src/shared/protocol-version' @@ -12,6 +13,7 @@ export const MOBILE_RUNTIME_CLIENT_CAPABILITIES = remoteRuntimeClientCapabilitie AGENT_SESSION_PENDING_SEND_RESULT_RUNTIME_CAPABILITY, STRUCTURED_AGENT_SESSION_HOLD_RUNTIME_CAPABILITY, CLAUDE_STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY, + SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY, // Opts into the typed turn record; without it the host sends the legacy status carrier. AGENT_SESSION_TURN_ITEM_CAPABILITY ]) diff --git a/src/main/runtime/orca-runtime-create-mobile-session-terminal.ts b/src/main/runtime/orca-runtime-create-mobile-session-terminal.ts index 8dd5b510735a..8f6d71a9e896 100644 --- a/src/main/runtime/orca-runtime-create-mobile-session-terminal.ts +++ b/src/main/runtime/orca-runtime-create-mobile-session-terminal.ts @@ -29,6 +29,9 @@ export class OrcaRuntimeWithCreateMobileSessionTerminal extends OrcaRuntimeWithC clientNavigationId?: string navigation?: RuntimeNavigationTarget clientMutationId?: string + // Older mobile clients optimistically append; preserve that placement until they advertise + // split-group ordering support. + supportsSplitGroupPlacement?: boolean signal?: AbortSignal } = {} ): Promise { diff --git a/src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts b/src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts index 49c7bbf766cc..f1b8fa16af5c 100644 --- a/src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts +++ b/src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts @@ -32,6 +32,7 @@ export class OrcaRuntimeWithCreateRuntimeOwnedMobileSessionTerminal extends Orca launchAgent?: TuiAgent viewMode?: 'terminal' | 'chat' targetGroupId?: string + supportsSplitGroupPlacement?: boolean launchConfig?: SleepingAgentLaunchConfig signal?: AbortSignal } = {} @@ -113,7 +114,8 @@ export class OrcaRuntimeWithCreateRuntimeOwnedMobileSessionTerminal extends Orca isActive: activate ? false : candidate.isActive })), tab, - afterTabId + afterTabId, + { afterParentGroup: opts.supportsSplitGroupPlacement !== false } ) const next: RuntimeMobileSessionTabsSnapshot = { worktree: worktreeId, diff --git a/src/main/runtime/orca-runtime-run-create-mobile-session-terminal.ts b/src/main/runtime/orca-runtime-run-create-mobile-session-terminal.ts index 0caedfa1bba2..05621ac97928 100644 --- a/src/main/runtime/orca-runtime-run-create-mobile-session-terminal.ts +++ b/src/main/runtime/orca-runtime-run-create-mobile-session-terminal.ts @@ -32,6 +32,7 @@ export class OrcaRuntimeWithRunCreateMobileSessionTerminal extends OrcaRuntimeWi activate?: boolean clientNavigationId?: string clientMutationId?: string + supportsSplitGroupPlacement?: boolean signal?: AbortSignal } = {} ): Promise { @@ -41,14 +42,23 @@ export class OrcaRuntimeWithRunCreateMobileSessionTerminal extends OrcaRuntimeWi const worktreeId = workspace.id const cwd = this.resolveWorkspaceTerminalStartupCwd(workspace, opts.cwd) this.hydrateHeadlessMobileSessionTabsFromWorkspaceSession(worktreeId) + // Older mobile clients append their optimistic tab, so make the host append too until the + // client advertises the grouped placement contract. + const requestedAfterTabId = opts.afterTabId + const afterTabId = + opts.clientNavigationId && opts.supportsSplitGroupPlacement === false + ? undefined + : requestedAfterTabId let afterDesktopTabId: string | undefined - if (opts.afterTabId) { + if (requestedAfterTabId) { const snapshot = this.mobileSessionTabsByWorktree.get(worktreeId) - const anchor = snapshot?.tabs.find((tab) => tab.id === opts.afterTabId) + const anchor = snapshot?.tabs.find((tab) => tab.id === requestedAfterTabId) if (!anchor) { throw new Error('after_tab_not_found') } - afterDesktopTabId = anchor.type === 'terminal' ? anchor.parentTabId : anchor.id + if (afterTabId) { + afterDesktopTabId = anchor.type === 'terminal' ? anchor.parentTabId : anchor.id + } } const startupCommand = await this.resolveMobileSessionTerminalCommand(workspace, opts) this.assertStableReadyGraph(graphEpoch) @@ -60,7 +70,7 @@ export class OrcaRuntimeWithRunCreateMobileSessionTerminal extends OrcaRuntimeWi return await this.createRuntimeOwnedMobileSessionTerminal( worktreeId, opts.activate !== false, - opts.afterTabId, + afterTabId, { command: startupCommand.command, cwd, @@ -70,6 +80,7 @@ export class OrcaRuntimeWithRunCreateMobileSessionTerminal extends OrcaRuntimeWi launchAgent: startupCommand.launchAgent, viewMode: opts.viewMode, targetGroupId: opts.targetGroupId, + supportsSplitGroupPlacement: opts.supportsSplitGroupPlacement, launchConfig: startupCommand.launchConfig, signal: opts.signal } @@ -184,7 +195,7 @@ export class OrcaRuntimeWithRunCreateMobileSessionTerminal extends OrcaRuntimeWi return await this.createRuntimeOwnedMobileSessionTerminal( worktreeId, opts.activate !== false, - opts.afterTabId, + afterTabId, { command: startupCommand.command, cwd, @@ -195,6 +206,7 @@ export class OrcaRuntimeWithRunCreateMobileSessionTerminal extends OrcaRuntimeWi launchAgent: startupCommand.launchAgent, viewMode: opts.viewMode, targetGroupId: opts.targetGroupId, + supportsSplitGroupPlacement: opts.supportsSplitGroupPlacement, launchConfig: startupCommand.launchConfig, signal: opts.signal } diff --git a/src/main/runtime/orca-runtime-tests/runtime-availability.spec.ts b/src/main/runtime/orca-runtime-tests/runtime-availability.spec.ts index c1814c904eef..8a818e3ca6a7 100644 --- a/src/main/runtime/orca-runtime-tests/runtime-availability.spec.ts +++ b/src/main/runtime/orca-runtime-tests/runtime-availability.spec.ts @@ -42,6 +42,7 @@ describe('OrcaRuntimeService', () => { expect(status.capabilities).toContain('workspace-ports.v1') expect(status.capabilities).toContain('mobile.tasks.v1') expect(status.capabilities).toContain('terminal.quick-commands.v1') + expect(status.capabilities).toContain('session-tabs.split-group-placement.v1') expect(status.capabilities).toContain('worktree.create-idempotency.v1') expect(status.worktreeCreateIdempotency).toEqual({ dedupeTtlMs: 60_000 }) expect(status.capabilities).toContain('files.mutation-ownership.v1') diff --git a/src/main/runtime/rpc/methods/session-tabs.test.ts b/src/main/runtime/rpc/methods/session-tabs.test.ts index f295d2626daa..88c446ea8dd3 100644 --- a/src/main/runtime/rpc/methods/session-tabs.test.ts +++ b/src/main/runtime/rpc/methods/session-tabs.test.ts @@ -2,7 +2,10 @@ import { describe, expect, it, vi } from 'vitest' import { RpcDispatcher } from '../dispatcher' import type { RpcRequest } from '../core' import type { OrcaRuntimeService } from '../../orca-runtime' -import { SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY } from '../../../../shared/protocol-version' +import { + SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY, + SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY +} from '../../../../shared/protocol-version' import { SESSION_TAB_METHODS } from './session-tabs' import { visibleSnapshot } from './session-tabs-snapshot.test-fixture' @@ -497,6 +500,41 @@ describe('session tab RPC methods', () => { ) }) + it('passes split-group placement support to paired terminal creation', async () => { + const runtime = { + getRuntimeId: () => 'test-runtime', + createMobileSessionTerminal: vi.fn().mockResolvedValue({ + tab: { type: 'terminal', id: 'tab-1::leaf-1' }, + publicationEpoch: 'epoch-1', + snapshotVersion: 1 + }) + } as unknown as OrcaRuntimeService + const dispatcher = new RpcDispatcher({ runtime, methods: SESSION_TAB_METHODS }) + + await dispatcher.dispatchStreaming( + makeRequest('session.tabs.createTerminal', { + worktree: 'id:wt-1', + afterTabId: 'tab-1', + clientMutationId: 'create-1' + }), + () => {}, + { + clientKind: 'runtime', + pairedDeviceId: 'device-a', + clientCapabilities: [SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY] + } + ) + + expect(runtime.createMobileSessionTerminal).toHaveBeenCalledWith( + 'id:wt-1', + expect.objectContaining({ + afterTabId: 'tab-1', + clientNavigationId: 'device-a', + supportsSplitGroupPlacement: true + }) + ) + }) + it('preserves legacy agent creation for mixed-version clients', async () => { const runtime = { getRuntimeId: () => 'test-runtime', diff --git a/src/main/runtime/rpc/methods/session-tabs.ts b/src/main/runtime/rpc/methods/session-tabs.ts index d6441ee84cba..40e1525f1486 100644 --- a/src/main/runtime/rpc/methods/session-tabs.ts +++ b/src/main/runtime/rpc/methods/session-tabs.ts @@ -18,6 +18,7 @@ import { restoreStructuredTabsIfSupported } from './structured-session-tab-resto import { isStructuredNativeChatEnabled } from './structured-agent-session-policy' import { assertLegacyAiVaultResumeCommandAllowed } from '../../../ai-vault/structured-session-ownership' import { SessionTabsUnsubscribeAllParams } from '../../../../shared/rpc-contract/session-tabs-params' +import { SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY } from '../../../../shared/protocol-version' export const SESSION_TAB_METHODS = [ defineMethod({ @@ -46,7 +47,10 @@ export const SESSION_TAB_METHODS = [ defineMethod({ name: 'session.tabs.createTerminal', params: CreateTerminalTab, - handler: async (params, { runtime, signal, clientKind, pairedDeviceId }) => { + handler: async ( + params, + { runtime, signal, clientKind, pairedDeviceId, clientCapabilities } + ) => { if (params.command) { await assertLegacyAiVaultResumeCommandAllowed(params.command, () => runtime.ensureStructuredAgentSessionHost() @@ -74,6 +78,14 @@ export const SESSION_TAB_METHODS = [ clientKind }), clientMutationId: params.clientMutationId, + ...(pairedDeviceId + ? { + supportsSplitGroupPlacement: + clientCapabilities?.includes( + SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY + ) === true + } + : {}), // Why: a dead client connection must cancel the surface wait instead // of running down the timeout and rolling back a live tab (#7718). signal diff --git a/src/shared/protocol-version.ts b/src/shared/protocol-version.ts index aaec08cf46f7..a4e3e46aefcb 100644 --- a/src/shared/protocol-version.ts +++ b/src/shared/protocol-version.ts @@ -122,6 +122,11 @@ export const TERMINAL_CREATE_IDEMPOTENCY_RUNTIME_CAPABILITY = export const SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY = 'session-tabs.close-intent.v1' as const export const SESSION_TABS_AUTHORITATIVE_INVENTORY_RUNTIME_CAPABILITY = 'session-tabs.authoritative-inventory.v1' as const +// Why: older hosts splice a created terminal after the requested leaf, while newer hosts place it +// after the complete split parent. Clients gate optimistic placement on this capability so an old +// host cannot overwrite a grouped optimistic order with its legacy leaf-level snapshot. +export const SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY = + 'session-tabs.split-group-placement.v1' as const // Why: a client advertising this retains every terminal retirement proof it receives until the // surface is published live again, so a session-tabs stream sends each proof once instead of // repeating the host's whole bounded list on every title tick. @@ -281,6 +286,7 @@ export const RUNTIME_CAPABILITIES = [ TERMINAL_CREATE_IDEMPOTENCY_RUNTIME_CAPABILITY, SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY, SESSION_TABS_AUTHORITATIVE_INVENTORY_RUNTIME_CAPABILITY, + SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY, AGENT_SESSION_BOUNDARY_RUNTIME_CAPABILITY, REMOTE_SERVER_UPDATE_CAPABILITY, AGENT_SESSION_HOST_AUTHORITY_RUNTIME_CAPABILITY, diff --git a/src/shared/session-tab-placement.test.ts b/src/shared/session-tab-placement.test.ts index 8ce0cd8c0f8d..2658b3c3cc4b 100644 --- a/src/shared/session-tab-placement.test.ts +++ b/src/shared/session-tab-placement.test.ts @@ -19,11 +19,41 @@ describe('placeCreatedSessionTab', () => { { id: 'trailing' } ], { id: 'new' }, - 'split::left' + 'split::left', + { afterParentGroup: true } ).map((tab) => tab.id) ).toEqual(['split::left', 'split::right', 'new', 'trailing']) }) + it('keeps legacy leaf placement when split grouping is not negotiated', () => { + expect( + placeCreatedSessionTab( + [ + { id: 'split::left', parentTabId: 'split' }, + { id: 'split::right', parentTabId: 'split' }, + { id: 'trailing' } + ], + { id: 'new' }, + 'split::left' + ).map((tab) => tab.id) + ).toEqual(['split::left', 'new', 'split::right', 'trailing']) + }) + + it('finds split siblings after an interleaved tab', () => { + expect( + placeCreatedSessionTab( + [ + { id: 'split::left', parentTabId: 'split' }, + { id: 'trailing' }, + { id: 'split::right', parentTabId: 'split' } + ], + { id: 'new' }, + 'split::left', + { afterParentGroup: true } + ).map((tab) => tab.id) + ).toEqual(['split::left', 'trailing', 'split::right', 'new']) + }) + it('appends when the anchor is the last tab', () => { expect( placeCreatedSessionTab([{ id: 'a' }, { id: 'b' }], created, 'b').map((t) => t.id) diff --git a/src/shared/session-tab-placement.ts b/src/shared/session-tab-placement.ts index dd810424c4e0..1b4729a6156b 100644 --- a/src/shared/session-tab-placement.ts +++ b/src/shared/session-tab-placement.ts @@ -1,8 +1,13 @@ -/** Places a created tab after the anchor's top-level terminal group, or appends when unanchored. */ +export type SessionTabPlacementOptions = { + afterParentGroup?: boolean +} + +/** Places a created tab after the anchor, or after its parent group when enabled. */ export function placeCreatedSessionTab( tabs: readonly T[], created: T, - afterTabId: string | null | undefined + afterTabId: string | null | undefined, + options: SessionTabPlacementOptions = {} ): T[] { const next = tabs.filter((tab) => tab.id !== created.id) const anchor = afterTabId ? next.findIndex((tab) => tab.id === afterTabId) : -1 @@ -12,12 +17,11 @@ export function placeCreatedSessionTab Date: Fri, 11 Sep 2026 20:00:32 -0700 Subject: [PATCH 4/6] fix(e2e): run worktree first-paint probe on a mapped window --- .github/workflows/e2e.yml | 5 +++++ config/scripts/pr-e2e-gate-contract.test.mjs | 7 +++++++ tests/e2e/worktree-switch-first-paint.spec.ts | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 942f0f34a56e..a07bf0991ecb 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -173,6 +173,11 @@ jobs: - name: Run E2E tests (${{ matrix.shard_name }}) run: xvfb-run --auto-servernum bash .github/scripts/e2e-with-window-manager.sh env SKIP_BUILD=1 ORCA_E2E_FORWARD_APP_LOGS=1 ORCA_E2E_WEB_CLIENT=1 ORCA_RELAY_PATH="$GITHUB_WORKSPACE/out/relay" pnpm run test:e2e --shard=${{ matrix.shard }} + # The frame benchmark needs a mapped window, which the headless shards exclude. + - name: Run worktree first-paint benchmark + if: matrix.shard == '1/14' + run: xvfb-run --auto-servernum bash .github/scripts/e2e-with-window-manager.sh env SKIP_BUILD=1 ORCA_E2E_FORWARD_APP_LOGS=1 pnpm exec playwright test tests/e2e/worktree-switch-first-paint.spec.ts --config tests/playwright.config.ts --project=electron-headful --workers=1 + # Why: Playwright retains traces/screenshots only on failure. Uploading # them as an artifact makes post-mortem debugging on CI possible without # re-running locally. diff --git a/config/scripts/pr-e2e-gate-contract.test.mjs b/config/scripts/pr-e2e-gate-contract.test.mjs index 4f012b105b4c..22677bb152fe 100644 --- a/config/scripts/pr-e2e-gate-contract.test.mjs +++ b/config/scripts/pr-e2e-gate-contract.test.mjs @@ -179,6 +179,13 @@ describe('PR E2E gate contract', () => { 'pnpm run test:e2e "${TEST_FILES[@]}" --workers=1 "${E2E_PROJECT_ARGS[@]}"' ) expect(playwrightConfig).toContain('retries: 0') + const steps = e2eWorkflow.jobs.e2e.steps.filter((step) => + step.run?.includes('tests/e2e/worktree-switch-first-paint.spec.ts') + ) + expect(steps).toHaveLength(1) + expect(steps[0].if).toBe("matrix.shard == '1/14'") + expect(steps[0].run).toContain('xvfb-run --auto-servernum') + expect(steps[0].run).toContain('--project=electron-headful --workers=1') }) it('keeps startup-exec live parity in the isolated SSH lane', () => { diff --git a/tests/e2e/worktree-switch-first-paint.spec.ts b/tests/e2e/worktree-switch-first-paint.spec.ts index f062b6e246ac..307e179faf68 100644 --- a/tests/e2e/worktree-switch-first-paint.spec.ts +++ b/tests/e2e/worktree-switch-first-paint.spec.ts @@ -372,7 +372,12 @@ function median(values: readonly number[]): number { return sorted.length % 2 === 0 ? (sorted[middle - 1] + sorted[middle]) / 2 : sorted[middle] } -test.describe('Worktree switch first paint', () => { +// Linux needs a mapped window for animation frames after reload; run on an isolated display. +test.describe('Worktree switch first paint @headful', () => { + test.skip( + process.env.ORCA_BACKGROUND_LAUNCH === '1', + 'First-paint measurement requires a mapped window' + ) test('repaints an unmounted worktree within the switch budget', async ({ orcaPage, testRepoPath From 36b43d704ad7a7efc9ea4bc6b766b309ed52e163 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Wed, 16 Sep 2026 21:44:44 -0700 Subject: [PATCH 5/6] test(mobile): type tab placement updater --- ...-mobile-session-terminal-create-actions.test.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts b/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts index 27d11f844654..f4e5b3eea137 100644 --- a/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts +++ b/mobile/src/session/use-mobile-session-terminal-create-actions.test.ts @@ -6,6 +6,9 @@ import { markRpcDeliveryUnknown } from '../transport/rpc-delivery-ambiguity' import { useMobileSessionTerminalCreateActions } from './use-mobile-session-terminal-create-actions' import { SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY } from '../../../src/shared/protocol-version' +type PlacementTab = { id: string; parentTabId?: string } +type PlacementUpdater = (previous: PlacementTab[]) => PlacementTab[] + vi.mock('../platform/haptics', () => ({ triggerSuccess: vi.fn(), triggerError: vi.fn() @@ -41,7 +44,7 @@ function createScope(client: RpcClient) { connState: 'connected', setTerminals: vi.fn(), terminalsRef: { current: [] }, - setSessionTabs: vi.fn(), + setSessionTabs: vi.fn<(updater: PlacementUpdater) => void>(), defaultTerminalHandlesToLiveInput: vi.fn(), setActiveHandle: vi.fn(), activeSessionTabId: 'existing-tab', @@ -330,11 +333,12 @@ describe('optimistic placement of a created tab', () => { function tabIdsAfterCreate( scope: ReturnType, - prior: { id: string }[] + prior: PlacementTab[] ): string[] { - const updater = (scope.setSessionTabs as ReturnType).mock.calls.at(-1)?.[0] as ( - prev: { id: string }[] - ) => { id: string }[] + const updater = scope.setSessionTabs.mock.calls.at(-1)?.[0] + if (!updater) { + throw new Error('Expected a session tab updater') + } return updater(prior).map((tab) => tab.id) } From 2969f6c82f92774170cfddecd49d0aed91e05382 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Wed, 16 Sep 2026 22:20:23 -0700 Subject: [PATCH 6/6] test(mobile): model current host in create recordings --- ...sion.create-terminal-session.tabs.createterminal-1.json | 4 ++-- .../matrix-session.create-terminal-terminal.send-1.json | 4 ++-- ...-create-terminal-ignores-a-second-create-in-flight.json | 4 ++-- ...on-create-terminal-launches-an-agent-quick-command.json | 4 ++-- .../goldens/session-create-terminal-refused.json | 4 ++-- .../goldens/session-create-terminal-replaces-active.json | 4 ++-- .../session-create-terminal-runs-a-quick-command.json | 4 ++-- .../goldens/session-create-terminal-with-prompt.json | 4 ++-- .../session-create-terminal-without-active-tab.json | 4 ++-- .../goldens/session-create-terminal-without-handle.json | 4 ++-- .../adapters/session-terminal-create-mount-adapters.ts | 7 +++++++ .../rpc-recording/mutants/operation-mutations.ts | 4 ++-- 12 files changed, 29 insertions(+), 22 deletions(-) diff --git a/mobile/rpc-foundation/goldens/matrix-session.create-terminal-session.tabs.createterminal-1.json b/mobile/rpc-foundation/goldens/matrix-session.create-terminal-session.tabs.createterminal-1.json index 0e6cbcec813d..8d3c8f5191ca 100644 --- a/mobile/rpc-foundation/goldens/matrix-session.create-terminal-session.tabs.createterminal-1.json +++ b/mobile/rpc-foundation/goldens/matrix-session.create-terminal-session.tabs.createterminal-1.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "ae1572c1670073d0ac3d2d3abd0e7bee9910cbe4a0b09ecd941e887eeb1db165", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/matrix-session.create-terminal-terminal.send-1.json b/mobile/rpc-foundation/goldens/matrix-session.create-terminal-terminal.send-1.json index 74939755b87b..2316ed8267d0 100644 --- a/mobile/rpc-foundation/goldens/matrix-session.create-terminal-terminal.send-1.json +++ b/mobile/rpc-foundation/goldens/matrix-session.create-terminal-terminal.send-1.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "62930616f1017ffd4b74546c80b17f3aa3bcee52a6ad62ec144d95872fd31321", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/session-create-terminal-ignores-a-second-create-in-flight.json b/mobile/rpc-foundation/goldens/session-create-terminal-ignores-a-second-create-in-flight.json index b7a421c06b58..645b421fe2f7 100644 --- a/mobile/rpc-foundation/goldens/session-create-terminal-ignores-a-second-create-in-flight.json +++ b/mobile/rpc-foundation/goldens/session-create-terminal-ignores-a-second-create-in-flight.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "df99b9c0ebcffb3d8f173c87783862edb0a66befcc3cd73f1096871f45963913", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/session-create-terminal-launches-an-agent-quick-command.json b/mobile/rpc-foundation/goldens/session-create-terminal-launches-an-agent-quick-command.json index 3a29ade314b1..7c14a5330743 100644 --- a/mobile/rpc-foundation/goldens/session-create-terminal-launches-an-agent-quick-command.json +++ b/mobile/rpc-foundation/goldens/session-create-terminal-launches-an-agent-quick-command.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "fb9828d5e13917ce394061b2d702890e5198df04ce803363b2ce9f939921d00e", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/session-create-terminal-refused.json b/mobile/rpc-foundation/goldens/session-create-terminal-refused.json index 52e5ed1d65e9..65f0d42db222 100644 --- a/mobile/rpc-foundation/goldens/session-create-terminal-refused.json +++ b/mobile/rpc-foundation/goldens/session-create-terminal-refused.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "e9c32bdf3357ca5d69ac07cb7bbc63fe279c1a23c44e5c79fa0b1db4fd1c55dd", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/session-create-terminal-replaces-active.json b/mobile/rpc-foundation/goldens/session-create-terminal-replaces-active.json index 9859c64ec2aa..c6894dc76591 100644 --- a/mobile/rpc-foundation/goldens/session-create-terminal-replaces-active.json +++ b/mobile/rpc-foundation/goldens/session-create-terminal-replaces-active.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "726e19307f1e82f0c8ae9a555ec9c27c8eea7f8f40fa700dc0b71c54ecc9ca11", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/session-create-terminal-runs-a-quick-command.json b/mobile/rpc-foundation/goldens/session-create-terminal-runs-a-quick-command.json index ac5fd3048eb5..a2533f1d473c 100644 --- a/mobile/rpc-foundation/goldens/session-create-terminal-runs-a-quick-command.json +++ b/mobile/rpc-foundation/goldens/session-create-terminal-runs-a-quick-command.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "4dfbe31daae64a03fc588f2095235fdd9b37f26ecccefe596c35c8ef8f623651", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/session-create-terminal-with-prompt.json b/mobile/rpc-foundation/goldens/session-create-terminal-with-prompt.json index 36267793f930..45fc104a13cc 100644 --- a/mobile/rpc-foundation/goldens/session-create-terminal-with-prompt.json +++ b/mobile/rpc-foundation/goldens/session-create-terminal-with-prompt.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "fd654a7e34ae8004543a34a7a301d51858989fdc2bffb02ddf6edb814071b22d", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/session-create-terminal-without-active-tab.json b/mobile/rpc-foundation/goldens/session-create-terminal-without-active-tab.json index 7d9b32610b23..9dc529f48ff6 100644 --- a/mobile/rpc-foundation/goldens/session-create-terminal-without-active-tab.json +++ b/mobile/rpc-foundation/goldens/session-create-terminal-without-active-tab.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "da78ad25ea15e1c714f0147d34207529362743a56a519153f36b09345dee0ebc", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/rpc-foundation/goldens/session-create-terminal-without-handle.json b/mobile/rpc-foundation/goldens/session-create-terminal-without-handle.json index 3ec3d2faf258..02c68764064e 100644 --- a/mobile/rpc-foundation/goldens/session-create-terminal-without-handle.json +++ b/mobile/rpc-foundation/goldens/session-create-terminal-without-handle.json @@ -4,9 +4,9 @@ "namedDeltas": [], "runnerVersion": 1, "baseline": "4b876758d3158a8eb6b798055d8db7c58d1cd4a9", - "lockfileSha256": "788c1234b38a61fc882fca292341fce6690deee9cc6695673b0575cf2c4cf571", + "lockfileSha256": "4568633356187895ccda8e2ff83245c37d5621832c69e268733733b6947971e3", "recorderSha256": "d4fa125899cd863c03dbf96657d46b8c7d6c0ccf522b342bc4f164ed1e3becfe", - "adapterSha256": "f0cc9511c5e878b6dd78e2911b5c14351b41b7bb944e5e03c2fa1ddbcdc7ea10", + "adapterSha256": "fa7d9fd6428e89282f08e04fefba4289000eb3aed1462489a2f11efed374382c", "scenarioSha256": "f1952a0e2c9108dadf2f5b85ac1f43ec9db09db0ce81a575bb4dd3a8d18d9c83", "platform": "darwin", "scenarioVersion": 1, diff --git a/mobile/src/test-support/rpc-recording/adapters/session-terminal-create-mount-adapters.ts b/mobile/src/test-support/rpc-recording/adapters/session-terminal-create-mount-adapters.ts index 370687c4305b..865357d01caf 100644 --- a/mobile/src/test-support/rpc-recording/adapters/session-terminal-create-mount-adapters.ts +++ b/mobile/src/test-support/rpc-recording/adapters/session-terminal-create-mount-adapters.ts @@ -8,6 +8,7 @@ import type { Terminal } from '../../../session/mobile-session-route-types' import type { TuiAgent } from '../../../../../src/shared/tui-agent' +import { SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY } from '../../../../../src/shared/protocol-version' const PREVIOUS_HANDLE = 'terminal-0' @@ -71,6 +72,7 @@ export function sessionTerminalCreateMountAdapters( let activeHandle: string | null = PREVIOUS_HANDLE let worktreeId = '' let activeSessionTabId: string | null = null + let hostCapabilities: string[] = [SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY] let creating = false let createError = '' const terminalsRef = { current: terminals } @@ -91,6 +93,7 @@ export function sessionTerminalCreateMountAdapters( mountFixture[0]>({ worktreeId, client, + hostCapabilities, connState: 'connected', setTerminals: (update) => { terminals = typeof update === 'function' ? update(terminals) : update @@ -148,6 +151,10 @@ export function sessionTerminalCreateMountAdapters( activeSessionTabId = typeof args.activeSessionTabId === 'string' ? args.activeSessionTabId : null activeSessionTabIdRef.current = activeSessionTabId + hostCapabilities = + args.supportsSplitGroupPlacement === false + ? [] + : [SESSION_TABS_SPLIT_GROUP_PLACEMENT_RUNTIME_CAPABILITY] deviceTokenRef.current = typeof args.deviceToken === 'string' ? args.deviceToken : null return hook.mount() } diff --git a/mobile/src/test-support/rpc-recording/mutants/operation-mutations.ts b/mobile/src/test-support/rpc-recording/mutants/operation-mutations.ts index 7dee845037a1..569f8f763fc6 100644 --- a/mobile/src/test-support/rpc-recording/mutants/operation-mutations.ts +++ b/mobile/src/test-support/rpc-recording/mutants/operation-mutations.ts @@ -221,8 +221,8 @@ export const OPERATION_MUTATIONS = { // there. Invisible to any scenario whose session already has an active tab. 'create-after-tab-id-null': { file: 'use-mobile-session-terminal-create-actions.ts', - before: ' afterTabId: activeSessionTabId ?? undefined,', - after: ' afterTabId: activeSessionTabId,' + before: ' const afterTabId = activeSessionTabId ?? undefined', + after: ' const afterTabId = activeSessionTabId' }, // Swaps the two quick-command members, so a saved shell command arrives as an agent prompt and an // agent prompt arrives as a startup command. Invisible to any scenario that fills neither.