fix: 统一 AgentRun threadId 连续性
This commit is contained in:
@@ -446,25 +446,9 @@ async function runCodexStdioTurnWithSession(options: CodexStdioTurnOptions, sess
|
||||
};
|
||||
|
||||
if (options.threadId) {
|
||||
try {
|
||||
const threadResponse = requireResponseRecord(await client.request("thread/resume", withOptionalModel({ threadId: options.threadId, cwd: options.cwd, approvalPolicy: options.approvalPolicy, sandbox: options.sandbox }, options.model), requestTimeoutMs), "thread/resume");
|
||||
threadId = requireNestedId(threadResponse, "thread/resume", "thread");
|
||||
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",
|
||||
},
|
||||
});
|
||||
threadId = await startThread("thread/start:after-stale-resume");
|
||||
}
|
||||
const threadResponse = requireResponseRecord(await client.request("thread/resume", withOptionalModel({ threadId: options.threadId, cwd: options.cwd, approvalPolicy: options.approvalPolicy, sandbox: options.sandbox }, options.model), requestTimeoutMs), "thread/resume");
|
||||
threadId = requireNestedId(threadResponse, "thread/resume", "thread");
|
||||
emitEvent({ type: "backend_status", payload: { phase: "thread/resume:completed", threadId } });
|
||||
} else {
|
||||
threadId = await startThread();
|
||||
}
|
||||
@@ -884,12 +868,6 @@ function normalizeFailure(error: unknown): CodexStdioFailure {
|
||||
return new CodexStdioFailure(classifyMessageFailureKind(message, "backend-protocol-error"), message, "codex-stdio");
|
||||
}
|
||||
|
||||
function isStaleThreadResumeFailure(error: CodexStdioFailure): boolean {
|
||||
if (error.phase !== "response:thread/resume") return false;
|
||||
const text = `${error.message}\n${JSON.stringify(error.details)}`.toLowerCase();
|
||||
return /no rollout found for thread id/u.test(text);
|
||||
}
|
||||
|
||||
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