TypeScript
fix(server): an interrupted run no longer starts the settle timer on a snoozed thread (#17789)
Evolve Performance293938b91a6a
diff --git a/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts b/apps/server/src/orchestration-v2/ThreadSettlementService.test.tsindex 4ad315427cd..b22ff6a311e 100644--- a/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts+++ b/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts@@ -177,10 +177,17 @@ describe("isAutoSettlementCandidate", () => {).toBe(true);expect(ThreadSettlementService.isAutoSettlementCandidate(- shell({ ...snoozed, latestRunCompletedAt: at(-30 * 60 * 1_000) }),+ shell({ ...snoozed, status: "completed", latestRunCompletedAt: at(-30 * 60 * 1_000) }),NOW_MS,),).toBe(true);+ // An interrupted run leaves the thread snoozed, as the sidebar shows it.+ expect(+ ThreadSettlementService.isAutoSettlementCandidate(+ shell({ ...snoozed, status: "interrupted", latestRunCompletedAt: at(-30 * 60 * 1_000) }),+ NOW_MS,+ ),+ ).toBe(false);expect(ThreadSettlementService.isAutoSettlementCandidate(shell({ ...snoozed, status: "failed", latestRunCompletedAt: at(-2 * 60 * 60 * 1_000) }),diff --git a/apps/server/src/orchestration-v2/ThreadSettlementService.ts b/apps/server/src/orchestration-v2/ThreadSettlementService.tsindex d6cfe2caec4..64a54e92a59 100644--- a/apps/server/src/orchestration-v2/ThreadSettlementService.ts+++ b/apps/server/src/orchestration-v2/ThreadSettlementService.ts@@ -166,16 +166,8 @@ export function isAutoSettlementCandidate(if (thread.activityRunStatus != null) return false;if (backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? [])) return false;if (threadHasQueuedTurnStart(thread, nowMs)) return false;- const snoozedUntilMs = toMillis(thread.snoozedUntil);- if (snoozedUntilMs === null || snoozedUntilMs <= nowMs) return true;- const snoozedAtMs = toMillis(thread.snoozedAt);- const completedAtMs = toMillis(thread.latestRunCompletedAt);- const wokeOnError =- thread.status === "failed" &&- (snoozedAtMs === null || (completedAtMs !== null && completedAtMs > snoozedAtMs));- const wokeOnCompletion =- snoozedAtMs !== null && completedAtMs !== null && completedAtMs > snoozedAtMs;- return wokeOnError || wokeOnCompletion;+ // Interrupted runs must keep the same snooze protection the sidebar shows.+ return !isSnoozed(thread, nowMs);}/**