mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
Preserve unopened chat statuses during capacity eviction (#43061)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import type { Tab } from '../../../../../shared/workspace-layout/tab-groups/tab-types'
|
||||
import { structuredAgentSessionPaneKey } from '../../../../../shared/agent-session/view/structured-agent-session-projection'
|
||||
import type { AppState } from '../../types'
|
||||
import type { AgentStatusEntry } from '../../../../../shared/agent-status/contracts/agent-status-types'
|
||||
import type { TerminalPaneLayoutNode } from '../../../../../shared/workspace-layout/terminal-tab-types'
|
||||
@@ -37,11 +39,19 @@ function rootHasLeaf(root: TerminalPaneLayoutNode, leafId: string): boolean {
|
||||
return leaves.has(leafId)
|
||||
}
|
||||
|
||||
// Only exact rooted leaves prove placement; legacy colon-containing owners still match full keys.
|
||||
// Existing chat tabs and exact terminal leaves prove placement without mounting the workspace.
|
||||
export function classifyPaneKeyLiveness(
|
||||
layouts: AppState['terminalLayoutsByTabId']
|
||||
layouts: AppState['terminalLayoutsByTabId'],
|
||||
representedTabs?: Pick<ReadonlyMap<string, Tab>, 'get'>
|
||||
): (paneKey: string) => PaneLiveness {
|
||||
return (paneKey) => {
|
||||
const tab = representedTabs?.get(paneKey)
|
||||
if (
|
||||
tab?.contentType === 'agent-session' &&
|
||||
structuredAgentSessionPaneKey(tab.id, tab.entityId) === paneKey
|
||||
) {
|
||||
return 'live'
|
||||
}
|
||||
for (const tabId of paneKeyCandidateTabIds(paneKey)) {
|
||||
const root = layouts[tabId]?.root
|
||||
if (root && rootHasLeaf(root, paneKey.slice(tabId.length + 1))) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** Regression for #9872: missed pane teardown must not let heavy live status rows grow unbounded. */
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { Tab } from '../../../../../shared/workspace-layout/tab-groups/tab-types'
|
||||
import type { ParsedAgentStatusPayload } from '../../../../../shared/agent-status/contracts/agent-status-types'
|
||||
import { AGENT_STATUS_STALE_AFTER_MS } from '../../../../../shared/agent-status/contracts/agent-status-freshness'
|
||||
import type { SleepingAgentSessionRecord } from '../../../../../shared/agent-session/lifecycle/agent-session-resume'
|
||||
@@ -171,6 +172,46 @@ describe('agentStatusByPaneKey stays bounded (leak regression #9872)', () => {
|
||||
expect(live.get('tab-b:leaf-b')?.state).toBe('blocked')
|
||||
})
|
||||
|
||||
it('keeps an unopened native chat visible when orphan statuses exceed capacity', () => {
|
||||
const store = createTestStore()
|
||||
seedWorktree(store)
|
||||
store.setState({
|
||||
unifiedTabsByWorktree: {
|
||||
'wt-1': [
|
||||
{
|
||||
id: 'chat-tab',
|
||||
entityId: 'chat-session',
|
||||
worktreeId: 'wt-1',
|
||||
contentType: 'agent-session',
|
||||
agentSessionAgent: 'claude',
|
||||
label: 'Chat',
|
||||
customLabel: null,
|
||||
color: null,
|
||||
groupId: 'group-1',
|
||||
sortOrder: 0,
|
||||
createdAt: 1
|
||||
} satisfies Tab
|
||||
]
|
||||
}
|
||||
})
|
||||
setAgentAt(store, 'chat-tab:fa0095aa-0b8f-4e0b-a035-f6c949783135', {
|
||||
state: 'done',
|
||||
prompt: 'Finished',
|
||||
agentType: 'claude'
|
||||
})
|
||||
|
||||
churnFreshUnprovable(store, MAX_LIVE_AGENT_STATUSES + 1)
|
||||
|
||||
expect(
|
||||
store.getState().agentStatusByPaneKey.get('chat-tab:fa0095aa-0b8f-4e0b-a035-f6c949783135')
|
||||
?.state
|
||||
).toBe('done')
|
||||
expect(store.getState().agentStatusByPaneKey.projection.keys('wt-1')).toContain(
|
||||
'chat-tab:fa0095aa-0b8f-4e0b-a035-f6c949783135'
|
||||
)
|
||||
expect(store.getState().agentStatusByPaneKey.get('gone-0:leaf-0')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('bounds the map when fresh unprovable rows dominate, without evicting a live pane', () => {
|
||||
const store = createTestStore()
|
||||
seedWorktree(store)
|
||||
|
||||
@@ -40,7 +40,7 @@ export function projectionEvictionKeys(
|
||||
}
|
||||
drafts.set(statuses, draft)
|
||||
}
|
||||
const classify = classifyPaneKeyLiveness(layouts)
|
||||
const classify = classifyPaneKeyLiveness(layouts, data.represented)
|
||||
for (const [key, row] of statuses.replacementsSince(draft.offset)) {
|
||||
draft.dead.delete(key)
|
||||
draft.fresh.delete(key)
|
||||
|
||||
@@ -76,7 +76,7 @@ export function stageProjectionRows(
|
||||
changedKeys.add(key)
|
||||
}
|
||||
const prepared = new Map<string, PreparedRow>(),
|
||||
classifier = classifyPaneKeyLiveness(state.terminalLayoutsByTabId)
|
||||
classifier = classifyPaneKeyLiveness(state.terminalLayoutsByTabId, represented)
|
||||
for (const key of changedKeys) {
|
||||
const accepted = state.agentStatusByPaneKey.get(key),
|
||||
entry = sourceEntry(key)
|
||||
|
||||
Reference in New Issue
Block a user