Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
102 changes: 102 additions & 0 deletions config/reliability-gates.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -20870,6 +20870,108 @@
"Reproduce and fix the native trigger; collect cross-platform and soak evidence."
],
"demotionRule": "Keep experimental until the initial trigger and cross-platform behavior are understood."
},
{
"id": "agent-status.nested-provider-roster",
"title": "Nested review CLIs cannot replace the active pane status",
"maturity": "experimental",
"protection": "partial",
"owner": "agent-session",
"layer": "cross-boundary",
"surfaces": [
"agent hook normalization",
"sidebar child rows",
"mobile status snapshots"
],
"platforms": [
"macos",
"linux",
"windows"
],
"providers": [
"local",
"daemon",
"ssh",
"wsl",
"remote-runtime"
],
"coveredPlatforms": [
"macos"
],
"coveredProviders": [],
"coverageNotes": "Contract tests exercise local HTTP hooks, loopback SSH/WSL relay forwarding and legacy relay snapshots. No live SSH, WSL, Linux or Windows execution is claimed. Daemon PTYs use the same hook ingress; folder workspace routing is covered. Hidden macOS Electron validation used the real WorktreeCardAgents component and store in a temporary harness, receiving real hook IPC: 60 nested Codex updates produced zero row mutations, retained 32 children and kept height at 1170px. Screenshots inspected; synthetic hooks, no new model-backed turn.",
"motivatingLinks": [
"User report (2026-10-15): Claude status in nwparker/SSH alternates between a 32-child roster and an empty roster when nested Codex reviews report on the inherited terminal pane.",
"https://github.com/stablyai/orca/pull/8211",
"https://github.com/stablyai/orca/pull/3990"
],
"invariant": "A different provider inheriting an active pane key cannot replace its child roster, main turn, prompt, resume identity, model or freshness, nor mutate the owning provider caches. Same-provider children still update; finished or stale owners permit provider replacement.",
"oracle": "Send a full Claude child roster, interleave Codex review lifecycle/tool/approval/completion hooks, and require identical snapshots plus zero publications. A later Claude child event must retain the original prompt and roster, and a real child completion must shrink it.",
"commands": [
"ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/server-nested-agent-roster.test.ts src/main/agent-hooks/server-nested-agent-model.test.ts src/main/agent-hooks/server-ingest-remote.test.ts src/renderer/src/store/slices/agent-status-tool-assistant-fields.test.ts --maxWorkers=2",
"ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/server-nested-agent-roster.test.ts src/main/agent-hooks/server-nested-agent-model.test.ts src/main/agent-hooks/server-ingest-remote.test.ts src/main/agent-hooks/server-agent-presence.test.ts src/renderer/src/store/slices/agent-status-tool-assistant-fields.test.ts src/main/agent-hooks/server-hook-http-ingest.test.ts src/wsl-guest/agent-hook-server.test.ts --maxWorkers=2",
"ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/server-nested-agent-roster.test.ts src/main/agent-hooks/server-ingest-remote.test.ts src/main/agent-hooks/server-nested-agent-model.test.ts src/main/agent-hooks/server-hook-http-ingest.test.ts src/main/agent-hooks/server-turn-started-at.test.ts src/renderer/src/store/slices/agent-status-tool-assistant-fields.test.ts --maxWorkers=2"
],
"testFiles": [
"src/main/agent-hooks/server-nested-agent-roster.test.ts",
"src/main/agent-hooks/server-nested-agent-model.test.ts",
"src/main/agent-hooks/server-ingest-remote.test.ts",
"src/renderer/src/store/slices/agent-status-tool-assistant-fields.test.ts"
],
"assertionRefs": [
{
"file": "src/main/agent-hooks/server-nested-agent-roster.test.ts",
"assertions": [
"keeps Claude children, prompt and turn stable through Codex review hooks",
"rejects a nested working snapshot from an older relay without renewing the parent"
]
}
],
"evidenceRuns": [
{
"date": "2026-10-15",
"runner": "local",
"platform": "macos",
"command": "ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/server-nested-agent-roster.test.ts src/main/agent-hooks/server-nested-agent-model.test.ts src/main/agent-hooks/server-ingest-remote.test.ts src/main/agent-hooks/server-agent-presence.test.ts src/renderer/src/store/slices/agent-status-tool-assistant-fields.test.ts src/main/agent-hooks/server-hook-http-ingest.test.ts src/wsl-guest/agent-hook-server.test.ts --maxWorkers=2",
"result": "passed",
"durationSeconds": 91.45,
"summary": "97 tests across seven files passed, including full 32-child local and relay HTTP flows, legacy remote snapshots, model isolation, owner process contracts and renderer ownership. Finished/stale replacement controls added afterward are validated separately."
},
{
"date": "2026-10-15",
"runner": "local",
"platform": "macos",
"command": "ORCA_BACKGROUND_LAUNCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/agent-hooks/server-nested-agent-roster.test.ts src/main/agent-hooks/server-ingest-remote.test.ts src/main/agent-hooks/server-nested-agent-model.test.ts src/main/agent-hooks/server-hook-http-ingest.test.ts src/main/agent-hooks/server-turn-started-at.test.ts src/renderer/src/store/slices/agent-status-tool-assistant-fields.test.ts --maxWorkers=2",
"result": "passed",
"durationSeconds": 180.43,
"summary": "Final implementation passes 64 tests in six files, including local/relay finished-provider replacement, stale-provider replacement, 32-child ownership, legacy remote snapshots, turn clocks and renderer identity."
}
],
"runtimeBudget": {
"p95Seconds": 30,
"scope": "Focused local HTTP, relay, legacy snapshot and renderer contracts; excludes package build and machine contention."
},
"flakeHistory": {
"status": "not-started",
"evidence": "New gate; no CI soak history."
},
"redGreenEvidence": {
"status": "partial",
"evidence": "Live incident records alternate between a Claude 32-child roster and a Codex empty roster. Executing the original HEAD identity function accepts a nested working status; the patched function rejects it. Local and relay HTTP roster tests pass and hidden Electron real-component proof preserves all 32 rendered children through 60 nested hooks. No archived CI red/green run yet."
},
"performanceBudget": {
"required": true,
"evidence": "Reuses the existing constant-time provider identity decision. Rejected nested hooks add no polling, timers, subprocesses, retained state or renderer publications; tests require zero status publications for six nested hooks."
},
"promotionCriteria": [
"Save red/green evidence and CI soak before promotion."
],
"knownGaps": [
"A nested CLI started before any owner is observed may still establish the initial pane identity.",
"Same-provider nested sessions remain governed by the existing process/session ownership rules.",
"Live SSH/WSL, Linux, Windows and physical mobile validation are not included."
],
"demotionRule": "Keep experimental until CI soak; investigate any roster loss or blocked genuine provider replacement without weakening the snapshot and publication assertions."
}
]
}
10 changes: 4 additions & 6 deletions src/main/agent-hooks/server-ingest-remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('AgentHookServer ingestRemote', () => {
)
})

it('preserves active pane identity when a nested remote hook reports another agent', () => {
it('preserves active pane status when a nested remote hook reports another agent', () => {
vi.useFakeTimers()
vi.setSystemTime(1_000)
try {
Expand Down Expand Up @@ -234,17 +234,15 @@ describe('AgentHookServer ingestRemote', () => {
expect.objectContaining({
paneKey: PANE,
state: 'working',
prompt: 'nested claude',
prompt: 'parent codex',
agentType: 'codex',
toolName: 'Read',
toolInput: '00-review-context.md',
receivedAt: 1_100
receivedAt: 1_000
})
])
expect(listener).toHaveBeenLastCalledWith(
expect.objectContaining({
payload: expect.objectContaining({
prompt: 'nested claude',
prompt: 'parent codex',
agentType: 'codex'
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/agent-hooks/server-nested-agent-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('AgentHookServer nested agent model fence', () => {
server.stop()
}

expect(pushed.length).toBeGreaterThanOrEqual(4)
expect(pushed).toHaveLength(2)
expect(pushed.every((payload) => payload.agentType === 'claude')).toBe(true)
expect(pushed.map((payload) => payload.model)).not.toContain('gpt-6-astra')
})
Expand Down
209 changes: 209 additions & 0 deletions src/main/agent-hooks/server-nested-agent-roster.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { AgentHookServer } from './server'
import { buildBody, PANE, postHookEvent } from './server.test-fixtures'
import { RelayAgentHookServer } from '../../wsl-guest/agent-hook-server'
import {
AGENT_STATUS_MAX_SUBAGENTS,
AGENT_STATUS_STALE_AFTER_MS
} from '../../shared/agent-status-types'
import type { AgentHookSource } from '../../shared/agent-hook-relay'

vi.mock('../telemetry/client', () => ({ track: vi.fn() }))
vi.mock('../telemetry/cohort-classifier', () => ({
getCohortAtEmit: vi.fn(() => ({ nth_repo_added: 2 }))
}))

afterEach(() => vi.restoreAllMocks())

describe('nested agent hooks preserve the owning pane', () => {
it.each(['local', 'relay'] as const)(
'keeps Claude children, prompt and turn stable through Codex review hooks over %s',
async (transport) => {
const server = new AgentHookServer()
const dir = mkdtempSync(join(tmpdir(), 'orca-nested-roster-'))
const relay = new RelayAgentHookServer({
endpointDir: dir,
forward: (event) => server.ingestRemote(event, 'conn-1')
})
const pushed = vi.fn()
server.setListener(pushed)
await server.start({ env: 'production' })
try {
if (transport === 'relay') {
await relay.start()
}
const post = async (source: AgentHookSource, payload: Record<string, unknown>) => {
const body = buildBody(payload)
const response =
transport === 'local'
? await postHookEvent(server, body, `/hook/${source}`)
: await fetch(`http://127.0.0.1:${relay.getCoordinates().port}/hook/${source}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Orca-Agent-Hook-Token': relay.getCoordinates().token
},
body: JSON.stringify(body)
})
expect(response.status).toBe(204)
}
await post('claude', {
hook_event_name: 'UserPromptSubmit',
session_id: 'claude-parent',
prompt: 'Fix SSH'
})
await post('claude', {
hook_event_name: 'Stop',
session_id: 'claude-parent',
background_tasks: Array.from({ length: AGENT_STATUS_MAX_SUBAGENTS }, (_, i) => ({
id: `child${i}`,
type: 'subagent',
status: 'running',
description: `Fix issue ${i}`
}))
})
const before = server.getStatusSnapshot()
expect(before[0]).toMatchObject({
state: 'working',
prompt: 'Fix SSH',
mainAgent: { state: 'done' },
providerSession: { id: 'claude-parent' }
})
expect(before[0]?.subagents).toHaveLength(AGENT_STATUS_MAX_SUBAGENTS)
pushed.mockClear()
for (const hook_event_name of [
'SessionStart',
'UserPromptSubmit',
'PreToolUse',
'PostToolUse',
'PermissionRequest',
'Stop'
]) {
await post('codex', {
hook_event_name,
session_id: 'codex-review',
prompt: 'Review origin/main',
tool_name: 'shell',
tool_input: { command: 'git diff' },
model: 'gpt-6-astra'
})
expect(server.getStatusSnapshot()).toEqual(before)
}
expect(pushed).not.toHaveBeenCalled()
await post('claude', {
hook_event_name: 'PreToolUse',
session_id: 'claude-parent',
agent_id: 'child0',
tool_name: 'Read',
tool_input: { file_path: 'README.md' }
})
expect(server.getStatusSnapshot()[0]).toMatchObject({
prompt: 'Fix SSH',
mainAgent: { state: 'done' },
providerSession: { id: 'claude-parent' },
subagents: before[0]?.subagents
})
await post('claude', {
hook_event_name: 'SubagentStop',
session_id: 'claude-parent',
agent_id: 'child0'
})
expect(server.getStatusSnapshot()[0]?.subagents).toHaveLength(
AGENT_STATUS_MAX_SUBAGENTS - 1
)
await post('claude', {
hook_event_name: 'Stop',
session_id: 'claude-parent',
background_tasks: []
})
expect(server.getStatusSnapshot()[0]?.state).toBe('done')
await post('codex', {
hook_event_name: 'UserPromptSubmit',
session_id: 'new-codex',
prompt: 'New turn'
})
expect(server.getStatusSnapshot()[0]).toMatchObject({
agentType: 'codex',
prompt: 'New turn',
providerSession: { id: 'new-codex' }
})
} finally {
relay.stop()
server.stop()
rmSync(dir, { recursive: true, force: true })
}
}
)

it('allows a different provider after the previous status becomes stale', async () => {
const now = vi.spyOn(Date, 'now').mockReturnValue(1_000)
const server = new AgentHookServer()
await server.start({ env: 'production' })
try {
await postHookEvent(
server,
buildBody({
hook_event_name: 'UserPromptSubmit',
session_id: 'old-claude',
prompt: 'Old turn'
})
)
now.mockReturnValue(1_000 + AGENT_STATUS_STALE_AFTER_MS + 1)
await postHookEvent(
server,
buildBody({
hook_event_name: 'UserPromptSubmit',
session_id: 'new-codex',
prompt: 'New turn'
}),
'/hook/codex'
)
expect(server.getStatusSnapshot()[0]).toMatchObject({
agentType: 'codex',
prompt: 'New turn',
providerSession: { id: 'new-codex' }
})
} finally {
server.stop()
}
})

it('rejects a nested working snapshot from an older relay without renewing the parent', () => {
const server = new AgentHookServer()
const route = { paneKey: PANE, tabId: 'tab-1', worktreeId: 'folder:workspace' }
server.ingestRemote(
{
...route,
payload: {
state: 'working',
prompt: 'Fix SSH',
agentType: 'claude',
subagents: [{ id: 'child', state: 'working', startedAt: Date.now() }],
mainAgent: { state: 'done', stateStartedAt: Date.now() }
}
},
'conn-1'
)
const before = server.getStatusSnapshot()
const pushed = vi.fn()
server.setListener(pushed)
pushed.mockClear()
server.ingestRemote(
{
...route,
payload: {
state: 'working',
prompt: 'Review origin/main',
agentType: 'codex'
}
},
'conn-1'
)
expect(server.getStatusSnapshot()).toEqual(before)
expect(pushed).not.toHaveBeenCalled()
server.stop()
})
})
Loading
Loading