Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,28 @@ import type {
/**
* Storage identity of the connection a page's partition is derived from.
*
* The legacy half names the partition an older build already populated, so a client
* upgrade adopts that jar instead of deriving an empty one.
* The superseded identities name partitions an older build already populated, so a client
* upgrade adopts that jar instead of deriving an empty one: `pairingAuthorityConnectionIdentity`
* is the pairing-revision identity (equal to the current one for hosts that never re-pair in
* place), and `legacyAuthorityConnectionIdentity` the older per-process one.
*/
export type BrowserClientPageAuthorityIdentity = {
authorityConnectionIdentity: string
pairingAuthorityConnectionIdentity: string
legacyAuthorityConnectionIdentity: string
}

// Why pick: transition inputs carry the whole host start, and only the identity belongs here.
export function pageAuthorityIdentity(
input: BrowserClientPageAuthorityIdentity
): BrowserClientPageAuthorityIdentity {
return {
authorityConnectionIdentity: input.authorityConnectionIdentity,
pairingAuthorityConnectionIdentity: input.pairingAuthorityConnectionIdentity,
legacyAuthorityConnectionIdentity: input.legacyAuthorityConnectionIdentity
}
}

export type BrowserClientPageCommandExecutorDependencies = BrowserClientPageAuthorityIdentity & {
orcaProfileId: string
/** Environment record that owns this host's partitions for storage lifecycle. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('BrowserClientPageCommandExecutor authority fencing', () => {

executor.completeAuthorityTransition({
authorityConnectionIdentity: 'authority-record-b',
pairingAuthorityConnectionIdentity: 'pairing-authority-record-b',
legacyAuthorityConnectionIdentity: 'legacy-authority-record-b'
})
await expect(
Expand Down Expand Up @@ -146,6 +147,7 @@ describe('BrowserClientPageCommandExecutor authority fencing', () => {
expect(order).toEqual(['release-route'])
executor.completeAuthorityTransition({
authorityConnectionIdentity: 'authority-record-b',
pairingAuthorityConnectionIdentity: 'pairing-authority-record-b',
legacyAuthorityConnectionIdentity: 'legacy-authority-record-b'
})
await executor.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function createHarness(options: { maxPages?: number } = {}) {
const dependencies = {
orcaProfileId: 'orca-profile-a',
authorityConnectionIdentity: 'authority-record-a',
pairingAuthorityConnectionIdentity: 'pairing-authority-record-a',
legacyAuthorityConnectionIdentity: 'legacy-authority-record-a',
storageScope: 'a'.repeat(64),
maxPages: options.maxPages,
Expand Down
7 changes: 7 additions & 0 deletions src/main/browser/browser-client-page-command-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ describe('BrowserClientPageCommandExecutor', () => {
authorityConnectionIdentity: 'authority-record-a',
executionHostIdentity: 'execution-host-record-a'
},
compatibleIdentity: {
orcaProfileId: 'orca-profile-a',
browserProfileId: 'profile-a',
authorityConnectionIdentity: 'pairing-authority-record-a',
executionHostIdentity: 'execution-host-record-a'
},
legacyIdentity: {
orcaProfileId: 'orca-profile-a',
browserProfileId: 'profile-a',
Expand Down Expand Up @@ -526,6 +532,7 @@ describe('BrowserClientPageCommandExecutor', () => {
expect(() =>
executor.completeAuthorityTransition({
authorityConnectionIdentity: 'authority-record-b',
pairingAuthorityConnectionIdentity: 'pairing-authority-record-b',
legacyAuthorityConnectionIdentity: 'legacy-authority-record-b'
})
).toThrow('browser_client_page_authority_transition_unavailable')
Expand Down
22 changes: 9 additions & 13 deletions src/main/browser/browser-client-page-command-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ import {
navigateBrowserClientPageCommand
} from './browser-client-page-command-execution'
import { publishBrowserClientRetainedPage } from './browser-client-page-availability'
import type {
BrowserClientPageAuthorityIdentity,
BrowserClientPageCommandExecutorDependencies
import {
pageAuthorityIdentity,
type BrowserClientPageAuthorityIdentity,
type BrowserClientPageCommandExecutorDependencies
} from './browser-client-page-command-executor-dependencies'

export class BrowserClientPageCommandExecutor {
Expand All @@ -51,14 +52,12 @@ export class BrowserClientPageCommandExecutor {
private readonly profileSwitches = new BrowserClientProfileSwitches()
private readonly navigationFence = new BrowserClientPageNavigationFence()
private closePromise: Promise<void> | null = null
private authorityConnectionIdentity: string
private legacyAuthorityConnectionIdentity: string
private authority: BrowserClientPageAuthorityIdentity
private authorityTransitioning = false
private closed = false

constructor(private readonly dependencies: BrowserClientPageCommandExecutorDependencies) {
this.authorityConnectionIdentity = dependencies.authorityConnectionIdentity
this.legacyAuthorityConnectionIdentity = dependencies.legacyAuthorityConnectionIdentity
this.authority = pageAuthorityIdentity(dependencies)
this.maxPages = dependencies.maxPages ?? BROWSER_CLIENT_HOST_PAGE_INVENTORY_MAX_PAGES
if (
!Number.isInteger(this.maxPages) ||
Expand Down Expand Up @@ -103,8 +102,7 @@ export class BrowserClientPageCommandExecutor {
pages: this.pages,
dependencies: {
...this.dependencies,
authorityConnectionIdentity: this.authorityConnectionIdentity,
legacyAuthorityConnectionIdentity: this.legacyAuthorityConnectionIdentity
...this.authority
},
assertAvailable: () =>
this.navigationFence.assertAvailable(this.closed || this.authorityTransitioning),
Expand Down Expand Up @@ -212,8 +210,7 @@ export class BrowserClientPageCommandExecutor {
if (this.closed || !this.authorityTransitioning || !input.authorityConnectionIdentity) {
throw new Error('browser_client_page_authority_transition_unavailable')
}
this.authorityConnectionIdentity = input.authorityConnectionIdentity
this.legacyAuthorityConnectionIdentity = input.legacyAuthorityConnectionIdentity
this.authority = pageAuthorityIdentity(input)
this.authorityTransitioning = false
}

Expand Down Expand Up @@ -260,8 +257,7 @@ export class BrowserClientPageCommandExecutor {
await createReservedBrowserClientPage(
{
...this.dependencies,
authorityConnectionIdentity: this.authorityConnectionIdentity,
legacyAuthorityConnectionIdentity: this.legacyAuthorityConnectionIdentity,
...this.authority,
retireSupersededExecutionHostPages: (route) =>
retireSupersededExecutionHostPages(this.pages.values(), route, (id, generation) =>
this.retirePage(id, generation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('BrowserClientPageCommandExecutor integration', () => {
const executor = new BrowserClientPageCommandExecutor({
orcaProfileId: 'orca-profile-a',
authorityConnectionIdentity: 'authority-record-a',
pairingAuthorityConnectionIdentity: 'pairing-authority-record-a',
legacyAuthorityConnectionIdentity: 'legacy-authority-record-a',
storageScope: 'a'.repeat(64),
retainNetworkRoute: vi.fn(async () => ({
Expand Down
11 changes: 8 additions & 3 deletions src/main/browser/browser-client-page-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
assertCurrentBrowserClientPageRenderer,
browserClientPageIdentity
} from './browser-client-page-command-admission'
import type { BrowserClientPageAuthorityIdentity } from './browser-client-page-command-executor-dependencies'
import { BrowserClientPageCommandError } from './browser-client-page-command-failure'
import type { BrowserClientPageGuestBinding } from './browser-client-page-guest-binding'
import { createBrowserClientPageInventory } from './browser-client-page-inventory'
Expand All @@ -23,10 +24,8 @@ import type {
import type { BrowserRouteSessionRegistry } from './browser-route-session-registry'
import type { BrowserRouteSessionHandle } from './browser-route-session-state'

type BrowserClientPageCreationDependencies = {
type BrowserClientPageCreationDependencies = BrowserClientPageAuthorityIdentity & {
orcaProfileId: string
authorityConnectionIdentity: string
legacyAuthorityConnectionIdentity: string
storageScope: string
retainNetworkRoute(executionHostKey: string, signal: AbortSignal): Promise<RetainedNetworkRoute>
retireSupersededExecutionHostPages(route: RetainedNetworkRoute): Promise<void>
Expand Down Expand Up @@ -74,6 +73,12 @@ export async function createReservedBrowserClientPage(
authorityConnectionIdentity: dependencies.authorityConnectionIdentity,
executionHostIdentity: route.executionHostIdentity
},
compatibleIdentity: {
orcaProfileId: dependencies.orcaProfileId,
browserProfileId: event.command.browserProfileId,
authorityConnectionIdentity: dependencies.pairingAuthorityConnectionIdentity,
executionHostIdentity: route.executionHostIdentity
},
legacyIdentity: {
orcaProfileId: dependencies.orcaProfileId,
browserProfileId: event.command.browserProfileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function createHarness() {
const dependencies = {
orcaProfileId: 'orca-profile-a',
authorityConnectionIdentity: 'authority-record-a',
pairingAuthorityConnectionIdentity: 'pairing-authority-record-a',
legacyAuthorityConnectionIdentity: 'legacy-authority-record-a',
storageScope: 'a'.repeat(64),
retainNetworkRoute: vi.fn(async (executionHostKey: string) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function createHarness() {
const dependencies = {
orcaProfileId: 'orca-profile-a',
authorityConnectionIdentity: 'authority-record-a',
pairingAuthorityConnectionIdentity: 'pairing-authority-record-a',
legacyAuthorityConnectionIdentity: 'legacy-authority-record-a',
storageScope: 'a'.repeat(64),
retainNetworkRoute: vi.fn(async () => route),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function harness() {
const executor = new BrowserClientPageCommandExecutor({
orcaProfileId: 'profile-a',
authorityConnectionIdentity: 'authority-a',
pairingAuthorityConnectionIdentity: 'pairing-authority-a',
legacyAuthorityConnectionIdentity: 'legacy-authority-a',
storageScope: 'a'.repeat(64),
retainNetworkRoute: vi.fn(async () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ async function importPartition(): Promise<string> {
// Why: mirrors startPairedRuntimeBrowserClientHost — settings-level operations target the
// server's own machine, so the identity comes from the same helper the host uses.
executionHostIdentity: browserAuthorityExecutionHostStorageIdentity(storageScope),
pairingAuthorityConnectionIdentity: 'paired-runtime:pairing-authority-a',
legacyAuthorityConnectionIdentity: 'paired-runtime:legacy-authority-a',
legacyExecutionHostIdentity:
legacyBrowserNativeExecutionHostStorageIdentity(authorityRuntimeId),
Expand Down
5 changes: 4 additions & 1 deletion src/main/browser/browser-client-route-cookie-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const routeIdentity = {
orcaProfileId: 'orca-profile-a',
authorityConnectionIdentity: 'paired-runtime:authority-a',
executionHostIdentity: 'execution-host-a',
pairingAuthorityConnectionIdentity: 'paired-runtime:pairing-authority-a',
legacyAuthorityConnectionIdentity: 'paired-runtime:legacy-authority-a',
legacyExecutionHostIdentity: 'legacy-execution-host-a',
storageScope: 'e'.repeat(64)
Expand Down Expand Up @@ -99,7 +100,8 @@ describe('importCookiesIntoClientRoutePartition', () => {
expect(bindingStore.set).toHaveBeenCalledWith(
partition,
expect.stringMatching(/^[a-f0-9]{64}$/),
routeIdentity.storageScope
routeIdentity.storageScope,
expect.stringMatching(/^[a-f0-9]{64}$/)
)
expect(recordClientRouteImportSourceMock).toHaveBeenCalledWith({
environmentId: 'env-a',
Expand Down Expand Up @@ -187,6 +189,7 @@ describe('importCookiesIntoClientRoutePartition', () => {
it('still succeeds when only the authority runtime id changed during the import', async () => {
getRouteIdentityMock.mockReturnValueOnce(routeIdentity).mockReturnValue({
...routeIdentity,
pairingAuthorityConnectionIdentity: 'paired-runtime:pairing-authority-restarted',
legacyAuthorityConnectionIdentity: 'paired-runtime:legacy-authority-restarted',
legacyExecutionHostIdentity: 'legacy-execution-host-restarted'
})
Expand Down
13 changes: 12 additions & 1 deletion src/main/browser/browser-client-route-cookie-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ function bindRoutePartition(
authorityConnectionIdentity: routeIdentity.authorityConnectionIdentity,
executionHostIdentity: routeIdentity.executionHostIdentity
},
compatibleIdentity: {
orcaProfileId: routeIdentity.orcaProfileId,
browserProfileId,
authorityConnectionIdentity: routeIdentity.pairingAuthorityConnectionIdentity,
executionHostIdentity: routeIdentity.executionHostIdentity
},
legacyIdentity: {
orcaProfileId: routeIdentity.orcaProfileId,
browserProfileId,
Expand All @@ -115,7 +121,12 @@ function bindRoutePartition(
})
const persisted = bindings.get(derived.partition)
if (persisted === null) {
bindings.set(derived.partition, derived.bindingFingerprint, routeIdentity.storageScope)
bindings.set(
derived.partition,
derived.bindingFingerprint,
routeIdentity.storageScope,
derived.aliasFingerprint
)
} else if (persisted !== derived.bindingFingerprint) {
throw new Error('browser_route_partition_binding_conflict')
}
Expand Down
37 changes: 35 additions & 2 deletions src/main/browser/browser-route-partition-binding-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ const FINGERPRINT_RE = /^[a-f0-9]{64}$/
* partition name can no longer be derived and is therefore always an orphan.
* `lastUsedAt` orders capacity eviction; 0 marks an entry written before the
* store recorded it, which is therefore evicted first.
* `aliasFingerprints` are newer identities adopted onto the partition. They sit beside
* `fingerprint` rather than replacing it, so an older build that reads only `fingerprint`
* still finds the same jar instead of reporting a binding conflict.
*/
export type BrowserRoutePartitionBinding = {
fingerprint: string
storageScope: string | null
lastUsedAt: number
aliasFingerprints?: readonly string[]
}

export const MAX_ALIAS_FINGERPRINTS = 2

export function bindingAnswersTo(
binding: BrowserRoutePartitionBinding,
fingerprint: string
): boolean {
return binding.fingerprint === fingerprint || !!binding.aliasFingerprints?.includes(fingerprint)
}

export function assertBinding(partition: string, fingerprint: string): void {
Expand Down Expand Up @@ -111,13 +124,33 @@ function parseBinding(legacy: boolean, entry: unknown): BrowserRoutePartitionBin
return null
}
const lastUsedAt = parseLastUsedAt(candidate.lastUsedAt)
const aliases = parseAliasFingerprints(
'aliasFingerprints' in entry ? entry.aliasFingerprints : undefined
)
const optional = aliases.length > 0 ? { aliasFingerprints: aliases } : {}
if (candidate.storageScope === null) {
return { fingerprint: candidate.fingerprint, storageScope: null, lastUsedAt }
return { fingerprint: candidate.fingerprint, storageScope: null, lastUsedAt, ...optional }
}
if (typeof candidate.storageScope !== 'string' || !FINGERPRINT_RE.test(candidate.storageScope)) {
return null
}
return { fingerprint: candidate.fingerprint, storageScope: candidate.storageScope, lastUsedAt }
return {
fingerprint: candidate.fingerprint,
storageScope: candidate.storageScope,
lastUsedAt,
...optional
}
}

// Why lenient: an alias only widens lookup, so a malformed one is dropped rather than
// making the whole binding file unreadable.
function parseAliasFingerprints(value: unknown): readonly string[] {
if (!Array.isArray(value)) {
return []
}
return value
.filter((alias): alias is string => typeof alias === 'string' && FINGERPRINT_RE.test(alias))
.slice(-MAX_ALIAS_FINGERPRINTS)
}

// Why: absent on entries written before eviction existed, which must evict first.
Expand Down
29 changes: 22 additions & 7 deletions src/main/browser/browser-route-partition-binding-store-fake.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
import type { BrowserRoutePartitionBindingStore } from './browser-route-session-registry-contract'

export type BrowserRoutePartitionBindingStoreFake = BrowserRoutePartitionBindingStore & {
entries: Map<string, { fingerprint: string; storageScope: string }>
entries: Map<string, FakeBinding>
}

type FakeBinding = { fingerprint: string; storageScope: string; aliasFingerprints?: string[] }

/** In-memory stand-in for the persisted binding store, for tests that only need its semantics. */
export function createBrowserRoutePartitionBindingStoreFake(): BrowserRoutePartitionBindingStoreFake {
const entries = new Map<string, { fingerprint: string; storageScope: string }>()
const entries = new Map<string, FakeBinding>()
return {
entries,
get: (partition) => entries.get(partition)?.fingerprint ?? null,
set: (partition, fingerprint, storageScope) => {
entries.set(partition, { fingerprint, storageScope })
set: (partition, fingerprint, storageScope, alias) => {
entries.set(partition, {
fingerprint,
storageScope,
...(alias ? { aliasFingerprints: [alias] } : {})
})
return []
},
touch: () => {},
findPartitionByFingerprint: (fingerprint) => {
for (const [partition, entry] of entries) {
if (entry.fingerprint === fingerprint) {
if (entry.fingerprint === fingerprint || entry.aliasFingerprints?.includes(fingerprint)) {
return partition
}
}
return null
},
rebind: (partition, fingerprint, storageScope) => {
entries.set(partition, { fingerprint, storageScope })
rebind: (partition, fingerprint, storageScope, alias) => {
const existing = entries.get(partition)
if (!existing) {
throw new Error('browser_route_partition_binding_invalid')
}
const aliases = (existing.aliasFingerprints ?? []).filter((entry) => entry !== fingerprint)
entries.set(partition, {
fingerprint,
storageScope,
aliasFingerprints: alias && !aliases.includes(alias) ? [...aliases, alias] : aliases
})
}
}
}
Loading
Loading