refactor(subagent-codex): centralize cancellation settlement
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user