Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

perf(renderer): forget visible-tab-pick state when a worktree is removed (STA-12498) (#36165)

Neil553c0ccb2802
diff --git a/src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts b/src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts
index b06c582e5ca..df5ac8cc49a 100644
--- a/src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts
+++ b/src/renderer/src/runtime/web-session-tabs-sync/tracking-lifecycle.ts
@@ -1,4 +1,7 @@
-import { forgetVisibleTabPicksForEnvironment } from '../web-session-visible-tab-pick-report'
+import {
+ forgetVisibleTabPicksForEnvironment,
+ forgetVisibleTabPicksForWorktree
+} from '../web-session-visible-tab-pick-report'
import {
latestSessionTabsSnapshotByWorktree,
replayableSessionTabsSnapshotByWorktree,
@@ -154,6 +157,7 @@ export function clearWebSessionTabsTrackingForWorktree(
clearWebSessionBrowserPlacementsForWorktree(environmentId, worktreeId)
clearWebSessionTerminalPlacementsForWorktree(environmentId, worktreeId)
forgetMirroredTerminalHandles(environmentId, worktreeId)
+ forgetVisibleTabPicksForWorktree(environmentId, worktreeId)
}
export function clearWebSessionTabsTrackingForEnvironment(environmentId: string): void {
diff --git a/src/renderer/src/runtime/web-session-visible-tab-pick-report.test.ts b/src/renderer/src/runtime/web-session-visible-tab-pick-report.test.ts
index 2598364247f..5993c4f89dc 100644
--- a/src/renderer/src/runtime/web-session-visible-tab-pick-report.test.ts
+++ b/src/renderer/src/runtime/web-session-visible-tab-pick-report.test.ts
@@ -1,5 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import type { RuntimeMobileSessionTabsResult } from '../../../shared/runtime-types'
+import type {
+ RuntimeMobileSessionTabsRemovedResult,
+ RuntimeMobileSessionTabsResult
+} from '../../../shared/runtime-types'
import { toWebTerminalSurfaceTabId } from '../../../shared/terminal-surface-id'
const WT = 'repo::/srv/project'
@@ -41,6 +44,7 @@ vi.mock('./web-session-tabs-sync/frame-drawn-server-workspaces', () => ({
import { setRuntimeEnvironmentConnectionGenerationForTests } from '../store/slices/runtime-status-connection-generation'
import {
forgetVisibleTabPicksForEnvironment,
+ forgetVisibleTabPicksForWorktree,
reportVisibleTabPickToHost,
resetReportedVisibleTabPicksForTests,
VISIBLE_TAB_PICK_SETTLE_MS
@@ -149,6 +153,29 @@ describe('reporting the tab the desktop shows to a server that remembers picks p
expect(mocks.call).toHaveBeenCalledTimes(1)
})
+ it('forgets a removed workspace and never caches its removal frame', () => {
+ mocks.state.activeWorktreeId = 'other'
+ reportVisibleTabPickToHost(ENV, frame('host-tab-2'))
+ // Removal forgets the workspace and then reports its removal frame, the store-patch order.
+ forgetVisibleTabPicksForWorktree(ENV, WT)
+ const removal: RuntimeMobileSessionTabsRemovedResult = {
+ ...frame('host-tab-2'),
+ removed: true,
+ activeGroupId: null,
+ activeTabId: null,
+ activeTabType: null,
+ tabs: []
+ }
+ reportVisibleTabPickToHost(ENV, removal)
+ expect(vi.getTimerCount()).toBe(0)
+
+ const previous = mocks.state
+ mocks.state = { ...previous, activeWorktreeId: WT }
+ mocks.listener?.(mocks.state, previous)
+ expect(vi.getTimerCount()).toBe(0)
+ expect(mocks.call).not.toHaveBeenCalled()
+ })
+
it('reports nothing for a workspace that is not on screen, or not owned by this server', () => {
mocks.state.activeWorktreeId = 'other'
deliver(frame('host-tab-2'))
diff --git a/src/renderer/src/runtime/web-session-visible-tab-pick-report.ts b/src/renderer/src/runtime/web-session-visible-tab-pick-report.ts
index be169bc00e8..d1a9cd97f9a 100644
--- a/src/renderer/src/runtime/web-session-visible-tab-pick-report.ts
+++ b/src/renderer/src/runtime/web-session-visible-tab-pick-report.ts
@@ -18,6 +18,7 @@ import {
} from './web-session-focus-intent'
import { WEB_SESSION_TAB_RPC_TIMEOUT_MS } from './web-session-tab-rpc-timeout'
import { isServerFrameDrawnWorkspace } from './web-session-tabs-sync/frame-drawn-server-workspaces'
+import { isWebSessionTabsWorktreeRemovalFrame } from './web-session-tabs-sync/session-tabs-inventory-absence'
/** The pane last reported per connection and workspace. Reporting again only when the desktop's own
* pane changes keeps two windows sharing one device id from steering the pick back and forth. */
@@ -93,7 +94,11 @@ export function reportVisibleTabPickToHost(
): void {
const frameKey = `${environmentId}\0${snapshot.worktree}`
// Only servers that keep a pick per device project it; an older one would move the host instead.
- if (!snapshot.publicationEpoch.endsWith(CLIENT_NAVIGATION_PUBLICATION_EPOCH_SUFFIX)) {
+ // A removal frame has nothing to pick, and caching it would outlive the workspace.
+ if (
+ !snapshot.publicationEpoch.endsWith(CLIENT_NAVIGATION_PUBLICATION_EPOCH_SUFFIX) ||
+ isWebSessionTabsWorktreeRemovalFrame(snapshot)
+ ) {
latestFrameByWorkspace.delete(frameKey)
return
}
@@ -269,28 +274,38 @@ function visibleTerminalPane(
}
}
-/** Mirror teardown for an environment drops everything recorded for it. */
-export function forgetVisibleTabPicksForEnvironment(environmentId: string): void {
- teardownEpochByEnvironment.set(
- environmentId,
- (teardownEpochByEnvironment.get(environmentId) ?? 0) + 1
- )
- const prefix = `${environmentId}\0`
+function forgetVisibleTabPicks(matches: (frameKey: string) => boolean): void {
for (const map of [reportedPaneByWorkspace, latestFrameByWorkspace]) {
for (const key of map.keys()) {
- if (key.startsWith(prefix)) {
+ if (matches(key)) {
map.delete(key)
}
}
}
for (const [key, timer] of pendingCheckByWorkspace) {
- if (key.startsWith(prefix)) {
+ if (matches(key)) {
clearTimeout(timer)
pendingCheckByWorkspace.delete(key)
}
}
}
+/** Mirror teardown for an environment drops everything recorded for it. */
+export function forgetVisibleTabPicksForEnvironment(environmentId: string): void {
+ teardownEpochByEnvironment.set(
+ environmentId,
+ (teardownEpochByEnvironment.get(environmentId) ?? 0) + 1
+ )
+ const prefix = `${environmentId}\0`
+ forgetVisibleTabPicks((key) => key.startsWith(prefix))
+}
+
+/** A removed workspace drops its record, so later workspace switches never scan it. */
+export function forgetVisibleTabPicksForWorktree(environmentId: string, worktreeId: string): void {
+ const frameKey = `${environmentId}\0${worktreeId}`
+ forgetVisibleTabPicks((key) => key === frameKey)
+}
+
export function resetReportedVisibleTabPicksForTests(): void {
reportedPaneByWorkspace.clear()
latestFrameByWorkspace.clear()