refactor(subagent-codex): centralize cancellation settlement

This commit is contained in:
pku-xht
2026-08-05 07:36:54 +08:00
parent 2e00a93eda
commit 9e91e206d4
3 changed files with 13 additions and 37 deletions
+1 -1
View File
@@ -179,7 +179,7 @@ export async function startCodexRun(
const collectOutput = (): ContentBlock[] => wire.collectOutput()
const result: Promise<SubagentResult> = settleRunResult({
attempt: () => Promise.race([
wire.runTurn(texts, runAbort.signal, () => runAbort.signal.aborted),
wire.runTurn(texts, runAbort.signal),
processFailure,
]),
collectOutput,
@@ -168,13 +168,11 @@ export class CodexAppServerWire {
* terminal notification.
* @param texts - already validated task text blocks.
* @param signal - local cancellation for the published run.
* @param cancelled - whether local cancellation has already won.
* @returns the shared subagent result.
*/
async runTurn(
texts: readonly string[],
signal: AbortSignal,
cancelled: () => boolean,
): Promise<SubagentResult> {
const completion = Promise.withResolvers<JsonObject>()
this.turnCompleted = completion
@@ -187,8 +185,6 @@ export class CodexAppServerWire {
this.commitTurnId(string(turn.id, 'turn/start turn id'))
const completed = await this.guarded(completion.promise, signal)
if (cancelled()) return { output: this.collectOutput(), stopReason: 'aborted' }
const terminal = object(completed.turn, 'turn/completed turn')
const status = terminal.status
if (isContextWindowExceeded(terminal)) {