Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0f292ca
fix: correct managed OMP readiness and lifecycle status
sauravhiremath Sep 30, 2026
426cea0
fix: preserve genuine OMP readiness title evidence
sauravhiremath Sep 30, 2026
39e2d31
fix: keep OMP async completion checks after agent settled
sauravhiremath Sep 30, 2026
38c5d65
fix: reject stale-clear renderer titles as idle evidence
sauravhiremath Sep 30, 2026
bb71fd2
fix: preserve OMP readiness boundaries after completed turns
sauravhiremath Sep 30, 2026
6573145
Merge upstream/main into fix/omp-status-mapping
sauravhiremath Oct 1, 2026
370eb49
fix: require shell evidence before retiring agent launch authority
sauravhiremath Oct 1, 2026
58a7bb7
fix: retain agent status and completed turn duration
sauravhiremath Oct 1, 2026
bee3570
fix: fence stale OMP launch authority and hook retirement
sauravhiremath Oct 1, 2026
0b2b1bb
Merge upstream/main into fix/omp-status-mapping
sauravhiremath Oct 2, 2026
1b79ee7
Merge main and reconcile OMP readiness with native title evidence
sauravhiremath Oct 3, 2026
a1f705a
Merge upstream main and preserve managed OMP readiness
sauravhiremath Oct 5, 2026
2f5e87c
Merge upstream main and simplify OMP status integration
sauravhiremath Oct 7, 2026
e9ed8c4
Keep upstream formatting outside the OMP status fix
sauravhiremath Oct 7, 2026
0dfb9ea
Merge latest upstream main into OMP status fix
sauravhiremath Oct 9, 2026
7f77bd6
docs: record completed OMP agent status reproduction
sauravhiremath Oct 15, 2026
4756879
Merge upstream main and preserve OMP status lifecycle
sauravhiremath Oct 15, 2026
5909949
Merge upstream main and tighten OMP status ownership
sauravhiremath Oct 19, 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
39 changes: 39 additions & 0 deletions docs/reference/agent-status-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,45 @@ Three consequences:
decay, acknowledgements, dismissals, unread. Those stay reader-side but
become one shared implementation (PR 3).

## Managed OMP hook status

The managed extension sends OMP events to `/hook/omp` on the execution host.
`normalizePiCompatibleEvent` maps them into the existing hook status store.
Native, WSL, SSH, and folder workspaces use the same mapping.
No second reporter or reader-side rule is required.

- Startup and session switches send current activity. Readiness requires idle,
no pending messages, and no active jobs. Missing activity does not prove readiness.
- Idle readiness uses `done` with `sessionBoundary: true`. It is not turn completion.
This also applies after a completed turn: retry, compaction, dialog close, and
approval resolution keep the prior main-agent outcome without another completion.
- Retry and compaction start as `working`. Their end can restore readiness only
when current activity is clear and no continuation flag is true.
- Real UI dialogs use `waiting`; tool approvals use `blocked`. Closing a dialog
restores current activity. Nested dialogs, reloads, and stale closes are tracked.
- `agent_end` with `willContinue: true` does not complete a turn. Owned jobs,
children, and pending messages keep the combined row `working` after the main
agent completes. The final all-clear keeps the main-agent outcome and its clock.
- OMP keeps checking owned jobs and pending messages after `agent_settled` until
they clear. Pi still uses `agent_settled` instead of its idle fallback check.
- The last assistant stop reason maps `stop` to `success`, `error` to `failure`,
and `aborted` to `cancellation`. Other reasons have no outcome. Normal provider
completion does not prove that the user's task succeeded.
- Shutdown clears local timers and dialog tracking without a completion event.
Missing hooks or transport loss never prove process exit. Process verdicts
remain `live`, `unverifiable`, and `exited`.
- Timer-cleared working titles do not prove readiness. Their origin survives
graph rebuilds and same-title hydration. While the stale-clear flag is set,
neither the OSC title nor the renderer title proves idle, even after rebranding.
A genuine OSC title clears the flag and restores idle-title evidence.
- A fresh working hook prevents a retained prompt from proving readiness.
- Selected-target sends recognize current Pi and OMP idle state markers,
including wrapped titles, and keep support for the legacy idle title.

Activity and outcome fields are optional payload fields. Existing remote clients
do not need a new wire opcode. A source change does not update an installed app
or its managed extension until that source is built and deployed.

## The store already exists

The hook server's state is that store today for every PTY-based agent. The
Expand Down
1 change: 0 additions & 1 deletion src/main/pi/agent-status-extension-omp-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ describe('OMP agent_end contract', () => {
await vi.waitFor(() =>
expect(postedHookNames(harness.fetchMock)).toEqual(['agent_start', 'agent_end'])
)
expect(context.isIdle).not.toHaveBeenCalled()
}
}
)
Expand Down
1 change: 0 additions & 1 deletion src/main/pi/agent-status-extension-omp-prefill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('OMP prefill through the explicitly loaded status extension', () => {
h.reload()
await h.callHook('session_start', {}, { ui: { setEditorText } })
expect(setEditorText).toHaveBeenCalledTimes(1)
expect(h.fetchMock).not.toHaveBeenCalled()
})

it('preserves the draft until an editor is available', async () => {
Expand Down
29 changes: 0 additions & 29 deletions src/main/pi/agent-status-extension-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,35 +163,6 @@ describe('getPiAgentStatusExtensionSource', () => {
}
})

it('keeps OMP runtime status payloads unchanged by Pi session metadata', async () => {
const harness = createHarness({ kind: 'omp' })

await harness.callHook(
'session_start',
{},
{
sessionManager: {
getSessionId: () => 'omp-session-1',
getSessionFile: () => '/tmp/omp-session-1.jsonl'
}
}
)
await harness.callHook('agent_start')

expect(harness.fetchMock).toHaveBeenCalledTimes(1)
expect(harness.fetchMock.mock.calls[0]?.[1]?.body).toBe(
JSON.stringify({
paneKey: 'pane-1',
launchToken: 'launch-1',
tabId: 'tab-1',
worktreeId: 'tree-1',
env: 'env-1',
version: '1.2.3',
payload: { hook_event_name: 'agent_start' }
})
)
})

it('tracks persistent OMP sessions and clears ephemeral session ids', async () => {
const harness = createHarness({ kind: 'omp' })
let sessionId = 'omp-session-8'
Expand Down
8 changes: 4 additions & 4 deletions src/main/pi/agent-status-extension-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ export function getPiAgentStatusExtensionSource(kind: PiAgentKind = 'pi'): strin
' const metadata = getPostSessionMetadata(ompRuntime)',
'// Model changes must not erase an unacknowledged completion in the latest-only slot.',
" const previousCompletion = latestPost?.hookEventName === 'agent_end' && !latestPost.delivered && latestPost.metadata.session_id === metadata.session_id",
" const preserveCompletion = ompRuntime && previousCompletion && ['model_select', 'ui_prompt_start', 'ui_prompt_end'].includes(hookEventName)",
' pendingPost = {',
' revision: ++postRevision,',
' attempts: 0,',
' delivered: false,',
" hookEventName: ompRuntime && hookEventName === 'model_select' && previousCompletion ? 'agent_end' : hookEventName,",
// Why: every coalesced snapshot must retain an open modal, not just its start event.
" hookEventName: preserveCompletion ? 'agent_end' : hookEventName,",
kind === 'pi'
? ' extra: { ...extra, ...(!ompRuntime && piUiPromptDepth > 0 ? { ui_prompt_active: true } : {}) },'
: ' extra,',
? ' extra: { ...(preserveCompletion ? latestPost.extra : {}), ...extra, ...((ompRuntime ? ompUiPromptDepth : piUiPromptDepth) > 0 ? { ui_prompt_active: true } : preserveCompletion ? { ui_prompt_active: false } : {}) },'
: ' extra: { ...(preserveCompletion ? latestPost.extra : {}), ...extra, ...(ompUiPromptDepth > 0 ? { ui_prompt_active: true } : preserveCompletion ? { ui_prompt_active: false } : {}) },',
' metadata,',
' ompRuntime,',
' }',
Expand Down
18 changes: 16 additions & 2 deletions src/main/pi/agent-status-extension-test-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import { getPiAgentStatusExtensionSource } from './agent-status-extension-source

export type HookContext = {
hasUI?: boolean
ui?: { setEditorText?: (text: string) => void; notify?: (message: string, level: string) => void }
ui?: {
setEditorText?: (text: string) => void
notify?: (message: string, level: string) => void
confirm?: (title: string, message: string) => Promise<boolean>
input?: (title: string, placeholder?: string) => Promise<string | undefined>
}
isIdle?: () => boolean
hasPendingMessages?: () => boolean
getAsyncJobSnapshot?: () => { running: unknown[]; recent?: unknown[] } | null
agent?: { kind: 'main' | 'sub' }
model?: { provider?: unknown; id?: unknown } | null
modelRegistry?: { getAvailable: () => { provider: string; id: string }[] }
sessionManager?: {
Expand Down Expand Up @@ -205,7 +213,13 @@ export function createAgentStatusExtensionHarness(args: {
setModel: setModelMock,
events: piEvents,
on(name: string, handler: HookHandler) {
target[name] = handler
const previous = target[name]
target[name] = previous
? async (event, ctx) => {
await previous(event, ctx)
await handler(event, ctx)
}
: handler
}
})
}
Expand Down
54 changes: 34 additions & 20 deletions src/main/pi/agent-status-handler-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getAgentStatusInputRedactionSourceLines } from './agent-status-input-re
import type { PiAgentKind } from '../../shared/pi-agent-kind'
import { getOmpSessionOwnerHandlerSourceLines } from './omp-session-status-owner-source'
import { getPiAgentStatusUiPromptHandlerSourceLines } from './agent-status-ui-prompt-source'
import * as ompStatusLifecycle from './omp-status-lifecycle-source'
import {
getPiSubagentRosterEventSourceLines,
getPiSubagentRosterSetupSourceLines
Expand All @@ -17,6 +18,7 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
? [
" onStatus('session_start', (event, ctx) => {",
' updateSessionMetadata(ctx)',
' if (isOmpRuntime()) { invalidateOmpUiDialogs(); post("session_start", readOmpActivity(ctx)); return }',
...(kind === 'pi' ? [' piUiPromptDepth = 0'] : []),
' // Why: /reload re-registers the active session, but it is not a',
' // turn boundary and must not clear the visible status or unread state.',
Expand All @@ -25,7 +27,13 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
' })',
''
]
: []
: [
" onStatus('session_start', (_event, ctx) => {",
' invalidateOmpUiDialogs()',
' updateRuntimeOmpSessionMetadata(ctx)',
" post('session_start', readOmpActivity(ctx))",
' })'
]

// Why: OMP can switch sessions in-process, so each latest-only post needs fresh identity.
const ctxParam = ', ctx'
Expand Down Expand Up @@ -63,6 +71,7 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
" post('tool_approval_resolved', {",
' tool_name: event.toolName,',
' approved: event.approved,',
' ...readOmpActivity(ctx),',
' })',
' })',
''
Expand Down Expand Up @@ -123,6 +132,7 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
" return (err as { code?: string } | null)?.code !== 'ESRCH'",
' }',
'}',
...ompStatusLifecycle.getOmpStatusLifecycleSourceLines(),
'',
"// Why: child agents inherit the lead's pane env; only its process may",
'// register status hooks. PID identity keeps in-process reloads reporting.',
Expand All @@ -136,26 +146,14 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
...getPiSubagentRosterSetupSourceLines(),
...(kind !== 'pi'
? [
" pi.on('session_shutdown', () => { lifecycleState.active.clear(); lifecycleState.exited?.clear(); lifecycleState.waiting = false; resetPostQueue(); clearPendingAgentEndCheck() })"
]
: []),
...(kind !== 'prime-agent'
? [
" pi.on('session_switch', (_event, ctx) => {",
' if (!isOmpRuntime()) return',
' lifecycleState.active.clear()',
' lifecycleState.exited?.clear()',
' lifecycleState.waiting = false',
' resetPostQueue()',
' clearPendingAgentEndCheck()',
' updateRuntimeOmpSessionMetadata(ctx)',
' })'
" pi.on('session_shutdown', (_event, ctx) => { if (!ownsSessionStatus(ctx)) return; lifecycleState.active.clear(); lifecycleState.exited?.clear(); lifecycleState.waiting = false; resetPostQueue(); clearPendingAgentEndCheck(); invalidateOmpUiDialogs(); ompCompletionExtra = {}; ompCompletionContext = null })"
]
: []),
...getOmpSessionOwnerHandlerSourceLines(),
...getOmpModelCommandSourceLines(),
...sessionStartHandler,
...(kind === 'omp' ? getPiPrefillHandlerSourceLines('omp', true) : []),
...ompStatusLifecycle.getOmpStatusLifecycleHandlerSourceLines(),
` onStatus('before_agent_start', (event${ctxParam}) => {`,
...captureSessionMetadata,
" post('before_agent_start', { prompt: event.prompt ?? '' })",
Expand All @@ -166,6 +164,7 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
' clearPendingAgentEndCheck()',
' lifecycleState.waiting = false',
' runGeneration += 1',
' if (isOmpRuntime()) { invalidateOmpUiDialogs(); ompCompletionExtra = {}; ompCompletionContext = null }',
// Why: a turn cannot begin under a dialog holding input focus, so this is the one
// boundary that can recover a modal whose close never arrived.
...(kind === 'pi' ? [' piUiPromptDepth = 0', ' piTurnInFlight = true'] : []),
Expand Down Expand Up @@ -212,8 +211,7 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
'',
' // Why: modern Pi stays non-idle across retry/compaction/follow-up work,',
' // while legacy Pi becomes idle after its final agent_end handlers.',
' // OMP instead marks non-terminal agent_end events with willContinue, so it',
' // returns before the recheck timer is ever armed.',
' // OMP continuation events never establish completion; owned jobs delay all-clear.',
' const AGENT_END_IDLE_RECHECK_MS = 25',
' const AGENT_END_IDLE_RECHECK_MAX_MS = 250',
' let agentSettledSupported = false',
Expand All @@ -226,6 +224,8 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
' let runGeneration = 0',
' let endedRunGeneration = 0',
' let completionPostedGeneration = -1',
' let ompCompletionExtra: Record<string, unknown> = {}',
' let ompCompletionContext = null',
' let agentEndIdleRecheckMs = AGENT_END_IDLE_RECHECK_MS',
' let pendingAgentEndCheck: ReturnType<typeof setTimeout> | null = null',
' let pendingAgentEndContext: { isIdle: () => boolean } | null = null',
Expand All @@ -241,26 +241,38 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
' lifecycleState.exited?.clear()',
' if (lifecycleState.active.size > 0) {',
' lifecycleState.waiting = true',
' if (isOmpRuntime()) post("agent_end", { ...ompCompletionExtra, has_active_jobs: true })',
' return',
' }',
' if (isOmpRuntime() && ompCompletionContext) {',
' const activity = readOmpActivity(ompCompletionContext)',
' if (activity.has_active_jobs === true || activity.has_pending_messages === true) {',
' post("agent_end", { ...ompCompletionExtra, ...activity })',
' pendingAgentEndContext = ompCompletionContext',
' if (pendingAgentEndCheck === null) pendingAgentEndCheck = setTimeout(checkPendingAgentEnd, AGENT_END_IDLE_RECHECK_MS)',
' pendingAgentEndCheck?.unref?.()',
' return',
' }',
' }',
' lifecycleState.waiting = false',
' if (completionPostedGeneration === endedRunGeneration) return',
' completionPostedGeneration = endedRunGeneration',
// Why: distinct from the completion guard, which holds the generation of the posted run
// and so starts clean on a pane that has not run a turn yet — that pane is idle, not busy.
...(kind === 'pi' ? [' piTurnInFlight = false'] : []),
" post('agent_end')",
" post('agent_end', isOmpRuntime() ? ompCompletionExtra : {})",
' }',
'',
' function checkPendingAgentEnd(): void {',
' pendingAgentEndCheck = null',
' const ctx = pendingAgentEndContext',
' if (!ctx || agentSettledSupported || completionPostedGeneration === endedRunGeneration) {',
' if (!ctx || (agentSettledSupported && !isOmpRuntime()) || completionPostedGeneration === endedRunGeneration) {',
' pendingAgentEndContext = null',
' return',
' }',
' try {',
' if (ctx.isIdle()) {',
' const activity = isOmpRuntime() ? readOmpActivity(ctx) : null',
' if (ctx.isIdle() && activity?.has_active_jobs !== true && activity?.has_pending_messages !== true) {',
' pendingAgentEndContext = null',
' postAgentEndOnce()',
' return',
Expand Down Expand Up @@ -289,6 +301,8 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
' }',
' endedRunGeneration = runGeneration',
' if (isOmpRuntime()) {',
' ompCompletionContext = ctx',
' ompCompletionExtra = { turn_outcome: readOmpTurnOutcome(event?.messages) }',
' postAgentEndOnce()',
' return',
' }',
Expand Down
Loading