Merge pull request #100 from pikasTech/fix/issue20-steer-terminal-rejection

Fix compact terminal codex steer rejection
This commit is contained in:
Lyon
2026-05-23 15:59:08 +08:00
committed by GitHub
5 changed files with 94 additions and 6 deletions
+50 -2
View File
@@ -621,11 +621,57 @@ function classifySteerFailure(response: unknown, targetPath: string, stableProxy
};
}
function unwrapSteerResponse(response: unknown, targetPath: string, stableProxyPath: string, rawProxyEquivalent: string): { ok: true; upstream: { ok: unknown; status: unknown }; body: Record<string, unknown> } | { ok: false; diagnostics: ClassifiedCodexSteerError } {
function unwrapSteerResponse(response: unknown, targetPath: string, stableProxyPath: string, rawProxyEquivalent: string): { ok: true; upstream: { ok: unknown; status: unknown }; body: Record<string, unknown> } | { ok: false; diagnostics: ClassifiedCodexSteerError; rawResponse: unknown } {
const record = asRecord(response);
const body = responseBody(record);
if (record?.ok === true && body?.ok === true) return { ok: true, upstream: { ok: record.ok, status: record.status }, body };
return { ok: false, diagnostics: classifySteerFailure(response, targetPath, stableProxyPath, rawProxyEquivalent) };
return { ok: false, diagnostics: classifySteerFailure(response, targetPath, stableProxyPath, rawProxyEquivalent), rawResponse: response };
}
function terminalStatusFromTask(task: Record<string, unknown> | null): string {
const direct = asString(task?.terminalStatus);
if (direct.length > 0) return direct;
const attempts = asArray(task?.attempts).map((item) => asRecord(item)).filter((item): item is Record<string, unknown> => item !== null);
for (let index = attempts.length - 1; index >= 0; index -= 1) {
const status = asString(attempts[index]?.terminalStatus);
if (status.length > 0) return status;
}
return "";
}
function compactTerminalSteerRejection(taskId: string, response: unknown): Record<string, unknown> | null {
const record = asRecord(response);
const body = responseBody(record);
const task = asRecord(body?.task);
const status = asString(task?.status);
if (!isTerminalTaskStatus(status)) return null;
const terminalStatus = terminalStatusFromTask(task);
const lastUpdate = task?.updatedAt ?? task?.finishedAt ?? null;
return {
ok: false,
steer: {
accepted: false,
reason: "task-already-terminal",
taskId,
status,
terminalStatus: terminalStatus || null,
lastUpdate,
updatedAt: task?.updatedAt ?? null,
finishedAt: task?.finishedAt ?? null,
retryable: false,
},
message: `task ${taskId} is already terminal (${status}); codex steer only applies to an active running turn`,
commands: {
show: `bun scripts/cli.ts codex task ${taskId}`,
read: `bun scripts/cli.ts codex read ${taskId}`,
followUpSubmit: `bun scripts/cli.ts codex submit --prompt-file <path> --reference-task-id ${taskId}`,
supervisor: `bun scripts/cli.ts codex tasks --view supervisor --limit ${defaultTasksLimit}`,
},
upstream: {
status: responseStatus(record),
error: asString(body?.error) || null,
},
};
}
function steerSuccessAttempt(attempt: number, durationMs: number, upstream: { ok: unknown; status: unknown }): CodexSteerAttemptSummary {
@@ -4830,6 +4876,8 @@ function codexSteerTask(taskId: string, args: string[], fetcher: CodexResponseFe
}
attempts.push(steerFailureAttempt(attempt, durationMs, response.diagnostics));
failedResponse = response;
const terminalRejection = compactTerminalSteerRejection(taskId, response.rawResponse);
if (terminalRejection !== null) return terminalRejection;
if (!shouldRetrySteerFailure(response.diagnostics, attempt, options.retryAttempts)) break;
sleepSync(options.retryDelayMs);
}