fix: fail stale codex thread resume
This commit is contained in:
@@ -452,9 +452,7 @@ async function runCodexStdioTurnWithSession(options: CodexStdioTurnOptions, sess
|
||||
emitEvent({ type: "backend_status", payload: { phase: "thread/resume:completed", threadId } });
|
||||
} catch (error) {
|
||||
const failure = normalizeFailure(error);
|
||||
if (!isMissingRolloutThreadResumeFailure(failure)) throw error;
|
||||
emitEvent({ type: "backend_status", payload: threadResumeNonResumablePayload(options.threadId, failure) });
|
||||
threadId = await startThread("thread/replacement-start");
|
||||
throw threadResumeFailure(options.threadId, failure);
|
||||
}
|
||||
} else {
|
||||
threadId = await startThread();
|
||||
@@ -910,12 +908,6 @@ function normalizeFailure(error: unknown): CodexStdioFailure {
|
||||
return new CodexStdioFailure(classifyMessageFailureKind(message, "backend-protocol-error"), message, "codex-stdio");
|
||||
}
|
||||
|
||||
function isMissingRolloutThreadResumeFailure(error: CodexStdioFailure): boolean {
|
||||
if (error.phase !== "response:thread/resume") return false;
|
||||
const text = `${error.message}\n${JSON.stringify(error.details)}`.toLowerCase();
|
||||
return text.includes("no rollout found for thread id");
|
||||
}
|
||||
|
||||
function threadResumeFailure(threadId: string, error: CodexStdioFailure): CodexStdioFailure {
|
||||
return new CodexStdioFailure(
|
||||
"thread-resume-failed",
|
||||
@@ -931,18 +923,6 @@ function threadResumeFailure(threadId: string, error: CodexStdioFailure): CodexS
|
||||
);
|
||||
}
|
||||
|
||||
function threadResumeNonResumablePayload(threadId: string, error: CodexStdioFailure): JsonRecord {
|
||||
return {
|
||||
phase: "thread/resume:non-resumable",
|
||||
requestedThreadId: threadId,
|
||||
originalFailureKind: error.failureKind,
|
||||
originalPhase: error.phase,
|
||||
originalDetails: redactJson(error.details),
|
||||
replacement: "thread/start",
|
||||
valuesPrinted: false,
|
||||
};
|
||||
}
|
||||
|
||||
function classifyCodexErrorRecord(error: JsonRecord, fallback: FailureKind): FailureKind {
|
||||
const parts: string[] = [];
|
||||
if (typeof error.message === "string") parts.push(error.message);
|
||||
|
||||
Reference in New Issue
Block a user