Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
30756cb
fix: gate startup agent recovery on host inventory
nwparker Sep 14, 2026
b34925c
fix: defer recovery while a live agent lacks conversation ownership
nwparker Sep 14, 2026
e53f155
fix(mobile): two known main bugs the RPC migration preserved (#20563)
Jinwoo-H Sep 14, 2026
50e752f
test(mobile): pin each RPC golden to its own scenario input, not the …
Jinwoo-H Sep 14, 2026
a4c11f1
fix(native-chat): stop a bounded tail read from moving the chat curso…
brennanb2025 Sep 14, 2026
fc525c3
refactor(mobile): send the task workspace-creation domain through typ…
Jinwoo-H Sep 14, 2026
eba56f2
feat(ai-vault-search): construct the session search indexer in the sc…
Jinwoo-H Sep 14, 2026
c6a7216
fix(native-chat): hide activity while awaiting input (#20496)
brennanb2025 Sep 14, 2026
875b86d
Update README downloads badge
github-actions[bot] Sep 14, 2026
1d1bca2
Bump mobile app.json to 0.0.50 (#20661)
brennanb2025 Sep 14, 2026
b4d4358
fix(native-chat): bound a dispatch reason before it reaches the journ…
brennanb2025 Sep 14, 2026
d8b6151
fix(native-chat): keep a resumed transcript pinned to its end (#20651)
brennanb2025 Sep 14, 2026
2acd2f4
Surface stage, unstage and discard failures with retry capability (#2…
AmethystLiang Sep 14, 2026
d5be0d6
Add copy button to code blocks (#20357)
AmethystLiang Sep 14, 2026
6c70801
fix(source-control): prevent text wrapping in section headers and act…
AmethystLiang Sep 14, 2026
2186a88
fix(store): stop two no-op writes from re-running every selector in t…
OrcaWin Sep 14, 2026
c3372ae
fix(ai-vault): bound streamed remote JSONL records (#20700)
nwparker Sep 14, 2026
1ba9801
fix(ci): stop hourly versions dropping below a tagged or already-ship…
nwparker Sep 14, 2026
dede24d
fix(store): preserve state identity for no-op updater branches (#20703)
nwparker Sep 14, 2026
955051d
fix(codex): settle a structured send on admission, and stop minting a…
brennanb2025 Sep 14, 2026
59d29af
test: add a verified OMP native-chat mock scenario (#20655)
nwparker Sep 14, 2026
3632311
fix(omp): preserve status after terminal title owner rewrite (#20610)
nwparker Sep 14, 2026
fc4519c
fix(omp): preserve zsh startup with global aliases (#20621)
nwparker Sep 14, 2026
ee1a0a4
fix(git): avoid Windows tree kills after the command has exited (#20606)
nwparker Sep 14, 2026
8d93505
fix(terminal): retain renames before renderer pane hydration (#20619)
nwparker Sep 14, 2026
f21f81d
fix(agents): find OMP by its full project name (#20647)
nwparker Sep 14, 2026
68f0b2e
feat(runtime): stream file uploads instead of buffering whole files (…
mmarabel Sep 14, 2026
389d672
fix(omp): preserve saved conversation names in session history (#20636)
nwparker Sep 14, 2026
46eb595
fix(ui): contain idle caret paint so agent panes stop burning CPU (#1…
innocarpe Sep 14, 2026
d51747e
feat(relay): expose preloaded PostgreSQL statement statistics (#20712)
Jinwoo-H Sep 14, 2026
49fba59
fix(runtime): apply the tui-idle evidence ranking to mailbox delivery…
nwparker Sep 14, 2026
4a02762
fix(agent-session): honour the backup-recovery fence floor on surface…
brennanb2025 Sep 14, 2026
bac96b2
fix(hooks): actually terminate a timed-out hook's process tree (#20576)
nwparker Sep 14, 2026
41e42be
fix(worktrees): safely remove prunable git-file registrations (#20617)
nwparker Sep 14, 2026
dd85e5f
fix: keep OMP terminals when folder workspaces become Git repos (#20653)
nwparker Sep 14, 2026
f55b7ba
fix(native-chat): cancel pending prompts precisely (#20601)
brennanb2025 Sep 14, 2026
742a7ad
fix(omp): resume independent child sessions from history (#20629)
nwparker Sep 14, 2026
767b7c1
fix(ai-vault): expand nested OMP session history (#20663)
nwparker Sep 14, 2026
b8554f1
fix(composer): clarify failed attachment drops (#20704)
AmethystLiang Sep 14, 2026
6cb5643
fix(deps): migrate Tiptap security updates with Markdown compatibilit…
OrcaWin Sep 14, 2026
4bcdc67
Distinguish pane load failures from empty states (#20735)
AmethystLiang Sep 14, 2026
b07c403
Log bounded PostgreSQL acquisition and execution failure diagnostics …
Jinwoo-H Sep 15, 2026
6a11a0b
test(mobile): pin each RPC golden to the recorder inputs that can rea…
Jinwoo-H Sep 15, 2026
ffc3312
Fix PTY child process verdict to preserve unverifiable state (#20729)
AmethystLiang Sep 15, 2026
20794ee
ci: keep the baseline build off the compatibility matrix lanes (#20733)
nwparker Sep 15, 2026
2b34255
fix(ci): stop defining pilot mutant tests inside a conditional (#20755)
nwparker Sep 15, 2026
db09a7b
fix(native-chat): let a reader park just above the latest message (#2…
brennanb2025 Sep 15, 2026
b61a234
feat(design-system): gate renderer UI with @shadcn/lint (#20731)
nwparker Sep 15, 2026
6f4e4bf
Update README downloads badge
github-actions[bot] Sep 15, 2026
ff5b1a5
fix(native-chat): preserve detached transcript position during growth…
brennanb2025 Sep 15, 2026
438603f
feat(native-chat): add a message rail for jumping between your prompt…
brennanb2025 Sep 15, 2026
99062ed
fix(worktrees): preserve unverifiable disk witness (#20713)
AmethystLiang Sep 15, 2026
ef39f32
test(native-chat): split the windowing test harness out of the suite …
nwparker Sep 15, 2026
11180fa
chore(lint): add anti-slop oxlint plugin (pinned, all rules off) (#20…
nwparker Sep 15, 2026
b792065
chore(lint): enable anti-slop no-reduce-accumulator-copy and no-widen…
nwparker Sep 15, 2026
4a5b058
fix(runtime): keep listed handles when graph sync learns a PTY incarn…
nwparker Sep 15, 2026
ab6b86d
fix(orchestration): require registered structured worker pane key (#2…
brennanb2025 Sep 15, 2026
bbd808a
fix(lint): keep root postinstall as the sole Electron binary install …
nwparker Sep 15, 2026
cf19735
Update README downloads badge
github-actions[bot] Sep 15, 2026
18d0afc
test(package): let the postinstall contract allow unrelated chained s…
nwparker Sep 15, 2026
3ec6193
fix(pty): preserve child-process inspection uncertainty (#20756)
AmethystLiang Sep 15, 2026
c9ae17f
fix(lint): enable anti-slop/no-unknown-type-aliases (#20784)
nwparker Sep 15, 2026
49e5fa5
refactor(lint): enable anti-slop/no-reflect-apply (#20782)
nwparker Sep 15, 2026
775a932
fix(git): distinguish binary absence from missing cwd on spawn ENOENT…
AmethystLiang Sep 15, 2026
22ce8d6
fix(lint): enable anti-slop/no-module-mocking (#20783)
nwparker Sep 15, 2026
0569ca4
Improve microphone permission errors and drop failure reporting (#20801)
AmethystLiang Sep 15, 2026
6fe140d
Report clipboard and composer drop failures (#20795)
AmethystLiang Sep 15, 2026
37a5b27
test(package): reject an Electron install takeover by exact command (…
nwparker Sep 15, 2026
f7b2736
fix(worktree): block removal when the archive hook fails (#20153)
nwparker Sep 15, 2026
f107499
fix(lint): enable anti-slop/no-reflect-get (#20786)
nwparker Sep 15, 2026
c0fb04c
fix(relay): open the real null device when detaching Windows stdio (#…
nwparker Sep 15, 2026
37394e9
build(release): compile the Windows relay process-table addon (#20809)
nwparker Sep 15, 2026
e4a9d24
fix(automations): repair cron step expansion and day restriction (#20…
nwparker Sep 15, 2026
bfdec26
fix(lint): enable anti-slop/no-object-parameters (#20781)
nwparker Sep 15, 2026
231e805
fix(lint): enable anti-slop/no-shape-in-symbol-names (#20785)
nwparker Sep 15, 2026
caa465d
fix(automations): stop tick latency counting against the missed-run g…
nwparker Sep 15, 2026
36ef93a
refactor(mobile): migrate the small domains onto RpcOperation (step 4…
Jinwoo-H Sep 15, 2026
9ab0a18
refactor(agent-status): isolate legacy status ingress behind one admi…
brennanb2025 Sep 15, 2026
f742ab8
Update README downloads badge
github-actions[bot] Sep 15, 2026
44268d9
refactor(mobile): send the github.* PR surface and the diff-review lo…
Jinwoo-H Sep 15, 2026
9878482
refactor(mobile): send the transport pairing and status domain throug…
Jinwoo-H Sep 15, 2026
2dfdbc8
refactor(mobile): send the task provider, detail and board domains th…
Jinwoo-H Sep 15, 2026
d130347
refactor(mobile): send the dictation, terminal, notification and brow…
Jinwoo-H Sep 15, 2026
62c5037
fix(lint): avoid reflective status entry reads (#20872)
Jinwoo-H Sep 15, 2026
2eb9320
refactor(agent-launch): make the launch-mode decision surface-neutral…
brennanb2025 Sep 15, 2026
22857cd
fix(crash-reporting): stop periodic emitters from evicting the crash …
OrcaWin Sep 15, 2026
60d7939
fix(native-chat): replace the raw question tool row with an awaiting-…
brennanb2025 Sep 15, 2026
6c03bb6
fix(lint): replace Reflect.get with typed property access in mounting…
brennanb2025 Sep 15, 2026
22ca862
test(native-chat): widen real-timer waitFor budget in agent-session-w…
brennanb2025 Sep 15, 2026
e7206f6
fix(mobile): retire a structured operation id the host has refused (#…
brennanb2025 Sep 15, 2026
783d8fe
fix(lint): merge duplicate type imports in the mobile RPC recorder ad…
Jinwoo-H Sep 15, 2026
1457d39
fix(native-chat): release sessions after provider root exit (#20502)
brennanb2025 Sep 15, 2026
0056161
test(mobile): record the real worktree catalog snapshot result in the…
Jinwoo-H Sep 15, 2026
2fccaca
test(mobile): mount screens, declared device stores and declared OS s…
Jinwoo-H Sep 15, 2026
981a482
fix(cli,relay): stop reading an unsignalable pid as a dead one (+ unv…
nwparker Sep 15, 2026
72a8c09
fix(ssh): corroborate an empty lsof answer before calling an endpoint…
nwparker Sep 15, 2026
946dacc
fix(worktrees): route unstamped local worktrees local in the two stat…
LesleyMurfin Sep 15, 2026
8edec28
fix(worktree): keep a WSL checkout case so delete cannot take the twi…
nwparker Sep 15, 2026
52b6851
fix(worktree-create): prioritize creation Git and defer background pr…
Jinwoo-H Sep 15, 2026
0325f1a
feat(agent-status): add the canonical store and child-work contract (…
brennanb2025 Sep 15, 2026
0869d99
refactor(mobile): send the rest of the session domain through typed R…
Jinwoo-H Sep 15, 2026
b5a9946
fix(e2e): fabricate runtime-host health through the snapshot that own…
brennanb2025 Sep 15, 2026
13ba649
fix(terminal): let a runtime-created Windows terminal BE the requeste…
nwparker Sep 15, 2026
6da7238
feat(agent-launch): one executor for agent launches, exposed as agent…
brennanb2025 Sep 15, 2026
a9232e8
fix(claude): single-own turn identity so Stop reaches a provider-open…
brennanb2025 Sep 15, 2026
3520e8e
fix: highlight bash fences in Markdown source mode (#20592)
100space Sep 16, 2026
7ec2986
fix(lint): merge the duplicate agent-status contract type imports (#2…
brennanb2025 Sep 16, 2026
ea7902c
refactor(mobile): send the device-state holdouts through typed RpcOpe…
Jinwoo-H Sep 16, 2026
615b137
refactor(mobile): own the request/cache lifecycle in GenerationScoped…
Jinwoo-H Sep 16, 2026
b8d4cde
refactor(mobile): send six screen-mounted call sites through typed Rp…
Jinwoo-H Sep 16, 2026
d4c19d5
test(mobile): let the RPC recorder open a subscription and script its…
Jinwoo-H Sep 16, 2026
c33a446
feat(mobile): clarify the notification opt-in screen (#20930)
Jinwoo-H Sep 16, 2026
07c7606
fix(computer-use): reap detached macOS helpers through owner exit (#2…
nwparker Sep 16, 2026
7f23d44
refactor(daemon): consolidate snapshot-safe listener delivery (#20945)
nwparker Sep 16, 2026
e6a4108
fix: name the id-kind mismatch when --ack is given a message id (#15743)
kaluli123123 Sep 16, 2026
357c978
refactor(agent-launch): retire the duplicate worker-start mode decisi…
brennanb2025 Sep 16, 2026
96d77b3
perf: always show project names and remove notification scans (#20931)
Jinwoo-H Sep 16, 2026
47bb473
Remove agent map from dashboard popout (#20929)
AmethystLiang Sep 16, 2026
9ed561c
fix(claude): judge Stop against the turn the journal published (#20921)
brennanb2025 Sep 16, 2026
bfc297d
fix(settings): keep integration connect dialog drafts on backdrop cli…
AmethystLiang Sep 16, 2026
b0d46e2
fix(settings): preserve multiline proxy bypass rules (#20957)
AmethystLiang Sep 16, 2026
feb04ec
Virtualize automations run history table for large histories (#20916)
AmethystLiang Sep 16, 2026
4948afc
fix(linear): show 'Cannot verify' when skill scan is inconclusive (#2…
AmethystLiang Sep 16, 2026
f78483e
refactor(mobile): send the subscription-gated holdouts through typed …
Jinwoo-H Sep 16, 2026
c702e77
Stop reading the terminal arguments field on the structured chat rout…
brennanb2025 Sep 16, 2026
16ac901
docs: remove unavailable diff shortcuts (#20974)
OrcaWin Sep 16, 2026
e39b432
fix(editor): preserve Markdown scroll after image layout (#20956)
nwparker Sep 16, 2026
7860933
Fix browser viewport presets incorrectly scaled by UI zoom (#20962)
AmethystLiang Sep 16, 2026
d62328a
fix(codex): remove redundant Windows hook launcher for Unicode profil…
nwparker Sep 16, 2026
07b7687
fix(sidebar): keep the Projects filter when a project is added (#20987)
OrcaWin Sep 16, 2026
15cac68
Native chat keeps scrolling to bottom (#20898)
AmethystLiang Sep 16, 2026
406d71f
fix: keep activation inventory on its execution host
nwparker Sep 16, 2026
3b03739
Merge 406d71f369b01c872a9e998d1b00557ccd578126 into 15cac68802361f3b9…
nwparker Sep 16, 2026
6d42f2f
test: remove obsolete message type import after main integration
nwparker Sep 16, 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 @@ -3,15 +3,16 @@ import { act } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { useTerminalWatcherEffects } from '../use-terminal-watcher-effects'
import type { TerminalColdActivationController } from '../terminal-cold-activation'

const mocks = vi.hoisted(() => ({
gate: vi.fn(),
resume: vi.fn(),
authority: 'none',
launchStatus: vi.fn((_worktreeId: string, _provider: string): string => 'idle'),
createTab: vi.fn()
}))
vi.mock('@/store', () => ({
useAppStore: Object.assign(() => 'none', {
useAppStore: Object.assign(() => mocks.authority, {
getState: () => ({ activeWorktreeId: 'wt-1' })
})
}))
Expand All @@ -22,7 +23,7 @@ vi.mock('@/lib/structured-agent-session-launch', () => ({
getStructuredAgentLaunchStatus: mocks.launchStatus
}))
vi.mock('@/lib/resume-sleeping-agent-session', () => ({
resumeSleepingAgentSessionsForWorktree: vi.fn()
resumeSleepingAgentSessionsForWorktree: mocks.resume
}))
vi.mock('@/lib/workspace-terminal-host-authority', () => ({
createWorkspaceTerminalHostAuthoritySelector: () => () => 'none'
Expand All @@ -34,23 +35,48 @@ vi.mock('../terminal-pane/terminal-parked-tab-watchers', () => ({
disposeAllParkedTerminalWatchers: vi.fn()
}))

;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
let root: Root | undefined
afterEach(async () => {
await act(async () => root?.unmount())
vi.clearAllMocks()
mocks.authority = 'none'
})

function Watcher(): null {
function Watcher({ restored = true, hydrated = false, worktreeId = 'wt-1' } = {}): null {
useTerminalWatcherEffects({
activeWorktreeId: 'wt-1',
activeWorktreeId: worktreeId,
workspaceSessionReady: true,
terminalStartupRestorationReady: true,
terminalStartupRestorationReady: restored,
hydrationSucceeded: hydrated,
workspaceSurfaceIds: [],
tabsByWorktree: {},
createTab: mocks.createTab,
reconcileWorktreeTabModel: () => ({ renderableTabCount: 0 })
} as unknown as TerminalColdActivationController)
reconcileWorktreeTabModel: () => ({
renderableTabCount: 0,
activeRenderableTabId: null
}),
activationDeferredMountTabIdsByWorktreeRef: { current: new Map() },
activeTabId: null,
activeTabIdByWorktree: {},
activeView: 'terminal',
activityTerminalPortals: [],
anyMountedWorktreeHasLayout: false,
backgroundMountRevision: 0,
effectiveParkedTerminalWorktreeIds: new Set(),
evictionExemptTerminalTabIds: new Set(),
getEffectiveLayoutForWorktree: () => undefined,
groupsByWorktree: {},
measurableBackgroundWorktreeIdsRef: { current: new Set() },
mountedWorktreeIdsRef: { current: new Set() },
pairedRuntimeParkingEnvironmentIds: new Set(),
pendingStartupByTabId: {},
renderedActiveWorktreeId: worktreeId,
terminalParkingEnabled: false,
terminalProviderSnapshotCapabilityRevision: 0,
terminalSshParkingEnabled: false,
terminalTitleSnapshotAuthorityEnabled: false
})
return null
}

Expand Down Expand Up @@ -81,3 +107,51 @@ describe('passive terminal seeding during native chat creation', () => {
expect(mocks.createTab).toHaveBeenCalledTimes(expectedTabs)
})
})

describe('startup agent recovery host inventory', () => {
it('keeps recovery available until the execution host answers', async () => {
mocks.authority = 'unverifiable'
mocks.gate.mockResolvedValue('adopted')
root = createRoot(document.createElement('div'))
await act(async () => root?.render(<Watcher hydrated />))
expect(mocks.gate).not.toHaveBeenCalled()
expect(mocks.resume).not.toHaveBeenCalled()
mocks.authority = 'live'
await act(async () => root?.render(<Watcher hydrated />))
expect(mocks.gate).toHaveBeenCalledTimes(1)
await act(async () => root?.render(<Watcher hydrated />))
expect(mocks.gate).toHaveBeenCalledTimes(1)
})

it('waits for terminal restoration, then uses the activation gate', async () => {
mocks.authority = 'live'
mocks.gate.mockResolvedValue('adopted')
root = createRoot(document.createElement('div'))
await act(async () => root?.render(<Watcher hydrated restored={false} />))
expect(mocks.resume).not.toHaveBeenCalled()
expect(mocks.gate).not.toHaveBeenCalled()
await act(async () => root?.render(<Watcher hydrated />))
expect(mocks.gate).toHaveBeenCalledWith('wt-1')
expect(mocks.resume).not.toHaveBeenCalled()
})

it.each(['blocked', 'rejected'])(
'retries a %s startup after leaving and returning',
async (outcome) => {
mocks.authority = 'live'
if (outcome === 'rejected') {
mocks.gate.mockRejectedValue(new Error('host unavailable'))
} else {
mocks.gate.mockResolvedValue('blocked')
}
root = createRoot(document.createElement('div'))
await act(async () => root?.render(<Watcher hydrated />))
expect(mocks.gate).toHaveBeenCalledTimes(1)
await act(async () => root?.render(<Watcher hydrated worktreeId="wt-2" />))
mocks.gate.mockResolvedValue('adopted')
await act(async () => root?.render(<Watcher hydrated />))
expect(mocks.gate.mock.calls.map(([id]) => id)).toEqual(['wt-1', 'wt-2', 'wt-1'])
expect(mocks.resume).not.toHaveBeenCalled()
}
)
})
27 changes: 22 additions & 5 deletions src/renderer/src/components/use-terminal-watcher-effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from './terminal-pane/terminal-parked-tab-watchers'
import { useAppStore } from '@/store'
import { gateWorktreeAgentActivation } from '@/lib/worktree-agent-activation-gate'
import { resumeSleepingAgentSessionsForWorktree } from '@/lib/resume-sleeping-agent-session'
import { createWorkspaceTerminalHostAuthoritySelector } from '@/lib/workspace-terminal-host-authority'
import { getStructuredAgentLaunchStatus } from '@/lib/structured-agent-session-launch'
import { AGENT_SESSION_PROVIDER_HANDLE_PROVIDERS } from '../../../shared/agent-session-provider-handle'
Expand Down Expand Up @@ -251,7 +250,12 @@ export function useTerminalWatcherEffects(controller: TerminalWatcherController)

const startupResumeWorktreeIdsRef = useRef(new Set<string>())
useEffect(() => {
if (!workspaceSessionReady || !hydrationSucceeded || !activeWorktreeId) {
if (
!workspaceSessionReady ||
!terminalStartupRestorationReady ||
!hydrationSucceeded ||
!activeWorktreeId
) {
return
}
if (startupResumeWorktreeIdsRef.current.has(activeWorktreeId)) {
Expand All @@ -263,7 +267,20 @@ export function useTerminalWatcherEffects(controller: TerminalWatcherController)
return
}
startupResumeWorktreeIdsRef.current.add(activeWorktreeId)
// Why: startup hydration restores the worktree without activateAndRevealWorktree, so orphaned live/quit records need a terminal-surface pass after cold restore.
resumeSleepingAgentSessionsForWorktree(activeWorktreeId)
}, [activeWorktreeId, activeWorktreeHostAuthority, hydrationSucceeded, workspaceSessionReady])
// Startup recovery needs the same host census and in-flight gate as explicit activation.
void gateWorktreeAgentActivation(activeWorktreeId).then(
(outcome) => {
if (outcome === 'blocked') {
startupResumeWorktreeIdsRef.current.delete(activeWorktreeId)
}
},
() => startupResumeWorktreeIdsRef.current.delete(activeWorktreeId)
)
}, [
activeWorktreeId,
activeWorktreeHostAuthority,
hydrationSucceeded,
terminalStartupRestorationReady,
workspaceSessionReady
])
}
38 changes: 36 additions & 2 deletions src/renderer/src/lib/worktree-agent-activation-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,49 @@ describe('worktree agent activation gate', () => {
})
})

it.each(['present', 'unknown'] as const)(
'does not resume OMP when a surfaced %s agent lacks conversation ownership',
async (agentOwnership) => {
const record = {
...sleepingRecord('old-tab', DEAD_LEAF_ID, 'omp-session'),
agent: 'omp' as const
}
const ptyId = `${WORKTREE_ID}@@current-omp`
const { deps, resume, createTab } = testDeps({
sessions: [{ ...listed(ptyId), title: 'OMP', agentOwnership }],
sleeping: [record],
surfaceOwners: new Map([
[
ptyId,
{
ptyId,
tabId: 'current-tab',
paneKey: `current-tab:${LIVE_LEAF_ID}`
}
]
])
})
seedExistingSurface(deps.getState(), {
tabId: 'current-tab',
leafId: LIVE_LEAF_ID,
boundPtyId: ptyId
})
await expect(runWorktreeAgentActivationGate(WORKTREE_ID, deps)).resolves.toBe('blocked')
expect(resume).not.toHaveBeenCalled()
expect(createTab).not.toHaveBeenCalled()
expect(deps.getState().sleepingAgentSessionsByPaneKey[record.paneKey]).toEqual(record)
}
)

it('does not use an ambiguous tab binding as a live session claim', async () => {
const live = sleepingRecord('tab-live', LIVE_LEAF_ID, 'live-session')
const livePtyId = `${WORKTREE_ID}@@live-agent`
const { deps, resume } = testDeps({ sessions: [listed(livePtyId)], sleeping: [live] })
deps.getState().ptyIdsByTabId['tab-live'] = [livePtyId, `${WORKTREE_ID}@@other-agent`]

await expect(runWorktreeAgentActivationGate(WORKTREE_ID, deps)).resolves.toBe('resumed')
await expect(runWorktreeAgentActivationGate(WORKTREE_ID, deps)).resolves.toBe('blocked')

expect(resume).toHaveBeenCalledWith(WORKTREE_ID, { skipClaimKeys: new Set() })
expect(resume).not.toHaveBeenCalled()
})

it('blocks when a structured TUI owner is absent from live inventory', async () => {
Expand Down
35 changes: 25 additions & 10 deletions src/renderer/src/lib/worktree-agent-activation-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ function sessionBelongsToWorkspace(sessionId: string, worktreeId: string): boole
)
}

function liveSleepingAgentClaimKeys(
function liveSleepingAgentClaims(
store: ActivationStore,
worktreeId: string,
livePtyIds: ReadonlySet<string>,
structuredInventory: StructuredActivationInventory | null
): Set<string> {
): { keys: Set<string>; claimedPtyIds: Set<string> } {
const keys = new Set<string>()
const claimedPtyIds = new Set<string>()
for (const record of Object.values(store.sleepingAgentSessionsByPaneKey)) {
if (record.worktreeId !== worktreeId) {
continue
Expand All @@ -134,10 +135,11 @@ function liveSleepingAgentClaimKeys(
const persistedPtyId =
layoutPtyId ?? (tabPtyIds?.length === 1 ? tabPtyIds[0] : undefined) ?? structuredOwnerPtyId
if (persistedPtyId && livePtyIds.has(persistedPtyId)) {
claimedPtyIds.add(persistedPtyId)
keys.add(getProviderSessionClaimKey(record))
}
}
return keys
return { keys, claimedPtyIds }
}

export async function runWorktreeAgentActivationGate(
Expand Down Expand Up @@ -243,14 +245,27 @@ export async function runWorktreeAgentActivationGate(
if (structured && !workspaceHasSleepingAgentSessions(deps.getState(), worktreeId)) {
return 'structured'
}
const launched = deps.resume(worktreeId, {
skipClaimKeys: liveSleepingAgentClaimKeys(
deps.getState(),
worktreeId,
liveWorkspacePtyIds,
structuredInventory
const store = deps.getState()
const claims = liveSleepingAgentClaims(
store,
worktreeId,
liveWorkspacePtyIds,
structuredInventory
)
const hasUnclaimedRecovery = Object.values(store.sleepingAgentSessionsByPaneKey).some(
(record) =>
record.worktreeId === worktreeId && !claims.keys.has(getProviderSessionClaimKey(record))
)
// A surfaced PTY without a conversation claim may still own the sleeping session.
if (
hasUnclaimedRecovery &&
liveWorkspaceSessions.some(
(session) => session.agentOwnership !== 'absent' && !claims.claimedPtyIds.has(session.id)
)
})
) {
return 'blocked'
}
const launched = deps.resume(worktreeId, { skipClaimKeys: claims.keys })
// 'empty' is the caller's directive — "this gate produced no surface, seed one" — not a
// claim the host had nothing; the callers re-check their own seeding guards first.
return launched > 0
Expand Down
Loading