Gate the Gemini GPU fallback on pane-owner evidence instead of raw title text (title evidence plan, PR 1) (#7458)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Brennan Benson
2026-07-06 15:01:06 -07:00
committed by GitHub
co-authored by Orca
parent 47feae3fb3
commit 6aed5c1122
9 changed files with 694 additions and 22 deletions
@@ -5,7 +5,8 @@ import {
import type { AppState } from '@/store/types'
import { findTerminalTabWorktreeId } from './native-chat-file-link'
export type NativeChatRuntimeOwnerState = Pick<AppState, 'tabsByWorktree'> & WorktreeRuntimeOwnerState
export type NativeChatRuntimeOwnerState = Pick<AppState, 'tabsByWorktree'> &
WorktreeRuntimeOwnerState
/**
* The runtime owner id for a Native Chat pane, as a primitive — non-null only for
@@ -20,7 +20,13 @@ const runtimeEnvironmentsSubscribe = vi.fn()
const ENV = 'env-1'
function message(id: string): NativeChatMessage {
return { id, role: 'assistant', blocks: [{ type: 'text', text: id }], timestamp: 1, source: 'transcript' }
return {
id,
role: 'assistant',
blocks: [{ type: 'text', text: id }],
timestamp: 1,
source: 'transcript'
}
}
function okEnvelope(result: unknown): { ok: true; result: unknown } {
@@ -224,7 +230,11 @@ describe('runtime readSession error mapping', () => {
expect(
toRuntimeNativeChatErrorMessage(
new RuntimeRpcCallError({ id: 'r-1', ok: false, error: { code: 'method_not_found', message: 'x' } })
new RuntimeRpcCallError({
id: 'r-1',
ok: false,
error: { code: 'method_not_found', message: 'x' }
})
)
).toEqual(tooOld)
@@ -49,7 +49,13 @@ import {
} from './use-native-chat-live-session'
function assistant(id: string, text: string): NativeChatMessage {
return { id, role: 'assistant', blocks: [{ type: 'text', text }], timestamp: 2, source: 'transcript' }
return {
id,
role: 'assistant',
blocks: [{ type: 'text', text }],
timestamp: 2,
source: 'transcript'
}
}
function user(id: string, text: string): NativeChatMessage {
@@ -176,7 +182,12 @@ describe('useNativeChatLiveSession — transport routing', () => {
expect(transportFactory).toHaveBeenCalledWith('env-1')
const transport = getMockTransport('env-1')
expect(transport.readSession).toHaveBeenCalledWith(AGENT, SESSION, expect.any(Number), undefined)
expect(transport.readSession).toHaveBeenCalledWith(
AGENT,
SESSION,
expect.any(Number),
undefined
)
expect(transport.subscribe).toHaveBeenCalledOnce()
})
@@ -1007,6 +1007,221 @@ describe('connectPanePty', () => {
})
})
it('drives runtime title, tab title, and renderer policy from one title decision', async () => {
const { connectPanePty } = await import('./pty-connection')
const pane = createPane(1)
const transport = createMockTransport('pty-gemini')
transportFactoryQueue.push(transport)
const manager = createManager(1, 1)
const deps = createDeps()
connectPanePty(pane as never, manager as never, deps as never)
await flushAsyncTicks()
const onTitleChange = createdTransportOptions[0]?.onTitleChange as
| ((title: string, rawTitle: string) => void)
| undefined
if (!onTitleChange) {
throw new Error('missing title callback')
}
onTitleChange('✦ Gemini CLI', '✦ Gemini CLI')
// Display/runtime/tab title and the GPU gate all come from the same decision.
expect(deps.setRuntimePaneTitle).toHaveBeenCalledWith('tab-1', 1, '✦ Gemini CLI')
expect(deps.updateTabTitle).toHaveBeenCalledWith('tab-1', '✦ Gemini CLI')
// Genuine Gemini under the default `auto` setting takes the DOM fallback.
expect(manager.setPaneGpuRendering).toHaveBeenCalledWith(1, false)
})
it('keeps GPU enabled when a pane-scoped OMP owner emits a Gemini-looking title', async () => {
const { connectPanePty } = await import('./pty-connection')
const paneKey = makePaneKey('tab-1', LEAF_1)
mockStoreState = {
...mockStoreState,
agentStatusByPaneKey: {
[paneKey]: {
paneKey,
agentType: 'omp',
state: 'working',
prompt: '',
updatedAt: Date.now(),
stateStartedAt: Date.now(),
stateHistory: []
}
}
} as StoreState
const pane = createPane(1)
const transport = createMockTransport('pty-omp-gemini-cwd')
transportFactoryQueue.push(transport)
const manager = createManager(1, 1)
const deps = createDeps()
connectPanePty(pane as never, manager as never, deps as never)
await flushAsyncTicks()
const onTitleChange = createdTransportOptions[0]?.onTitleChange as
| ((title: string, rawTitle: string) => void)
| undefined
if (!onTitleChange) {
throw new Error('missing title callback')
}
onTitleChange('✦ Gemini CLI', '✦ Gemini CLI')
// Pane-scoped owner evidence outranks the raw title, so the fallback cannot fire.
expect(manager.setPaneGpuRendering).toHaveBeenCalledWith(1, true)
expect(manager.setPaneGpuRendering).not.toHaveBeenCalledWith(1, false)
})
it('does not let one split pane title change another pane GPU state', async () => {
const { connectPanePty } = await import('./pty-connection')
const pane1 = createPane(1)
const pane2 = createPane(2)
const transport1 = createMockTransport('pty-split-1')
const transport2 = createMockTransport('pty-split-2')
transportFactoryQueue.push(transport1, transport2)
const manager = createManager(2, 1)
connectPanePty(pane1 as never, manager as never, createDeps() as never)
connectPanePty(pane2 as never, manager as never, createDeps() as never)
await flushAsyncTicks()
const onTitleChange1 = createdTransportOptions[0]?.onTitleChange as
| ((title: string, rawTitle: string) => void)
| undefined
if (!onTitleChange1) {
throw new Error('missing title callback for split pane 1')
}
onTitleChange1('✦ Gemini CLI', '✦ Gemini CLI')
const gpuCalls = manager.setPaneGpuRendering.mock.calls as [number, boolean][]
expect(gpuCalls.some(([paneId]) => paneId === 1)).toBe(true)
expect(gpuCalls.every(([paneId]) => paneId !== 2)).toBe(true)
})
it('DOM-gates a genuine Gemini split pane even when the tab launched a non-Gemini agent', async () => {
const { connectPanePty } = await import('./pty-connection')
// The shared tab.launchAgent must not veto the renderer for a sibling pane.
mockStoreState = {
...mockStoreState,
tabsByWorktree: {
'wt-1': [{ id: 'tab-1', ptyId: 'tab-pty', launchAgent: 'omp' }]
}
} as StoreState
const pane1 = createPane(1)
const pane2 = createPane(2)
const transport1 = createMockTransport('pty-split-owner-1')
const transport2 = createMockTransport('pty-split-owner-2')
transportFactoryQueue.push(transport1, transport2)
const manager = createManager(2, 2)
connectPanePty(pane1 as never, manager as never, createDeps() as never)
connectPanePty(pane2 as never, manager as never, createDeps() as never)
await flushAsyncTicks()
const onTitleChange2 = createdTransportOptions[1]?.onTitleChange as
| ((title: string, rawTitle: string) => void)
| undefined
if (!onTitleChange2) {
throw new Error('missing title callback for split pane 2')
}
onTitleChange2('✦ Gemini CLI', '✦ Gemini CLI')
expect(manager.setPaneGpuRendering).toHaveBeenCalledWith(2, false)
})
it('DOM-gates a genuine Gemini title in a pane whose launch agent was non-Gemini', async () => {
const { connectPanePty } = await import('./pty-connection')
const pane = createPane(1)
const transport = createMockTransport('pty-reused-gemini')
transportFactoryQueue.push(transport)
const manager = createManager(1, 1)
// Stale, never-cleared launch identity must not veto the renderer.
const deps = createDeps({ startup: { command: 'claude', launchAgent: 'claude' } })
connectPanePty(pane as never, manager as never, deps as never)
await flushAsyncTicks()
const onTitleChange = createdTransportOptions[0]?.onTitleChange as
| ((title: string, rawTitle: string) => void)
| undefined
if (!onTitleChange) {
throw new Error('missing title callback')
}
onTitleChange('✦ Gemini CLI', '✦ Gemini CLI')
expect(manager.setPaneGpuRendering).toHaveBeenCalledWith(1, false)
})
it('DOM-gates a genuine Gemini title when the only pane row is a done non-Gemini agent', async () => {
const { connectPanePty } = await import('./pty-connection')
const paneKey = makePaneKey('tab-1', LEAF_1)
mockStoreState = {
...mockStoreState,
agentStatusByPaneKey: {
[paneKey]: {
paneKey,
agentType: 'claude',
state: 'done',
prompt: '',
updatedAt: Date.now(),
stateStartedAt: Date.now(),
stateHistory: []
}
}
} as StoreState
const pane = createPane(1)
const transport = createMockTransport('pty-reused-done-row')
transportFactoryQueue.push(transport)
const manager = createManager(1, 1)
const deps = createDeps()
connectPanePty(pane as never, manager as never, deps as never)
await flushAsyncTicks()
const onTitleChange = createdTransportOptions[0]?.onTitleChange as
| ((title: string, rawTitle: string) => void)
| undefined
if (!onTitleChange) {
throw new Error('missing title callback')
}
onTitleChange('✦ Gemini CLI', '✦ Gemini CLI')
// A `done` row is a leftover from a prior agent, so it must not veto.
expect(manager.setPaneGpuRendering).toHaveBeenCalledWith(1, false)
})
it('DOM-gates a genuine Gemini title when the only pane row is a stale non-Gemini agent', async () => {
const { connectPanePty } = await import('./pty-connection')
const paneKey = makePaneKey('tab-1', LEAF_1)
const staleAt = Date.now() - 60 * 60 * 1000
mockStoreState = {
...mockStoreState,
agentStatusByPaneKey: {
[paneKey]: {
paneKey,
agentType: 'claude',
state: 'working',
prompt: '',
updatedAt: staleAt,
stateStartedAt: staleAt,
stateHistory: []
}
}
} as StoreState
const pane = createPane(1)
const transport = createMockTransport('pty-reused-stale-row')
transportFactoryQueue.push(transport)
const manager = createManager(1, 1)
const deps = createDeps()
connectPanePty(pane as never, manager as never, deps as never)
await flushAsyncTicks()
const onTitleChange = createdTransportOptions[0]?.onTitleChange as
| ((title: string, rawTitle: string) => void)
| undefined
if (!onTitleChange) {
throw new Error('missing title callback')
}
onTitleChange('✦ Gemini CLI', '✦ Gemini CLI')
// A stale working row (older than AGENT_STATUS_STALE_AFTER_MS) must not veto.
expect(manager.setPaneGpuRendering).toHaveBeenCalledWith(1, false)
})
it('normalizes after shell word deletion edits a typed command to omp', async () => {
const { connectPanePty } = await import('./pty-connection')
enableActiveRuntimeEnvironment()
@@ -3,12 +3,8 @@ import type { PaneManager, ManagedPane } from '@/lib/pane-manager/pane-manager'
import type { ManagedPaneInternal } from '@/lib/pane-manager/pane-manager-types'
import type { IBuffer, IDisposable } from '@xterm/xterm'
import { resolveCursorAgentImeAnchor } from '@/lib/pane-manager/terminal-ime-anchor'
import {
detectAgentStatusFromTitle,
agentTypeToIconAgent,
isGeminiTerminalTitle,
isClaudeAgent
} from '@/lib/agent-status'
import { detectAgentStatusFromTitle, agentTypeToIconAgent, isClaudeAgent } from '@/lib/agent-status'
import { resolvePaneTitleDecision } from './terminal-title-evidence'
import { scheduleRuntimeGraphSync } from '@/runtime/sync-runtime-graph'
import { useAppStore } from '@/store'
import { getWorktreeMapFromState } from '@/store/selectors'
@@ -1390,15 +1386,22 @@ export function connectPanePty(
)?.title
return runtimeTitle ?? tabTitle ?? null
}
const hasFreshPaneAgentSurface = (): boolean => {
const state = useAppStore.getState()
const entry = state.agentStatusByPaneKey[cacheKey]
const now = Date.now()
const entryIsFresh =
entry &&
// Why: a pane-scoped explicit row only counts as current ownership evidence
// when it is fresh and not already `done` — a stale or completed row is a
// leftover from a prior agent that may no longer own the shell.
const isFreshActivePaneAgentEntry = (
entry: AgentStatusEntry | undefined
): entry is AgentStatusEntry => {
return (
!!entry &&
typeof entry.updatedAt === 'number' &&
now - entry.updatedAt <= AGENT_STATUS_STALE_AFTER_MS
if (entryIsFresh && entry.state !== 'done') {
Date.now() - entry.updatedAt <= AGENT_STATUS_STALE_AFTER_MS &&
entry.state !== 'done'
)
}
const hasFreshPaneAgentSurface = (): boolean => {
const entry = useAppStore.getState().agentStatusByPaneKey[cacheKey]
if (isFreshActivePaneAgentEntry(entry)) {
return true
}
const liveTitle = getLivePaneAgentTitle()
@@ -1493,6 +1496,23 @@ export function connectPanePty(
state.agentStatusByPaneKey[cacheKey]?.agentType
)
}
// Why: the renderer veto (owner evidence beating a Gemini-looking title) must
// use only pane-scoped, CURRENT ownership. getAuthoritativePaneAgent leads
// with the tab-shared `tab.launchAgent` and a never-cleared
// `paneStartup.launchAgent`, which would let a sibling split pane or a reused
// pane keep WebGL for a genuine Gemini terminal (#7428 regression class).
// Launch identity is excluded, and the never-clearing startup seed
// (`paneStartup.initialAgentStatus`) too; a stale or `done` explicit row is
// ignored via the freshness predicate so a reused pane cannot inherit a prior
// agent's veto. Only live foreground command inference and a fresh, active
// hook row count. A genuine OMP/Pi pane stays protected owner-independently by
// the isPiAgentTitle guard inside isGeminiTerminalTitle.
const getPaneScopedRendererOwner = (): AgentType | undefined => {
const entry = useAppStore.getState().agentStatusByPaneKey[cacheKey]
return (
commandInferredPaneAgent ?? (isFreshActivePaneAgentEntry(entry) ? entry.agentType : undefined)
)
}
const clearInferredInterruptWorkingTitle = (): void => {
const state = useAppStore.getState()
const currentTitle = state.runtimePaneTitlesByTabId?.[deps.tabId]?.[pane.id]
@@ -2166,7 +2186,17 @@ export function connectPanePty(
let allowInitialIdleCacheSeed = false
const onTitleChange = (title: string, rawTitle: string): void => {
const paneTitle = normalizeCompatibleAgentTitleForOwner(title, getAuthoritativePaneAgent())
// Why: one owner-aware decision drives the display label, the runtime/tab
// title, task-completion tracking, and the renderer gate, so raw title text
// can no longer disable GPU behind stronger owner evidence (#7428/#7447).
const decision = resolvePaneTitleDecision({
normalizedTitle: title,
rawTitle,
displayOwnerAgentType: getAuthoritativePaneAgent(),
rendererOwnerAgentType: getPaneScopedRendererOwner(),
userGpuMode: useAppStore.getState().settings?.terminalGpuAcceleration ?? 'auto'
})
const paneTitle = decision.displayTitle
if (
shouldSuppressCodexAutoApprovalSyntheticTitle(paneTitle, {
paneKey: cacheKey,
@@ -2176,10 +2206,10 @@ export function connectPanePty(
) {
return
}
manager.setPaneGpuRendering(pane.id, !isGeminiTerminalTitle(rawTitle))
manager.setPaneGpuRendering(pane.id, decision.rendererPolicy.gpuEnabled)
deps.setRuntimePaneTitle(deps.tabId, pane.id, paneTitle)
if (syncAgentTaskCompleteTrackingEnabled()) {
agentCompletionCoordinator.observeTitle(rawTitle)
agentCompletionCoordinator.observeTitle(decision.rawTitle)
}
// Why: only the focused pane should drive the tab title — otherwise two
// agents in split panes cause rapid title flickering as each emits OSC
@@ -0,0 +1,185 @@
import { describe, expect, it } from 'vitest'
import type { AgentType } from '../../../../shared/agent-status-types'
import { resolvePaneRendererPolicy } from './terminal-renderer-policy'
const GEMINI_WORKING = '✦'
describe('resolvePaneRendererPolicy', () => {
describe('user GPU modes', () => {
it('keeps the content gate open under `off` for non-Gemini panes', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: 'zsh',
ownerAgentType: undefined,
userGpuMode: 'off'
})
// Why: the mode gate downstream forces DOM; the gate stays open so a later
// switch to auto/on can re-attach without waiting for a new title frame.
expect(decision).toEqual({
gpuEnabled: true,
reason: 'user-setting',
confidence: 'authoritative'
})
})
it('DOM-gates a genuine Gemini pane under `off`', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: `${GEMINI_WORKING} Gemini CLI`,
ownerAgentType: 'gemini',
userGpuMode: 'off'
})
expect(decision.gpuEnabled).toBe(false)
expect(decision.reason).toBe('user-setting')
})
it('forces GPU on under `on` even for a genuine Gemini pane', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: `${GEMINI_WORKING} Gemini CLI`,
ownerAgentType: 'gemini',
userGpuMode: 'on'
})
// Why: agent compatibility exclusions must not override an explicit on.
expect(decision).toEqual({
gpuEnabled: true,
reason: 'user-setting',
confidence: 'authoritative'
})
})
it('enables GPU under `auto` for an ordinary shell', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: 'bash',
ownerAgentType: undefined,
userGpuMode: 'auto'
})
expect(decision).toEqual({
gpuEnabled: true,
reason: 'capability',
confidence: 'authoritative'
})
})
})
describe('WebGL capability and context-loss containment', () => {
it('disables GPU under `on` when WebGL is unavailable', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: 'bash',
ownerAgentType: undefined,
userGpuMode: 'on',
webglUnavailable: true
})
expect(decision).toEqual({
gpuEnabled: false,
reason: 'capability',
confidence: 'authoritative'
})
})
it('disables GPU under `on` inside context-loss containment', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: 'bash',
ownerAgentType: undefined,
userGpuMode: 'on',
inContextLossContainment: true
})
expect(decision).toEqual({
gpuEnabled: false,
reason: 'context-loss',
confidence: 'authoritative'
})
})
it('disables GPU under `auto` inside context-loss containment', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: 'bash',
ownerAgentType: undefined,
userGpuMode: 'auto',
inContextLossContainment: true
})
expect(decision.gpuEnabled).toBe(false)
expect(decision.reason).toBe('context-loss')
})
})
describe('Gemini compatibility fallback under `auto`', () => {
it('DOM-gates a genuine Gemini title with no authoritative owner', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: `${GEMINI_WORKING} Gemini CLI`,
ownerAgentType: undefined,
userGpuMode: 'auto'
})
expect(decision).toEqual({
gpuEnabled: false,
reason: 'agent-compatibility',
confidence: 'fallback'
})
})
it('DOM-gates a genuine Gemini title with a Gemini owner at higher confidence', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: `${GEMINI_WORKING} Gemini CLI`,
ownerAgentType: 'gemini',
userGpuMode: 'auto'
})
expect(decision).toEqual({
gpuEnabled: false,
reason: 'agent-compatibility',
confidence: 'authoritative'
})
})
it('keeps GPU on when a non-Gemini owner emits a Gemini-looking title', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: `${GEMINI_WORKING} Gemini CLI`,
ownerAgentType: 'omp',
userGpuMode: 'auto'
})
// Why: OMP ownership is authoritative and outranks raw title text (#7428).
expect(decision.gpuEnabled).toBe(true)
expect(decision.reason).toBe('capability')
})
it('does not treat an `unknown` owner as an authoritative non-Gemini veto', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: `${GEMINI_WORKING} Gemini CLI`,
ownerAgentType: 'unknown',
userGpuMode: 'auto'
})
expect(decision.gpuEnabled).toBe(false)
expect(decision.reason).toBe('agent-compatibility')
})
})
describe('agent token text cannot flip renderer policy under authoritative owners', () => {
const AGENT_TOKENS = ['gemini', 'claude', 'codex', 'opencode', 'cursor', 'omp', 'pi'] as const
for (const token of AGENT_TOKENS) {
it(`keeps GPU on when a title mentions "${token}" but owner is another agent`, () => {
const ownerAgentType: AgentType = token === 'claude' ? 'codex' : 'claude'
const decision = resolvePaneRendererPolicy({
rawTitle: token,
ownerAgentType,
userGpuMode: 'auto'
})
expect(decision.gpuEnabled).toBe(true)
})
}
it('keeps GPU on for an OMP owner whose title is exactly the Gemini token', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: 'gemini',
ownerAgentType: 'omp',
userGpuMode: 'auto'
})
expect(decision.gpuEnabled).toBe(true)
})
it('keeps GPU on for a Pi owner whose title is exactly the Gemini token', () => {
const decision = resolvePaneRendererPolicy({
rawTitle: 'gemini',
ownerAgentType: 'pi',
userGpuMode: 'auto'
})
expect(decision.gpuEnabled).toBe(true)
})
})
})
@@ -0,0 +1,107 @@
import { isGeminiTerminalTitle } from '@/lib/agent-status'
import type { AgentType } from '../../../../shared/agent-status-types'
import type { GlobalSettings } from '../../../../shared/types'
export type TerminalGpuAccelerationMode = GlobalSettings['terminalGpuAcceleration']
/**
* The resolved renderer decision for a pane. `gpuEnabled` is the content-compat
* gate passed to `setPaneGpuRendering`; the user-setting mode gate and WebGL
* capability/context-loss latches are still applied downstream by the pane
* manager, so this decision never has to force WebGL on when it is unavailable.
*/
export type RendererPolicyDecision = {
gpuEnabled: boolean
reason: 'user-setting' | 'capability' | 'context-loss' | 'agent-compatibility'
confidence: 'authoritative' | 'fallback'
}
export type ResolvePaneRendererPolicyInput = {
rawTitle: string | null
ownerAgentType: AgentType | null | undefined
userGpuMode: TerminalGpuAccelerationMode
/** Set when the pane cannot obtain a WebGL context at all. */
webglUnavailable?: boolean
/** Set when the pane is inside GPU crash/context-loss containment. */
inContextLossContainment?: boolean
}
// Why: an authoritative non-Gemini owner (OMP, Pi, Claude, a shell, …) outranks
// raw title text. 'unknown' is not authoritative, so it does not veto the
// title-derived Gemini fallback.
function isKnownNonGeminiOwner(ownerAgentType: AgentType | null | undefined): boolean {
return (
typeof ownerAgentType === 'string' &&
ownerAgentType !== '' &&
ownerAgentType !== 'gemini' &&
ownerAgentType !== 'unknown'
)
}
type GeminiCompatFallback = {
disable: boolean
confidence: 'authoritative' | 'fallback'
}
// Why: keep the existing title-driven Gemini fallback, but let owner evidence
// veto it so a Pi/OMP pane whose cwd or session text mentions gemini is never
// forced onto the DOM renderer.
function resolveGeminiCompatFallback(
rawTitle: string | null,
ownerAgentType: AgentType | null | undefined
): GeminiCompatFallback {
if (!isGeminiTerminalTitle(rawTitle ?? '')) {
return { disable: false, confidence: 'authoritative' }
}
if (isKnownNonGeminiOwner(ownerAgentType)) {
return { disable: false, confidence: 'authoritative' }
}
return { disable: true, confidence: ownerAgentType === 'gemini' ? 'authoritative' : 'fallback' }
}
/**
* Resolves the pane renderer (WebGL vs DOM content gate) from the user GPU
* setting, WebGL capability/context-loss state, and owner/title evidence.
*
* Precedence: user `off` keeps the effective renderer on DOM downstream while
* leaving the content gate open for a later mode switch; WebGL
* unavailable/context-loss force DOM; explicit `on` keeps GPU regardless of
* agent compatibility; `auto` applies the Gemini compatibility fallback only
* when owner evidence does not attribute the pane to another agent/shell.
*/
export function resolvePaneRendererPolicy(
input: ResolvePaneRendererPolicyInput
): RendererPolicyDecision {
const { rawTitle, ownerAgentType, userGpuMode } = input
if (userGpuMode === 'off') {
// Why: the user-setting mode gate downstream already forces DOM. Mirror the
// title/owner content gate so a genuine Gemini pane stays DOM-gated while
// other panes keep the gate open for a later switch to `auto`/`on`.
const fallback = resolveGeminiCompatFallback(rawTitle, ownerAgentType)
// Why: carry the fallback's own confidence so identical inputs report the
// same confidence whether the effective mode is `off` or `auto`.
return {
gpuEnabled: !fallback.disable,
reason: 'user-setting',
confidence: fallback.confidence
}
}
if (input.inContextLossContainment) {
return { gpuEnabled: false, reason: 'context-loss', confidence: 'authoritative' }
}
if (input.webglUnavailable) {
return { gpuEnabled: false, reason: 'capability', confidence: 'authoritative' }
}
if (userGpuMode === 'on') {
return { gpuEnabled: true, reason: 'user-setting', confidence: 'authoritative' }
}
const fallback = resolveGeminiCompatFallback(rawTitle, ownerAgentType)
if (fallback.disable) {
return { gpuEnabled: false, reason: 'agent-compatibility', confidence: fallback.confidence }
}
return { gpuEnabled: true, reason: 'capability', confidence: 'authoritative' }
}
@@ -0,0 +1,56 @@
import { describe, expect, it } from 'vitest'
import { resolvePaneDisplayTitle, resolvePaneTitleDecision } from './terminal-title-evidence'
describe('resolvePaneDisplayTitle', () => {
it('normalizes a Pi-compatible title to the resolved OMP owner', () => {
expect(resolvePaneDisplayTitle('Pi ready', 'omp')).toBe('OMP ready')
})
it('passes an unowned title through unchanged', () => {
expect(resolvePaneDisplayTitle('bash', undefined)).toBe('bash')
})
})
describe('resolvePaneTitleDecision', () => {
it('derives the display label and the renderer veto from a pane-scoped OMP owner', () => {
const decision = resolvePaneTitleDecision({
normalizedTitle: 'Pi ready',
rawTitle: '✦ Gemini CLI',
displayOwnerAgentType: 'omp',
rendererOwnerAgentType: 'omp',
userGpuMode: 'auto'
})
expect(decision.displayTitle).toBe('OMP ready')
expect(decision.rawTitle).toBe('✦ Gemini CLI')
// Why: the OMP owner renames the label and vetoes the Gemini glyph fallback.
expect(decision.rendererPolicy.gpuEnabled).toBe(true)
})
it('uses the renderer owner, not the display owner, for the GPU veto', () => {
const decision = resolvePaneTitleDecision({
normalizedTitle: 'Pi ready',
rawTitle: '✦ Gemini CLI',
// Display label follows the sticky/tab-scoped owner, but the renderer veto
// sees no current pane-scoped owner, so the genuine Gemini pane goes DOM.
displayOwnerAgentType: 'omp',
rendererOwnerAgentType: undefined,
userGpuMode: 'auto'
})
expect(decision.displayTitle).toBe('OMP ready')
expect(decision.rendererPolicy.gpuEnabled).toBe(false)
expect(decision.rendererPolicy.reason).toBe('agent-compatibility')
})
it('DOM-gates a genuine Gemini pane while preserving its raw title', () => {
const decision = resolvePaneTitleDecision({
normalizedTitle: '✦ Gemini CLI',
rawTitle: '✦ Gemini CLI',
displayOwnerAgentType: 'gemini',
rendererOwnerAgentType: 'gemini',
userGpuMode: 'auto'
})
expect(decision.rawTitle).toBe('✦ Gemini CLI')
expect(decision.rendererPolicy.gpuEnabled).toBe(false)
expect(decision.rendererPolicy.reason).toBe('agent-compatibility')
})
})
@@ -0,0 +1,57 @@
import { normalizeCompatibleAgentTitleForOwner } from '../../../../shared/agent-title-owner'
import type { AgentType } from '../../../../shared/agent-status-types'
import {
resolvePaneRendererPolicy,
type RendererPolicyDecision,
type TerminalGpuAccelerationMode
} from './terminal-renderer-policy'
/**
* Owner-aware display label. Wraps the compatible-owner title normalization so
* the display label follows the resolved owner rather than raw wrapper text.
*/
export function resolvePaneDisplayTitle(
title: string,
ownerAgentType: AgentType | null | undefined
): string {
return normalizeCompatibleAgentTitleForOwner(title, ownerAgentType)
}
/**
* The resolved decision for one OSC title frame: a single owner-aware display
* label plus the renderer policy, so `updateTabTitle`, `setRuntimePaneTitle`,
* task-completion tracking, and the GPU gate all consume one interpretation.
*/
export type PaneTitleDecision = {
displayTitle: string
rawTitle: string
rendererPolicy: RendererPolicyDecision
}
export type ResolvePaneTitleDecisionInput = {
/** Normalized title from the transport (may already be display-shaped). */
normalizedTitle: string
rawTitle: string
/** Owner used for the display label — may include sticky/tab-scoped launch
* identity, which is correct for the visible label. */
displayOwnerAgentType: AgentType | null | undefined
/** Owner used for the renderer veto — must be pane-scoped and current so a
* sibling/reused pane's launch identity cannot keep GPU for a genuine
* Gemini pane. */
rendererOwnerAgentType: AgentType | null | undefined
userGpuMode: TerminalGpuAccelerationMode
webglUnavailable?: boolean
inContextLossContainment?: boolean
}
export function resolvePaneTitleDecision(input: ResolvePaneTitleDecisionInput): PaneTitleDecision {
const displayTitle = resolvePaneDisplayTitle(input.normalizedTitle, input.displayOwnerAgentType)
const rendererPolicy = resolvePaneRendererPolicy({
rawTitle: input.rawTitle,
ownerAgentType: input.rendererOwnerAgentType,
userGpuMode: input.userGpuMode,
webglUnavailable: input.webglUnavailable,
inContextLossContainment: input.inContextLossContainment
})
return { displayTitle, rawTitle: input.rawTitle, rendererPolicy }
}