fix: preserve code agent sessions after turn failures

This commit is contained in:
Codex
2026-06-03 00:28:40 +08:00
parent 4187c1b0ce
commit 0d4f5ef098
14 changed files with 72 additions and 52 deletions
@@ -18,7 +18,7 @@ export const CODE_AGENT_SESSION_STATUS_ALIASES = Object.freeze({
});
const ACTIVE_LIFECYCLE_STATUSES = new Set(["creating", "ready", "busy", "idle"]);
const TERMINAL_LIFECYCLE_STATUSES = new Set(["interrupted", "expired", "failed"]);
const TERMINAL_LIFECYCLE_STATUSES = new Set(["interrupted", "expired"]);
export function normalizeCodeAgentSessionLifecycleStatus(value, { fallback = null } = {}) {
const text = String(value ?? "").trim().toLowerCase();
@@ -75,7 +75,7 @@ export function codeAgentSessionLifecycleSummary(input = {}) {
(gateBlocked && !concreteLifecycleBlock);
if ((fallbackUsed || degraded) && !hasSession) status = "failed";
const requiresNewSession = status ? TERMINAL_LIFECYCLE_STATUSES.has(status) : degraded || fallbackUsed;
const reusable = status ? ACTIVE_LIFECYCLE_STATUSES.has(status) && status !== "creating" && degraded !== true : false;
const reusable = status ? ((ACTIVE_LIFECYCLE_STATUSES.has(status) && status !== "creating") || status === "failed") && degraded !== true : false;
const newSession = reused === false || (hasSession && !reused && !requiresNewSession);
const reasonCode = firstText(
input.degradationReasonCode,
@@ -171,8 +171,8 @@ function lifecyclePresentation({ status, rawStatus, reused, newSession, degraded
if (status === "failed") {
return {
label: "会话失败",
action: "new_session",
userMessage: "当前 Code Agent session 已失败,需重新发送建立新会话。"
action: "continue",
userMessage: "当前 Code Agent turn 已失败;session/thread 已保留,可继续发送下一条消息。"
};
}
if (status === "interrupted") {