fix(subagent): preserve terminal turn precedence
This commit is contained in:
1 parent
d5397cbc29
commit
b032097c2a
2 files changed
+21
-12
No files matched your search
@@ -331,10 +331,7 @@ export async function startCodexRun(
|
||||
const result: Promise<SubagentResult> = settleRunResult({
|
||||
attempt: async () => {
|
||||
try {
|
||||
const terminal = await Promise.race([
|
||||
wire.runTurn(texts, runAbort.signal),
|
||||
processFailure,
|
||||
])
|
||||
const terminal = await wire.runTurn(texts, runAbort.signal)
|
||||
if (terminal.stopReason === 'completed') return terminal
|
||||
const facts = wire.collectFailure()
|
||||
return { ...terminal, diagnostic: recordFailureDiagnostic(facts) }
|
||||
@@ -357,15 +354,11 @@ export async function startCodexRun(
|
||||
// The wire failure remains authoritative when exit observation fails.
|
||||
}
|
||||
}
|
||||
const facts = error instanceof CodexRunFailure
|
||||
? error.facts
|
||||
: endedBeforeTerminal && processFailureFacts !== undefined
|
||||
const facts = endedBeforeTerminal && processFailureFacts !== undefined
|
||||
? processFailureFacts
|
||||
: wire.collectFailure()
|
||||
recordFailureDiagnostic(facts)
|
||||
throw error instanceof CodexRunFailure
|
||||
? error
|
||||
: new CodexRunFailure(facts, thrown(error))
|
||||
throw new CodexRunFailure(facts, thrown(error))
|
||||
}
|
||||
},
|
||||
collectOutput,
|
||||
|
||||
@@ -1612,6 +1612,7 @@ describe('run lifecycle and quiescence', () => {
|
||||
onError: (error) => { errors.push(error.message) },
|
||||
})
|
||||
child.settle(outcome)
|
||||
child.fromChild.emit('end')
|
||||
await expect(run.result).resolves.toEqual({
|
||||
output: [],
|
||||
diagnostic: expectedFailureDiagnostic('process', 'process-exit', {
|
||||
@@ -1649,8 +1650,7 @@ describe('run lifecycle and quiescence', () => {
|
||||
child.peer.send(turnCompleted('failed', 'turn-1', 'thread-1', {
|
||||
codexErrorInfo: 'other',
|
||||
}))
|
||||
await nextTask()
|
||||
child.fromChild.emit('end')
|
||||
child.fromChild.end()
|
||||
child.settle({ exitCode: 17, signal: 'SIGABRT' })
|
||||
await expect(run.result).resolves.toEqual({
|
||||
output: [],
|
||||
@@ -1659,6 +1659,22 @@ describe('run lifecycle and quiescence', () => {
|
||||
})
|
||||
await run.dispose().catch(() => {})
|
||||
}
|
||||
{
|
||||
const child = fakeChild({ exitOnTerminate: false })
|
||||
const { run, turnStart } = await publishRun(child)
|
||||
child.peer.respond(turnStart, { turn: { id: 'turn-1' } })
|
||||
child.peer.send(
|
||||
agentMessage('answer', 'final_answer'),
|
||||
turnCompleted('completed'),
|
||||
)
|
||||
child.fromChild.end()
|
||||
child.settle({ exitCode: 17, signal: 'SIGABRT' })
|
||||
await expect(run.result).resolves.toEqual({
|
||||
output: [{ type: 'text', text: 'answer' }],
|
||||
stopReason: 'completed',
|
||||
})
|
||||
await run.dispose().catch(() => {})
|
||||
}
|
||||
{
|
||||
const child = fakeChild()
|
||||
const { run, turnStart } = await publishRun(child, undefined, {
|
||||
|
||||
Reference in new issue
Block a user