mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* fix(browser): switch client-hosted profiles with staged guest replacement Squashed from #30351 by @oliver-mee onto the current main. Fixes #30350 * fix(browser): fence staged profile guests, release switch grants, carry host profile metadata - A fence during automation retirement now revokes and stops the staged guest. - A failed or late-settling switch releases its execution-host grant so the page can be recreated. - Staging cleanup failures before handover stay visible to executor close. - createPage/restorePage carry host-owned profile metadata to profile-switch-v1 desktops, so recovery and restore can rebuild a switched page. * fix(browser): roll back a switch whose replacement died, and report a lost old guest * fix(browser): resolve client-hosted pages before the server-local target path when switching profiles * fix(browser): a staged profile-switch guest owns downloads it starts while loading * fix(browser): keep the original placement until a timed-out switch settles * fix(browser): rebind the original guest before releasing a rolled-back staged guest * test(browser): type the harness guest release mock * fix(browser): release the replaced generation's download transfers when a switch commits * fix(browser): admit file transfers from a staged profile-switch guest while its switch is pending * fix(browser): release only the replaced generation's download transfers after a switch * refactor(shared): import BrowserNetworkExecutionHost from its own module, no re-export * fix(browser): adopt a profile switch the client finished after the caller timed out --------- Co-authored-by: Oliver Mee <102673257+oliver-mee@users.noreply.github.com>
114 lines
4.3 KiB
TypeScript
114 lines
4.3 KiB
TypeScript
import type { BrowserNetworkExecutionHost } from '../../shared/browser-network-execution-host'
|
|
import { BROWSER_CLIENT_AUTOMATION_HOST_CAPABILITY } from '../../shared/browser-client-automation-protocol'
|
|
import { browserNetworkExecutionHostKey } from '../browser/browser-network-execution-route'
|
|
import type { BrowserHostLeaseRegistry } from './browser-host/browser-host-lease-registry'
|
|
import type { RuntimeBrowserClientPlacement } from '../../shared/runtime-browser-placement'
|
|
|
|
type RuntimeBrowserClientPageAuthority = Pick<
|
|
BrowserHostLeaseRegistry,
|
|
'authorityRuntimeId' | 'authorityEpoch' | 'createClientPage' | 'issueClientPageCommand'
|
|
>
|
|
|
|
type RuntimeBrowserClientPageCreation = {
|
|
browserPageId: string
|
|
browserHostClientId: string
|
|
pairedDeviceId: string
|
|
browserProfileId: string
|
|
executionHost: BrowserNetworkExecutionHost
|
|
workspaceId?: string
|
|
}
|
|
|
|
type RuntimeBrowserClientPageNavigation = {
|
|
browserPageId: string
|
|
placement: RuntimeBrowserClientPlacement
|
|
url: string
|
|
}
|
|
|
|
type RuntimeBrowserClientPageRetirement = {
|
|
browserPageId: string
|
|
placement: RuntimeBrowserClientPlacement
|
|
}
|
|
|
|
export async function createRuntimeBrowserClientPage(
|
|
authority: RuntimeBrowserClientPageAuthority,
|
|
input: RuntimeBrowserClientPageCreation
|
|
): Promise<{ browserPageId: string; placement: RuntimeBrowserClientPlacement }> {
|
|
const placement = await authority.createClientPage({
|
|
browserPageId: input.browserPageId,
|
|
browserHostClientId: input.browserHostClientId,
|
|
pairedDeviceId: input.pairedDeviceId,
|
|
browserProfileId: input.browserProfileId,
|
|
executionHostKey: browserNetworkExecutionHostKey(input.executionHost),
|
|
requiredCapabilities: [BROWSER_CLIENT_AUTOMATION_HOST_CAPABILITY],
|
|
...(input.workspaceId ? { workspaceId: input.workspaceId } : {})
|
|
})
|
|
return { browserPageId: input.browserPageId, placement }
|
|
}
|
|
|
|
export async function navigateRuntimeBrowserClientPage(
|
|
authority: RuntimeBrowserClientPageAuthority,
|
|
input: RuntimeBrowserClientPageNavigation
|
|
): Promise<void> {
|
|
const issued = authority.issueClientPageCommand(
|
|
{
|
|
authorityRuntimeId: authority.authorityRuntimeId,
|
|
authorityEpoch: authority.authorityEpoch,
|
|
browserPageId: input.browserPageId,
|
|
browserHostClientId: input.placement.browserHostClientId,
|
|
browserHostGeneration: input.placement.browserHostGeneration,
|
|
pageHostGeneration: input.placement.pageHostGeneration
|
|
},
|
|
{ type: 'navigate', url: input.url }
|
|
)
|
|
const result = await issued.result
|
|
if (result.status === 'failed') {
|
|
throw new Error(result.errorCode)
|
|
}
|
|
}
|
|
|
|
export async function closeRuntimeBrowserClientPage(
|
|
authority: RuntimeBrowserClientPageAuthority &
|
|
Pick<
|
|
BrowserHostLeaseRegistry,
|
|
'beginPageRetirement' | 'completePageRetirement' | 'requireClientPage'
|
|
>,
|
|
input: RuntimeBrowserClientPageRetirement
|
|
): Promise<void> {
|
|
const issued = authority.issueClientPageCommand(
|
|
{
|
|
authorityRuntimeId: authority.authorityRuntimeId,
|
|
authorityEpoch: authority.authorityEpoch,
|
|
browserPageId: input.browserPageId,
|
|
browserHostClientId: input.placement.browserHostClientId,
|
|
browserHostGeneration: input.placement.browserHostGeneration,
|
|
pageHostGeneration: input.placement.pageHostGeneration
|
|
},
|
|
{
|
|
type: 'closePage',
|
|
targetAuthority: {
|
|
authorityRuntimeId: authority.authorityRuntimeId,
|
|
authorityEpoch: authority.authorityEpoch,
|
|
browserHostClientId: input.placement.browserHostClientId,
|
|
browserHostGeneration: input.placement.browserHostGeneration,
|
|
pageHostGeneration: input.placement.pageHostGeneration
|
|
}
|
|
}
|
|
)
|
|
const result = await issued.result
|
|
if (result.status === 'failed') {
|
|
throw new Error(result.errorCode)
|
|
}
|
|
const canonicalPlacement = authority.requireClientPage({
|
|
authorityRuntimeId: authority.authorityRuntimeId,
|
|
authorityEpoch: authority.authorityEpoch,
|
|
browserPageId: input.browserPageId,
|
|
browserHostClientId: input.placement.browserHostClientId,
|
|
browserHostGeneration: input.placement.browserHostGeneration,
|
|
pageHostGeneration: input.placement.pageHostGeneration
|
|
})
|
|
const retirement = authority.beginPageRetirement(input.browserPageId, canonicalPlacement)
|
|
if (!authority.completePageRetirement(retirement)) {
|
|
throw new Error('browser_page_placement_stale')
|
|
}
|
|
}
|