fix: 收敛 stale thread 和 tool-call 错误归因
This commit is contained in:
+20
-14
@@ -452,19 +452,8 @@ async function runCodexStdioTurnWithSession(options: CodexStdioTurnOptions, sess
|
||||
emitEvent({ type: "backend_status", payload: { phase: "thread/resume:completed", threadId } });
|
||||
} catch (error) {
|
||||
const failure = normalizeFailure(error);
|
||||
if (!isStaleThreadResumeFailure(failure)) throw error;
|
||||
emitEvent({
|
||||
type: "backend_status",
|
||||
payload: {
|
||||
phase: "thread/resume:stale-thread-fallback",
|
||||
requestedThreadId: options.threadId,
|
||||
failureKind: failure.failureKind,
|
||||
message: failure.message,
|
||||
fallback: "thread/start",
|
||||
valuesPrinted: false,
|
||||
},
|
||||
});
|
||||
threadId = await startThread("thread/start:after-stale-resume");
|
||||
if (!isMissingRolloutThreadResumeFailure(failure)) throw error;
|
||||
throw threadResumeFailure(options.threadId, failure);
|
||||
}
|
||||
} else {
|
||||
threadId = await startThread();
|
||||
@@ -920,12 +909,27 @@ function normalizeFailure(error: unknown): CodexStdioFailure {
|
||||
return new CodexStdioFailure(classifyMessageFailureKind(message, "backend-protocol-error"), message, "codex-stdio");
|
||||
}
|
||||
|
||||
function isStaleThreadResumeFailure(error: CodexStdioFailure): boolean {
|
||||
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",
|
||||
`codex app-server thread/resume failed for existing thread: ${error.message}`,
|
||||
"thread/resume",
|
||||
{
|
||||
requestedThreadId: threadId,
|
||||
originalFailureKind: error.failureKind,
|
||||
originalPhase: error.phase,
|
||||
originalDetails: redactJson(error.details),
|
||||
valuesPrinted: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function classifyCodexErrorRecord(error: JsonRecord, fallback: FailureKind): FailureKind {
|
||||
const parts: string[] = [];
|
||||
if (typeof error.message === "string") parts.push(error.message);
|
||||
@@ -937,6 +941,8 @@ function classifyCodexErrorRecord(error: JsonRecord, fallback: FailureKind): Fai
|
||||
|
||||
function classifyMessageFailureKind(message: string, fallback: FailureKind): FailureKind {
|
||||
const text = String(message || "").toLowerCase();
|
||||
if (/invalid[_ -]?prompt/u.test(text) && /invalid function arguments json string|tool_call_id/u.test(text)) return "provider-invalid-tool-call";
|
||||
if (/invalid function arguments json string/u.test(text)) return "provider-invalid-tool-call";
|
||||
if (/rate.?limit|too many requests|\b429\b/u.test(text)) return "provider-rate-limited";
|
||||
if (/\b401\b|\b403\b|unauthori[sz]ed|forbidden|invalid api key|authentication|auth failed|oauth|access token/u.test(text)) return "provider-auth-failed";
|
||||
if (isProviderUnavailableMessage(text)) return "provider-unavailable";
|
||||
|
||||
Reference in New Issue
Block a user