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
2 changes: 1 addition & 1 deletion config/scripts/ci-shard-timings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9412,8 +9412,8 @@
"src/renderer/src/hooks/ipc-events/agent-status-terminal-title-tab-write.test.ts": 1604,
"src/renderer/src/hooks/ipc-events/browser-request-ipc-bridge.owner.test.ts": 465,
"src/renderer/src/hooks/ipc-events/browser-request-ipc-bridge.profile-switch.test.ts": 347,
"src/renderer/src/hooks/ipc-events/browser-state-capture-paint-hold.test.ts": 614,
"src/renderer/src/hooks/ipc-events/browser-state-open-link-profile.test.ts": 646,
"src/renderer/src/hooks/ipc-events/browser-state-paint-holds.test.ts": 614,
"src/renderer/src/hooks/ipc-events/direct-ssh-connect-reply-routing.test.ts": 1197,
"src/renderer/src/hooks/ipc-events/direct-ssh-hydration-fanout.test.ts": 1548,
"src/renderer/src/hooks/ipc-events/direct-ssh-hydration-target-metadata.test.ts": 1431,
Expand Down
52 changes: 36 additions & 16 deletions src/renderer/src/hooks/ipc-events/browser-state-ipc-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ function isClientHostedBrowserPage(browserPageId: string): boolean {
)
}

/** One automation-visibility lease per page while main reports it held; repeats are ignored. */
function createMainOwnedPaintHolds(): {
set: (browserPageId: string, held: boolean) => void
releaseAll: () => void
} {
const tokens = new Map<string, string>()
return {
set: (browserPageId, held) => {
const token = tokens.get(browserPageId)
if (held && !token) {
tokens.set(browserPageId, acquireBrowserAutomationVisibility(browserPageId))
} else if (!held && token) {
tokens.delete(browserPageId)
releaseBrowserAutomationVisibility(token)
}
},
// A dead hold cannot release later; clear it now so the page cannot remain drawn indefinitely.
releaseAll: () => {
for (const token of tokens.values()) {
releaseBrowserAutomationVisibility(token)
}
tokens.clear()
}
}
}

export function registerBrowserStateIpcBridge(
unsubs: (() => void)[],
isRuntimeEnvironmentActive: () => boolean
Expand Down Expand Up @@ -99,26 +125,14 @@ export function registerBrowserStateIpcBridge(
})
)
// Why: main owns capture holds and sends each page's first hold and last release; no reply is awaited.
const capturePaintHoldTokens = new Map<string, string>()
const capturePaintHolds = createMainOwnedPaintHolds()
const unsubscribeCapturePaintHold = window.api.browser.onCapturePaintHold?.(
({ browserPageId, held }) => {
const token = capturePaintHoldTokens.get(browserPageId)
if (held && !token) {
capturePaintHoldTokens.set(browserPageId, acquireBrowserAutomationVisibility(browserPageId))
} else if (!held && token) {
capturePaintHoldTokens.delete(browserPageId)
releaseBrowserAutomationVisibility(token)
}
}
({ browserPageId, held }) => capturePaintHolds.set(browserPageId, held)
)
if (unsubscribeCapturePaintHold) {
unsubs.push(() => {
unsubscribeCapturePaintHold()
// A dead hold cannot release later; clear it now so the page cannot remain drawn indefinitely.
for (const token of capturePaintHoldTokens.values()) {
releaseBrowserAutomationVisibility(token)
}
capturePaintHoldTokens.clear()
capturePaintHolds.releaseAll()
})
}
const unsubscribeAgentInputFocusGuard = window.api.browser.onAgentInputFocusGuard?.(
Expand All @@ -139,13 +153,19 @@ export function registerBrowserStateIpcBridge(
clearAgentInputFocusGuards()
})
}
// Why: the bootstrap lease is fixed at creation; an agent's page in a hidden worktree must keep drawing while it drives it.
const agentActivityPaintHolds = createMainOwnedPaintHolds()
const unsubscribeAgentActivity = window.api.browser.onAgentActivity?.(
({ browserPageId, worktreeId, active }) => {
setBrowserAgentPageActive(browserPageId, active, worktreeId)
agentActivityPaintHolds.set(browserPageId, active)
}
)
if (unsubscribeAgentActivity) {
unsubs.push(unsubscribeAgentActivity)
unsubs.push(() => {
unsubscribeAgentActivity()
agentActivityPaintHolds.releaseAll()
})
Comment on lines +156 to +168

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '1,160p' src/renderer/src/space.tsx
sed -n '1,150p' src/renderer/src/hooks/useIpcEvents.ts
rg -n 'installAppLifetimeIpcEvents|import.meta.hot|reloadIgnoringCache|webContents.reload|destroyRemovedBrowserWebview' src/renderer/src src/main

Repository: stablyai/orca

Length of output: 14261


Script executed:

set -u
printf '%s\n' '--- renderer root helper ---'
sed -n '1,220p' src/renderer/src/lib/react-renderer-root.ts
printf '%s\n' '--- app lifetime bridge ---'
sed -n '1,240p' src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts
printf '%s\n' '--- workspace-space reload wiring ---'
sed -n '1,120p' src/main/window/workspace-space-window.ts
sed -n '1,100p' src/main/window/main-window-shortcut-actions.ts
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'workspaceSpaceWindow' -e 'webContents.reload' -e 'getOrCreateRendererRoot' -e 'guest-destroyed' -e 'page-closed' src/main src/renderer/src | head -240

Repository: stablyai/orca

Length of output: 18156


Script executed:

set -u
printf '%s\n' '--- main renderer entry and app mount ---'
sed -n '1,150p' src/renderer/src/main.tsx
sed -n '1,90p' src/renderer/src/App.tsx
sed -n '1,90p' src/renderer/src/app-shell/use-app-shell-services.ts
printf '%s\n' '--- browser window reload callers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'reloadIgnoringCache()' -e 'webContents.reload()' -e 'mainWindow.webContents' -e 'getMainWindow' -e 'BrowserWindow' src/main/window src/main/menu src/main | head -260
printf '%s\n' '--- renderer/guest destruction bindings ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'render-process-gone' -e 'web-contents-created' -e 'guest-destroyed' -e 'destroyRemovedBrowserWebview' -e 'destroyBrowserGuest' -e 'webview.destroy' -e 'window.close' src/main/browser src/main/window src/renderer/src | head -300

Repository: stablyai/orca

Length of output: 41492


Script executed:

set -u
printf '%s\n' '--- retained browser page registry ---'
sed -n '1,360p' src/renderer/src/components/browser-pane/browser-client-page-retained-elements.ts
printf '%s\n' '--- host webview registry and page webview lifecycle ---'
sed -n '1,250p' src/renderer/src/components/browser-pane/host-guest/webview-registry.ts
sed -n '1,230p' src/renderer/src/components/browser-pane/host-guest/browser-page-webview.ts
printf '%s\n' '--- main-side guest lifecycle ---'
sed -n '1,230p' src/main/browser/browser-manager-guest-navigation-policy.ts
sed -n '1,190p' src/main/browser/browser-manager-registration.ts

Repository: stablyai/orca

Length of output: 30925


Script executed:

set -u
sed -n '220,390p' src/renderer/src/components/browser-pane/host-guest/webview-registry.ts
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'ensureBrowserPageWebview(' -e 'destroyPersistentWebview(' -e 'replacePersistentWebview(' -e 'unregisterPersistentWebview(' src/renderer/src/components/browser-pane

Repository: stablyai/orca

Length of output: 6362


Hydrate agent activity when Fast Refresh reinstalls the bridge.

During development HMR, the app can rerun the useIpcEvents effect while the persistent browser guest remains alive. The cleanup releases the old visibility lease, but the new onAgentActivity listener receives no snapshot of the already-active page. The hidden-worktree retention pass can then evict that page before the command ends.

Add an initialization snapshot or request-response synchronization for agent activity. Scope this correction to the development HMR lifecycle; a full renderer reload destroys the guest and ends its activity.

}
const unsubscribeAgentCursor = window.api.browser.onAgentCursor?.((event) => {
// Main waits for this answer, so a page nobody can see answers at once.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import { isBrowserAutomationVisible } from '@/components/browser-pane/host-guest
import { registerBrowserStateIpcBridge } from './browser-state-ipc-bridge'

type CapturePaintHoldEvent = { browserPageId: string; held: boolean }
type AgentActivityEvent = { browserPageId: string; worktreeId: string | null; active: boolean }

function captureHoldHandler(unsubs: (() => void)[] = []): (event: CapturePaintHoldEvent) => void {
let handler: ((event: CapturePaintHoldEvent) => void) | null = null
function registerBridge(unsubs: (() => void)[] = []): {
onHold: (event: CapturePaintHoldEvent) => void
onAgentActivity: (event: AgentActivityEvent) => void
} {
let onHold: ((event: CapturePaintHoldEvent) => void) | null = null
let onAgentActivity: ((event: AgentActivityEvent) => void) | null = null
const subscribe = vi.fn(() => () => {})
vi.stubGlobal('window', {
api: {
Expand All @@ -32,27 +37,31 @@ function captureHoldHandler(unsubs: (() => void)[] = []): (event: CapturePaintHo
onOpenLinkInOrcaTab: subscribe,
onSessionProfilesChanged: subscribe,
onCapturePaintHold: (callback: (event: CapturePaintHoldEvent) => void) => {
handler = callback
onHold = callback
return () => {}
},
onAgentActivity: (callback: (event: AgentActivityEvent) => void) => {
onAgentActivity = callback
return () => {}
}
}
}
})

registerBrowserStateIpcBridge(unsubs, () => false)
if (!handler) {
throw new Error('Expected the bridge to subscribe to browser:capturePaintHold')
if (!onHold || !onAgentActivity) {
throw new Error('Expected the bridge to subscribe to capture holds and agent activity')
}
return handler
return { onHold, onAgentActivity }
}

describe('capture paint holds from main', () => {
afterEach(() => {
vi.unstubAllGlobals()
})
afterEach(() => {
vi.unstubAllGlobals()
})

describe('capture paint holds from main', () => {
it('keeps the page drawn from the hold until its release, ignoring repeats', () => {
const onHold = captureHoldHandler()
const { onHold } = registerBridge()

onHold({ browserPageId: 'page-1', held: true })
onHold({ browserPageId: 'page-1', held: true })
Expand All @@ -67,7 +76,7 @@ describe('capture paint holds from main', () => {

it('releases a live hold when the bridge is disposed', () => {
const unsubs: (() => void)[] = []
const onHold = captureHoldHandler(unsubs)
const { onHold } = registerBridge(unsubs)

onHold({ browserPageId: 'page-2', held: true })
expect(isBrowserAutomationVisible('page-2')).toBe(true)
Expand All @@ -78,3 +87,17 @@ describe('capture paint holds from main', () => {
expect(isBrowserAutomationVisible('page-2')).toBe(false)
})
})

describe('agent activity from main', () => {
// #36161: a fixed bootstrap lease let a driven page in a hidden worktree stop drawing.
it('keeps the page drawn while an agent drives it, until main reports it idle', () => {
const { onAgentActivity } = registerBridge()

onAgentActivity({ browserPageId: 'page-3', worktreeId: 'wt-agent', active: true })
onAgentActivity({ browserPageId: 'page-3', worktreeId: 'wt-agent', active: true })
expect(isBrowserAutomationVisible('page-3')).toBe(true)

onAgentActivity({ browserPageId: 'page-3', worktreeId: 'wt-agent', active: false })
expect(isBrowserAutomationVisible('page-3')).toBe(false)
})
})
Loading