Files
orca/src/shared/codex-subagent-roster.test.ts
T
Brennan Benson 48e31b3fc0 fix(agent-status): show Codex v2 subagents (#11059)
* fix(agent-status): track Codex rollout subagents

* fix(agent-status): resolve cross-day Codex child rollouts and unblock CI gate

Codex files each rollout under its own local start date, so a session that
runs past midnight spawns children into a sibling day directory. Scanning
only the parent's directory left 13% of real subagent spawns (48/371 across
local rollouts) permanently unresolved, which pinned a phantom "working" row
and re-ran readdirSync every poll tick forever. Resolve the child's own day
directory from occurred_at_ms, and time-box a child whose rollout stays
unreadable so a deleted or never-written file can't leak a working row.

Also make the hook HTTP handler return void: the changed-code quality gate
keys findings by span overlap, so this PR's added line inside the pre-existing
async createServer callback resurfaced no-misused-promises as a new finding.

Tests cover cross-day resolution, grace-period retirement, and that the poll
re-arms across successive roster changes (the prior tests passed even when
the poll died after its first change).

* fix(agent-status): keep the Codex subagent poll alive across nested hooks

A nested non-codex CLI inherits its parent's ORCA_PANE_KEY, so its hook
POST reached scheduleCodexSubagentPoll and tore the timer down before the
source guard, silently ending polling while a rollout child was still live.
2026-07-27 23:50:25 -07:00

65 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
AGENT_MODEL_MAX_LENGTH,
AGENT_STATUS_MAX_SUBAGENTS,
AGENT_TYPE_MAX_LENGTH
} from './agent-status-types'
import {
codexRosterToSnapshots,
finishCodexSubagent,
upsertCodexSubagent,
type CodexSubagentRoster
} from './codex-subagent-roster'
describe('Codex subagent roster', () => {
it('normalizes retained identity fields before storing them', () => {
const roster: CodexSubagentRoster = new Map()
upsertCodexSubagent(
roster,
' child-1 ',
{
agentType: `reviewer\n${'x'.repeat(AGENT_TYPE_MAX_LENGTH * 2)}`,
description: 'Review the sidebar lifecycle',
model: `gpt-model-${'x'.repeat(AGENT_MODEL_MAX_LENGTH * 2)}`,
state: 'working'
},
10
)
const snapshot = codexRosterToSnapshots(roster)?.[0]
expect([...roster.keys()]).toEqual(['child-1'])
expect(snapshot?.agentType).toHaveLength(AGENT_TYPE_MAX_LENGTH)
expect(snapshot?.agentType).not.toContain('\n')
expect(snapshot?.description).toBe('Review the sidebar lifecycle')
expect(snapshot?.model).toHaveLength(AGENT_MODEL_MAX_LENGTH)
finishCodexSubagent(roster, ' child-1 ')
expect(roster.size).toBe(0)
})
it('rejects an id that would normalize to an invisible child', () => {
const roster: CodexSubagentRoster = new Map()
upsertCodexSubagent(roster, ' ', { state: 'waiting' }, 10)
expect(roster.size).toBe(0)
})
it('bounds live storage while admitting a replacement after one child stops', () => {
const roster: CodexSubagentRoster = new Map()
for (let index = 0; index <= AGENT_STATUS_MAX_SUBAGENTS; index += 1) {
upsertCodexSubagent(roster, `child-${index}`, { state: 'working' }, index)
}
expect(roster.size).toBe(AGENT_STATUS_MAX_SUBAGENTS)
expect(roster.has(`child-${AGENT_STATUS_MAX_SUBAGENTS}`)).toBe(false)
finishCodexSubagent(roster, 'child-0')
upsertCodexSubagent(roster, 'replacement', { state: 'working' }, 100)
expect(roster.size).toBe(AGENT_STATUS_MAX_SUBAGENTS)
expect(roster.has('replacement')).toBe(true)
})
})