fix(pi): validate inherited status owner pid markers

This commit is contained in:
Brennan Benson
2026-08-26 06:29:01 -07:00
parent 44e8b33a1c
commit 9479e4dec4
2 changed files with 34 additions and 3 deletions
@@ -6,7 +6,13 @@ describe('getPiAgentStatusExtensionSource', () => {
it('registers Prime hooks only in the event-emitting daemon worker', () => {
const frontend = createHarness({
kind: 'prime-agent',
env: { PRIME_AGENT_INTERNAL_DAEMON_WORKER: undefined }
env: {
PRIME_AGENT_INTERNAL_DAEMON_WORKER: undefined,
ORCA_PRIME_AGENT_STATUS_OWNED: String(SELF_PID - 1)
},
killImpl: () => {
throw Object.assign(new Error('ESRCH'), { code: 'ESRCH' })
}
})
const worker = createHarness({
kind: 'prime-agent',
@@ -14,7 +20,8 @@ describe('getPiAgentStatusExtensionSource', () => {
})
expect(frontend.handlers).toEqual({})
expect(frontend.processEnv.ORCA_PI_STATUS_OWNED).toBeUndefined()
expect(frontend.killMock).not.toHaveBeenCalled()
expect(frontend.processEnv.ORCA_PRIME_AGENT_STATUS_OWNED).toBe(String(SELF_PID - 1))
expect(worker.handlers.agent_start).toBeTypeOf('function')
expect(worker.processEnv.ORCA_PRIME_AGENT_STATUS_OWNED).toBe(String(SELF_PID))
})
@@ -322,6 +329,30 @@ describe('getPiAgentStatusExtensionSource', () => {
expect(harness.processEnv.ORCA_PI_STATUS_OWNED).toBe(String(SELF_PID))
})
it('claims the pane when the inherited owner PID exceeds safe integer precision', () => {
const harness = createHarness({
kind: 'pi',
pid: SELF_PID,
env: { ORCA_PI_STATUS_OWNED: '99999999999999999999999' }
})
expect(harness.killMock).not.toHaveBeenCalled()
expect(harness.handlers.agent_end).toBeTypeOf('function')
expect(harness.processEnv.ORCA_PI_STATUS_OWNED).toBe(String(SELF_PID))
})
it('claims the pane when the inherited owner PID exceeds the process API range', () => {
const harness = createHarness({
kind: 'pi',
pid: SELF_PID,
env: { ORCA_PI_STATUS_OWNED: String(2 ** 31) }
})
expect(harness.killMock).not.toHaveBeenCalled()
expect(harness.handlers.agent_end).toBeTypeOf('function')
expect(harness.processEnv.ORCA_PI_STATUS_OWNED).toBe(String(SELF_PID))
})
it.each(['pi', 'omp', 'prime-agent'] as const)(
'registers no status handlers for a nested %s subagent process',
(kind) => {
+1 -1
View File
@@ -66,7 +66,7 @@ export function getPiAgentStatusHandlerSourceLines(kind: PiAgentKind): string[]
'// import (the extension loads inside pi/omp with no Orca deps).',
'function isStatusOwnerAlive(pid: string): boolean {',
' const parsed = Number(pid)',
' if (!Number.isInteger(parsed) || parsed < 1) return false',
' if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 0x7fffffff) return false',
" if (typeof process.kill !== 'function') return true",
' try {',
' process.kill(parsed, 0)',