Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4c53712
fix(omp): reconcile live subagent status from native registry
kiendle Oct 14, 2026
680c957
fix(omp): harden native subagent tracking at scale
kiendle Oct 14, 2026
d55f359
test(omp): consolidate tracking regressions and native smoke
kiendle Oct 15, 2026
31a3af0
test(omp): keep core tracking regressions only
kiendle Oct 15, 2026
835ee65
fix(omp): preserve tracking through prompt completion markers
kiendle Oct 15, 2026
f87e1cb
Merge main and adapt OMP completion checks to typed runtime
kiendle Oct 15, 2026
16b06b8
test(omp): align tracking checks with current main contracts
kiendle Oct 15, 2026
edba859
fix(omp): preserve completion across shutdown and controller gaps
kiendle Oct 15, 2026
72180bd
fix(omp): fence superseded completion markers on reattached terminals
kiendle Oct 15, 2026
de20959
Merge current main and drop superseded OMP prompt-marker handling
kiendle Oct 18, 2026
5cc2c22
fix(omp): reconcile live subagents from the native registry
kiendle Oct 18, 2026
30237a7
revert(omp): drop the native registry observer and omp_status channel
AmoabaKelvin Oct 25, 2026
d04f83c
Merge origin/main into omp-subagent-status
AmoabaKelvin Oct 25, 2026
35e94b3
fix(omp): settle the pane once OMP no longer runs its children
AmoabaKelvin Oct 25, 2026
a12096f
test(omp): type the async job snapshot on the hook context
AmoabaKelvin Oct 25, 2026
6e5d7b2
fix(omp): keep a woken child that waits on its own background work
AmoabaKelvin Oct 25, 2026
1e99d02
fix(omp): skip pruning when OMP's job snapshot cannot name its children
AmoabaKelvin Oct 25, 2026
55c0f90
fix(omp): keep every child when OMP exposes no agent registry
AmoabaKelvin Oct 26, 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
13 changes: 8 additions & 5 deletions src/main/pi/agent-status-extension-async-subagents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,16 @@ describe('Pi child rows', () => {
])
})

it('posts an OMP task child with its description', async () => {
it.each([
['its description', 'Map the auth module', 'Map the auth module'],
['its name without one', undefined, 'AuthMap']
])('posts an OMP task child labelled by %s', async (_name, description, label) => {
const harness = createAgentStatusExtensionHarness({ kind: 'omp' })
await harness.callHook('session_start')
harness.emitPiEvent('task:subagent:lifecycle', {
id: '0-explore',
id: 'AuthMap',
agent: 'explore',
description: 'Map the auth module',
description,
detached: true,
status: 'started',
index: 0
Expand All @@ -233,11 +236,11 @@ describe('Pi child rows', () => {

expect(posts(harness).at(-1)?.subagents).toEqual([
{
id: '0-explore',
id: 'AuthMap',
state: 'working',
startedAt: expect.any(Number),
agentType: 'explore',
description: 'Map the auth module'
description: label
}
])
})
Expand Down
57 changes: 57 additions & 0 deletions src/main/pi/agent-status-extension-omp-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ function postedHookNames(fetchMock: ReturnType<typeof vi.fn>): string[] {
)
}

function lastSubagentIds(fetchMock: ReturnType<typeof vi.fn>): string[] {
const body = JSON.parse(String(fetchMock.mock.calls.at(-1)?.[1]?.body))
return (body.payload.subagents ?? []).map((subagent: { id: string }) => subagent.id)
}

const OMP_RUNTIME_CASES = [
['configured OMP', { kind: 'omp' as const }],
['title-routed OMP', { kind: 'pi' as const, title: 'omp' }],
Expand Down Expand Up @@ -244,6 +249,58 @@ describe('OMP subagent settlement', () => {
}
)

it('settles OMP when a child it no longer runs never reported finishing', async () => {
const harness = createAgentStatusExtensionHarness({ kind: 'omp' })

await hook(harness, 'agent_start')
await lifecycle(harness, 'Orphan', 'started')
await harness.callHook('agent_end', {}, { getAsyncJobSnapshot: () => ({ running: [] }) })
await vi.advanceTimersByTimeAsync(0)

expect(postedHookNames(harness.fetchMock).at(-1)).toBe('agent_end')
})

it('drops only the children OMP no longer runs', async () => {
const harness = createAgentStatusExtensionHarness({ kind: 'omp' })
const job = { type: 'task', agentId: 'Helper', label: 'Helper' }

await hook(harness, 'agent_start')
await lifecycle(harness, 'Orphan', 'started')
await lifecycle(harness, 'Helper', 'started')
await harness.callHook('agent_end', {}, { getAsyncJobSnapshot: () => ({ running: [job] }) })
await vi.advanceTimersByTimeAsync(0)

expect(postedHookNames(harness.fetchMock)).not.toContain('agent_end')
expect(lastSubagentIds(harness.fetchMock)).toEqual(['Helper'])
})

it('keeps every child when an older OMP snapshot cannot name its task jobs', async () => {
const harness = createAgentStatusExtensionHarness({ kind: 'omp' })
const job = { type: 'task', label: 'Helper-b1' }

await hook(harness, 'agent_start')
await lifecycle(harness, 'Helper', 'started')
await harness.callHook('agent_end', {}, { getAsyncJobSnapshot: () => ({ running: [job] }) })
await vi.advanceTimersByTimeAsync(0)

expect(postedHookNames(harness.fetchMock)).not.toContain('agent_end')
})

it('keeps OMP working while a woken child waits on its own background work', async () => {
const session = { isStreaming: false, hasPendingAsyncWork: () => true }
const harness = createAgentStatusExtensionHarness({
kind: 'omp',
ompModule: { AgentRegistry: { global: () => ({ get: () => ({ session }) }) } }
})

await hook(harness, 'agent_start')
await lifecycle(harness, 'Helper', 'started')
await harness.callHook('agent_end', {}, { getAsyncJobSnapshot: () => ({ running: [] }) })
await vi.advanceTimersByTimeAsync(0)

expect(postedHookNames(harness.fetchMock)).not.toContain('agent_end')
})

it('does not settle OMP when a child finishes mid-run', async () => {
const harness = createAgentStatusExtensionHarness({ kind: 'omp' })

Expand Down
5 changes: 5 additions & 0 deletions src/main/pi/agent-status-extension-test-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type HookContext = {
onTerminalInput?: (handler: (data: string) => { consume?: boolean } | undefined) => () => void
}
isIdle?: () => boolean
getAsyncJobSnapshot?: () => { running: { type: string; agentId?: string; label: string }[] }
resolvePlanReview?: (reviewId: string, choice: string) => boolean
model?: { provider?: unknown; id?: unknown } | null
modelRegistry?: { getAvailable: () => { provider: string; id: string }[] }
Expand Down Expand Up @@ -110,6 +111,8 @@ export function createAgentStatusExtensionHarness(args: {
curlExitCode?: number | null
fetchImpl?: (...params: Parameters<typeof fetch>) => Promise<unknown>
seedEventBus?: (bus: EventEmitter) => void
// OMP hands extensions its package exports as `pi.pi`.
ompModule?: unknown
// Pi versions before 0.84 shared one event bus across registrations.
sharedEventBus?: boolean
}): AgentStatusExtensionHarness {
Expand Down Expand Up @@ -165,6 +168,7 @@ export function createAgentStatusExtensionHarness(args: {
) => void
setModel: (model: unknown) => Promise<boolean>
events?: PiEventBus
pi?: unknown
}) => void
}
} = { exports: {} }
Expand Down Expand Up @@ -243,6 +247,7 @@ export function createAgentStatusExtensionHarness(args: {
},
setModel: setModelMock,
events,
pi: args.ompModule,
on(name: string, handler: HookHandler) {
target[name] = handler
;(handlerLists[name] ??= []).push(handler)
Expand Down
3 changes: 2 additions & 1 deletion src/main/pi/agent-status-handler-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
' lifecycleState.endedRunGeneration = lifecycleState.runGeneration',
...(kind === 'pi' ? [' recordReplyFinish(event)'] : []),
' if (isOmpRuntime()) {',
' postAgentEndOnce()',
' const prunedVisible = forgetFinishedOmpSubagents(ctx)',
' if (!postAgentEndOnce() && prunedVisible) postSubagentsUpdate()',
' return',
' }',
' if (agentSettledSupported) return',
Expand Down
33 changes: 31 additions & 2 deletions src/main/pi/agent-status-subagent-roster-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,35 @@ export function getPiSubagentRosterEventSourceLines(): string[] {
' function postSubagentsUpdate(): void {',
" if (!hasQueuedPost()) post('subagents_update')",
' }',
// OMP lifecycle frames can invert or lose a terminal; its job list and child sessions know which children still run.
' function forgetFinishedOmpSubagents(ctx): boolean {',
' const live = new Set<unknown>()',
' try {',
' const running = ctx?.getAsyncJobSnapshot?.()?.running',
' if (!Array.isArray(running)) return false',
// Older snapshots omit agentId, and workpool batch labels are not child ids.
' for (const job of running) {',
" if (job?.type !== 'task') continue",
" if (typeof job.agentId !== 'string') return false",
' live.add(job.agentId)',
' }',
// Woken or resumed children run outside the root's jobs.
' const registry = pi.pi?.AgentRegistry?.global?.()',
' for (const id of lifecycleState.active) {',
' const session = registry?.get?.(id)?.session',
' if (session?.isStreaming === true || session?.hasPendingAsyncWork?.() === true) live.add(id)',
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
' }',
' } catch {',
' return false',
' }',
' let wasVisible = false',
' for (const id of lifecycleState.active) {',
' if (live.has(id)) continue',
' wasVisible ||= isVisibleSubagent(lifecycleState, id)',
' forgetSubagent(id)',
' }',
' return wasVisible',
' }',
" const readLabel = (value: unknown): string | undefined => typeof value === 'string' && value.trim() ? value : undefined",
' lifecycleState.onEvent = (event: unknown, forcedStatus?: string): void => {',
" if (!event || typeof event !== 'object') return",
Expand All @@ -122,8 +151,8 @@ export function getPiSubagentRosterEventSourceLines(): string[] {
' if (isOmpRuntime() && !lifecycleState.ownsPane) return',
" if (status === 'started') {",
' lifecycleState.active.add(id)',
// Use labels/step keys because pi-subagents redacts task prompts; keys distinguish same-agent siblings.
" if (!subagentDetails.has(id)) subagentDetails.set(id, { agentType: readLabel(record.agent), description: readLabel(record.description) ?? readLabel(record.workflowKey), startedAt: Date.now(), workflow: record.mode === 'workflow', parent: readLabel(record.parentWorkflowRunId), registration })",
// Use labels/step keys because pi-subagents redacts task prompts; keys and OMP's named ids distinguish same-agent siblings.
" if (!subagentDetails.has(id)) subagentDetails.set(id, { agentType: readLabel(record.agent), description: readLabel(record.description) ?? readLabel(record.workflowKey) ?? (isOmpRuntime() ? id : undefined), startedAt: Date.now(), workflow: record.mode === 'workflow', parent: readLabel(record.parentWorkflowRunId), registration })",
// Pi reopens only posted completions; earlier children must preserve the idle check.
' if (!isTurnInFlight() && (isOmpRuntime() || lifecycleState.runGeneration === 0 || lifecycleState.completionPostedGeneration === lifecycleState.runGeneration)) {',
' lifecycleState.waiting = true',
Expand Down