Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f284818
fix(sidebar): a slept chat workspace reads asleep and hides
brennanb2025 Oct 18, 2026
86df5e4
fix(sidebar): a wake during Sleep's teardown keeps the workspace awake
brennanb2025 Oct 19, 2026
80921d4
Merge remote-tracking branch 'origin/main' into brennanb2025/slept-ch…
brennanb2025 Oct 19, 2026
00afaa6
test(sidebar): give the activation-race mock store the chat tab map S…
brennanb2025 Oct 19, 2026
274eff8
feat(native-chat): the host marks the chats an explicit Sleep stopped
brennanb2025 Oct 19, 2026
16e6105
refactor(sidebar): read a slept chat from its host's mark, not a wind…
brennanb2025 Oct 19, 2026
34530d0
fix(native-chat): preserve host-owned Sleep across fallback and legac…
brennanb2025 Oct 20, 2026
12bebe9
Merge origin/main and preserve Sleep receipts after provider start se…
brennanb2025 Oct 20, 2026
2fac7c2
fix(native-chat): clear Sleep when a new send is admitted
brennanb2025 Oct 20, 2026
67a8f65
chore: restore incoming documentation after merge hook formatting
brennanb2025 Oct 20, 2026
45b4e11
fix(native-chat): let admitted sends supersede pending Sleep receipts
brennanb2025 Oct 20, 2026
c323afe
fix(sidebar): wait for host Sleep state before showing restored chats
brennanb2025 Oct 20, 2026
c96fca5
fix(sidebar): retain host Sleep answers when chat projections remount
brennanb2025 Oct 20, 2026
aa0bd59
fix(native-chat): clear Sleep when queued drafts become sends
brennanb2025 Oct 20, 2026
13b1b70
test(sidebar): cover unknown and known chat Sleep state on the board
brennanb2025 Oct 20, 2026
fb9dd82
test(vault): expect both host status capability checks
brennanb2025 Oct 20, 2026
7d53c0a
test(native-chat): consolidate Sleep behavior coverage
brennanb2025 Oct 20, 2026
9ff4572
fix(native-chat): commit Sleep wake with send admission
brennanb2025 Oct 20, 2026
df2281e
test: pin visibility while chat host is unidentified
brennanb2025 Oct 20, 2026
3963fbd
Merge origin/main into slept chat workspace visibility
brennanb2025 Oct 20, 2026
75fdf27
test: consolidate workspace sleep regression flows
brennanb2025 Oct 20, 2026
85c308e
Merge main and preserve chat Sleep status with naming updates
brennanb2025 Oct 21, 2026
cbb493e
test: keep status feed regression within renderer boundary
brennanb2025 Oct 21, 2026
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 @@ -261,6 +261,7 @@ describe('workspace session field disposition census', () => {
'activeGroupIdByWorktree',
'lastVisitedAtByWorktreeId',
'defaultTerminalTabsAppliedByWorktreeId',
'explicitlySleptChatsByWorkspace',
'terminalTopologyRevisionByRepoId'
])
})
Expand All @@ -275,6 +276,7 @@ describe('workspace session field disposition census', () => {
'activeGroupIdByWorktree',
'lastVisitedAtByWorktreeId',
'defaultTerminalTabsAppliedByWorktreeId',
'explicitlySleptChatsByWorkspace',
'terminalTopologyRevisionByRepoId'
])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export const WORKSPACE_SESSION_FIELD_DISPOSITION = {
// the record's worktreeId on worktree and project removal. Moving a project between profiles runs
// removeSourceRepo, which has no owner scan, so these records leak there.
sleepingAgentSessionsByPaneKey: { onRepoRemoval: 'notRepoScoped', onTransfer: 'notTransferred' },
explicitlySleptChatsByWorkspace: {
onRepoRemoval: 'prunedByOwnerKey',
onTransfer: 'copiedByOwnerKey'
},
terminalPtyIncarnationsByPaneKey: {
onRepoRemoval: 'prunedByBespokeRule',
onTransfer: 'copiedByBespokeRule'
Expand Down
56 changes: 56 additions & 0 deletions src/main/orca-profiles/profile-project-session-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,69 @@ import {
removeRepoFromWorkspaceSession
} from './profile-project-session-state'
import { extractSessionForTransfer } from './profile-project-session-transfer'
import { isChatExplicitlySlept, sleptChatWorkspaceKey } from '../../shared/workspace-chat-sleep'

const REMOVED_WORKTREE_ID = 'repo-a::/removed'
const RETAINED_WORKTREE_ID = 'repo-b::/retained'
const REMOVED_REPO_ID = 'repo-a'
const RETAINED_REPO_ID = 'repo-b'

describe('profile project session state', () => {
it('keeps exact chat Sleep choices when a moved project needs a new repo id', () => {
const movedWorktreeId = 'repo-c::/removed'
const retainedKey = sleptChatWorkspaceKey(RETAINED_WORKTREE_ID, 'local')
const localKey = sleptChatWorkspaceKey(movedWorktreeId, 'local')
const remoteKey = sleptChatWorkspaceKey(movedWorktreeId, 'ssh:profile-test')
const tabs = (['local', 'ssh:profile-test'] as const).map((executionHostId, sortOrder) => ({
id: `chat-${sortOrder}`,
entityId: `session-${sortOrder}`,
groupId: 'group',
worktreeId: REMOVED_WORKTREE_ID,
executionHostId,
contentType: 'agent-session' as const,
label: 'Chat',
customLabel: null,
color: null,
sortOrder,
createdAt: 1
}))
const source: WorkspaceSessionState = {
...getDefaultWorkspaceSession(),
unifiedTabs: { [REMOVED_WORKTREE_ID]: tabs },
explicitlySleptChatsByWorkspace: Object.fromEntries(
tabs.map((tab) => [
sleptChatWorkspaceKey(REMOVED_WORKTREE_ID, tab.executionHostId),
[{ tabId: tab.id, sessionId: tab.entityId }]
])
)
}
const retained = [{ tabId: 'retained-chat', sessionId: 'retained-session' }]
const target = {
...getDefaultWorkspaceSession(),
explicitlySleptChatsByWorkspace: {
[retainedKey]: retained,
[localKey]: [{ tabId: 'old-chat', sessionId: 'old-session' }]
}
}
const result = mergeWorkspaceSessions(
target,
extractSessionForTransfer(source, REMOVED_REPO_ID, 'repo-c')
)

expect(result.explicitlySleptChatsByWorkspace).toEqual({
[retainedKey]: retained,
[localKey]: [{ tabId: 'chat-0', sessionId: 'session-0' }],
[remoteKey]: [{ tabId: 'chat-1', sessionId: 'session-1' }]
})
const movedTabs = result.unifiedTabs?.[movedWorktreeId] ?? []
expect(movedTabs).toHaveLength(2)
expect(
movedTabs.every((tab) =>
isChatExplicitlySlept(result.explicitlySleptChatsByWorkspace ?? {}, tab)
)
).toBe(true)
})

it('keeps topology revisions monotonic while merging session authority records', () => {
const base = {
...getDefaultWorkspaceSession(),
Expand Down
8 changes: 8 additions & 0 deletions src/main/orca-profiles/profile-project-session-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ export function mergeWorkspaceSessions(
}
}
: {}),
...(base.explicitlySleptChatsByWorkspace || incoming.explicitlySleptChatsByWorkspace
? {
explicitlySleptChatsByWorkspace: {
...base.explicitlySleptChatsByWorkspace,
...incoming.explicitlySleptChatsByWorkspace
}
}
: {}),
activeWorktreeIdsOnShutdown: [
...(base.activeWorktreeIdsOnShutdown ?? []),
...(incoming.activeWorktreeIdsOnShutdown ?? [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,13 @@ describe('migrating saved state from released SSH clients', () => {
const { state, local, host } = split()
host.lastVisitedAtByWorktreeId = { [WORKTREE]: 5 }
local.tabsByWorktree = { [WORKTREE]: [terminal('local')] }
local.explicitlySleptChatsByWorkspace = {
[`${HOST}|${WORKTREE}`]: [{ tabId: 'chat', sessionId: 'session' }]
}
expect(census(state).totalCount).toBe(0)
const session = exportState(state).payload.dormantState?.workspaceSession
expect(session?.tabsByWorktree[WORKTREE]?.map((tab) => tab.id)).toEqual(['local'])
expect(session).not.toHaveProperty('explicitlySleptChatsByWorkspace')
})

it('exports local tabs and drafts beside a host-only closed-pane resume record', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ function collectWorkspaceSession(
}
: null
})
// Sleep intent belongs to the client that recorded it.
delete fragment.explicitlySleptChatsByWorkspace
if (!sourceHostPartition) {
// Client focus is not host state, so the destination never carries it.
fragment.activeWorktreeId = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@ describe('deleting a workspace owner session fields', () => {
])
})

// Why not in the list above: this map also holds host-qualified keys, so it is scanned rather
// Why not in the list above: these maps also hold host-qualified keys, so they are scanned rather
// than indexed by the owner key, and the scan is the only thing that reaches a remote row.
it('deletes the recency entry under a bare and a host-qualified key alike', () => {
it('deletes recency and explicit chat Sleep entries under bare and host-qualified keys alike', () => {
const slept = [{ tabId: 'chat-1', sessionId: 'session-1' }]
const session: WorkspaceSessionState = {
...getDefaultWorkspaceSession(),
lastVisitedAtByWorktreeId: {
[REMOVED_OWNER_KEY]: 1,
[`ssh:user@host|${REMOVED_OWNER_KEY}`]: 2,
[RETAINED_OWNER_KEY]: 3,
[`ssh:user@host|${RETAINED_OWNER_KEY}`]: 4
},
explicitlySleptChatsByWorkspace: {
[`local|${REMOVED_OWNER_KEY}`]: slept,
[`ssh:user@host|${REMOVED_OWNER_KEY}`]: slept,
[`local|${RETAINED_OWNER_KEY}`]: slept
}
}

Expand All @@ -82,5 +88,8 @@ describe('deleting a workspace owner session fields', () => {
[RETAINED_OWNER_KEY]: 3,
[`ssh:user@host|${RETAINED_OWNER_KEY}`]: 4
})
expect(session.explicitlySleptChatsByWorkspace).toEqual({
[`local|${RETAINED_OWNER_KEY}`]: slept
})
})
})
26 changes: 17 additions & 9 deletions src/main/persistence/restoring-sessions/session-owner-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ import {
} from '../../../shared/worktree/host-qualified-identity'
import { SESSION_FIELDS_PRUNED_BY_OWNER_KEY } from '../../orca-profiles/profile-project-session-field-disposition'

// Keyed by `${executionHostId}|${worktreeId}` as well as the bare owner key.
const HOST_QUALIFIED_SESSION_FIELDS = [
'lastVisitedAtByWorktreeId',
'explicitlySleptChatsByWorkspace'
] as const

/**
* The census fields this path deletes by indexing the owner key.
*
* Two classified fields are handled separately below: the topology revision is keyed by repo
* rather than by owner, so removing one owner advances it instead of dropping it; and the recency
* map also holds host-qualified keys, so it is scanned rather than indexed.
* Some classified fields are handled separately below: the topology revision is keyed by repo
* rather than by owner, so removing one owner advances it instead of dropping it; and the
* host-qualified maps are scanned rather than indexed.
*/
export const OWNER_KEYED_SESSION_FIELDS_DELETED_WITH_THEIR_OWNER =
SESSION_FIELDS_PRUNED_BY_OWNER_KEY.filter(
(field) => field !== 'terminalTopologyRevisionByRepoId' && field !== 'lastVisitedAtByWorktreeId'
(field) =>
field !== 'terminalTopologyRevisionByRepoId' &&
!HOST_QUALIFIED_SESSION_FIELDS.some((hostQualified) => hostQualified === field)
)

export function createMinimalPersistedTerminalTab(args: {
Expand Down Expand Up @@ -89,12 +97,12 @@ export function deleteOwnerKeyedSessionFields(
delete record[ownerKey]
}
}
// Scanned, not indexed: this map also holds `${executionHostId}|${worktreeId}` keys.
if (next.lastVisitedAtByWorktreeId) {
for (const key of Object.keys(next.lastVisitedAtByWorktreeId)) {
for (const field of HOST_QUALIFIED_SESSION_FIELDS) {
const record: Record<string, unknown> | undefined = next[field]
for (const key of Object.keys(record ?? {})) {
const rawId = isWorktreeHostIdentity(key) ? getWorktreeIdFromHostIdentity(key) : key
if (key === ownerKey || rawId === ownerKey) {
delete next.lastVisitedAtByWorktreeId[key]
if (record && (key === ownerKey || rawId === ownerKey)) {
delete record[key]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export const WORKSPACE_SESSION_WORKTREE_REFERENCE_KIND = {
lastVisitedAtByWorktreeId: 'owner-keyed',
defaultTerminalTabsAppliedByWorktreeId: 'owner-keyed',
sleepingAgentSessionsByPaneKey: 'row-record',
// A remembered Sleep is a view choice, not evidence that a checkout still exists.
explicitlySleptChatsByWorkspace: 'none',
terminalPtyIncarnationsByPaneKey: 'none',
terminalTopologyRevisionByRepoId: 'none',
terminalSurfaceTombstonesByPaneKey: 'row-record',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ const referencingFields = Object.keys(WORKSPACE_SESSION_WORKTREE_REFERENCE_KIND)
.sort()

describe('migrateWorktreeIdentity worktree-reference coverage', () => {
it('rekeys view-only Sleep intent without treating it as checkout ownership', () => {
const session: WorkspaceSessionState = {
...getDefaultWorkspaceSession(),
explicitlySleptChatsByWorkspace: {
[`local|${OLD}`]: [{ tabId: 'chat', sessionId: 'session' }]
}
}
expect([...collectWorkspaceSessionWorktreeOwners(session, CANDIDATES)]).toEqual([])

expect(migrateWorktreeIdentity(persistedState(session), OLD, NEW)).toBe(true)
expect(session.explicitlySleptChatsByWorkspace).toEqual({
[`local|${NEW}`]: [{ tabId: 'chat', sessionId: 'session' }]
})
})

it('has a fixture for every field the ownership census says can name a worktree', () => {
const missing = referencingFields.filter((field) => !REFERENCE_FIXTURES[field])
expect(missing).toEqual([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
isWorktreeHostIdentity
} from '../../../shared/worktree/host-qualified-identity'
import { splitWorktreeIdForFilesystem } from '../../../shared/worktree/id'
import { renameSleptChatWorkspaceInSession } from '../../../shared/workspace-chat-sleep'

type WorktreeNamingRow = { worktreeId: string }

Expand Down Expand Up @@ -189,6 +190,8 @@ export function migrateWorktreeIdentity(
moveSessionKey(session.tabGroups, (groups) => groups.map(withNewWorktreeId)) || sessionChanged
sessionChanged = moveSessionKey(session.tabGroupLayouts) || sessionChanged
sessionChanged = moveSessionKey(session.activeGroupIdByWorktree) || sessionChanged
sessionChanged =
renameSleptChatWorkspaceInSession(session, oldWorktreeId, newWorktreeId) || sessionChanged
if (session.lastVisitedAtByWorktreeId) {
const nextRecency = { ...session.lastVisitedAtByWorktreeId }
let recencyChanged = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ describe('StructuredAgentSessionStatusBridge', () => {
expect(statuses()[0]).not.toHaveProperty('structuredHostOwned')
})

it('clears a marked chat when the first confirmed live summary is still working', async () => {
mocks.store?.setState({
unifiedTabsByWorktree: { 'wt-1': [{ ...structuredTab, executionHostId: 'local' }] },
explicitlySleptChatsByWorkspace: {
'local|wt-1': [{ tabId: structuredTab.id, sessionId: structuredTab.entityId }]
}
})
render(<StructuredAgentSessionStatusBridge />)
await waitFor(() => expect(mocks.subscribeStatus).toHaveBeenCalledOnce())
act(() => feed().emit({ type: 'snapshot', sessions: [summary()] }))
expect(mocks.store?.getState().explicitlySleptChatsByWorkspace['local|wt-1']).toBeUndefined()
})

it('maps each host status onto the sidebar agent state', async () => {
render(<StructuredAgentSessionStatusBridge />)
await waitFor(() => expect(mocks.subscribeStatus).toHaveBeenCalledOnce())
Expand Down Expand Up @@ -651,9 +664,12 @@ describe('StructuredAgentSessionStatusBridge', () => {
expect(mocks.setAgentStatus).toHaveBeenCalledTimes(calls)
})

it('keeps the host-fed chat row through Sleep and stops offering Sleep once the host lets go', async () => {
it('keeps the host-fed chat row through Sleep and offers Sleep until the chat is recorded slept', async () => {
const state = (): AppState => useAppStore.getState()
const sleepable = (): boolean => hasSleepableWorkspaceActivity('wt-1', state())
mocks.store?.setState({
unifiedTabsByWorktree: { 'wt-1': [{ ...structuredTab, executionHostId: 'local' }] }
})
render(<StructuredAgentSessionStatusBridge />)
await waitFor(() => expect(mocks.subscribeStatus).toHaveBeenCalledOnce())
act(() => feed().emit({ type: 'status', session: summary({ status: 'idle', updatedAt: 2 }) }))
Expand All @@ -675,7 +691,16 @@ describe('StructuredAgentSessionStatusBridge', () => {
expect(statuses()).toEqual([expect.objectContaining({ state: 'done' })])
expect(statuses()[0].structuredHostOwned).toBeUndefined()
expect(state().acknowledgedAgentsByPaneKey).toEqual({ [paneKey]: 3 })
// The host let go; only the explicit Sleep's record stops offering Sleep, and new work clears it.
expect(sleepable()).toBe(true)
const chat = { tabId: structuredTab.id, sessionId: structuredTab.entityId }
act(() => state().markWorkspaceChatsSlept('wt-1', 'local', [chat]))
expect(sleepable()).toBe(false)
act(() => feed().emit({ type: 'status', session: summary({ updatedAt: 3 }) }))
expect(state().explicitlySleptChatsByWorkspace['local|wt-1']).toBeUndefined()
// Work reported before the Sleep flow records the chat still wakes it.
act(() => state().markWorkspaceChatsSlept('wt-1', 'local', [chat]))
expect(state().explicitlySleptChatsByWorkspace['local|wt-1']).toBeUndefined()
})

it('drops the status and the feed when the last structured tab closes', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../../../../shared/agent-status-types'
import { structuredChildWorkLegacySubagents } from '../../../../shared/structured-agent-session-child-work-legacy'
import { structuredAgentSessionPaneKey } from '../../../../shared/structured-agent-session-projection'
import { isChatExplicitlySlept } from '../../../../shared/workspace-chat-sleep'
import { structuredAgentSessionAgentStatus } from '../../../../shared/structured-agent-session-agent-status'
import {
structuredAgentSessionDatedMainAgent,
Expand Down Expand Up @@ -328,6 +329,23 @@ function StructuredAgentSessionOwnedStatusProjection({
target: RuntimeClientTarget
}): null {
const { summary, observation } = useStructuredAgentSessionStatusSummary(tab.entityId, target)
const { id: tabId, entityId: sessionId, executionHostId, worktreeId } = tab
// Why: a send after Sleep's host stop can report working before the flow records the chat slept.
const slept = useAppStore((state) =>
isChatExplicitlySlept(state.explicitlySleptChatsByWorkspace, tab)
)
useEffect(() => {
if (!slept || observation !== 'live' || summary?.status !== 'working') {
return
}
const store = useAppStore.getState()
if (executionHostId) {
store.clearWorkspaceChatsSlept(worktreeId, {
hostId: executionHostId,
chats: [{ tabId, sessionId }]
})
}
}, [slept, summary, observation, tabId, sessionId, executionHostId, worktreeId])
const launchFailed =
useStructuredAgentSessionLaunchLifecycle(tab.worktreeId, tab.entityId) === 'failed'
const failedAt = useStructuredAgentSessionLaunchFailedAt(tab.entityId)
Expand Down
Loading