Skip to content

Commit 415ed0f

Browse files
fix(server): keep old failures from waking snoozed V2 threads (#9903)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 26a48b0 commit 415ed0f

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadSettlementService.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,36 @@ describe("isAutoSettlementCandidate", () => {
130130
snoozedAt: at(-60 * 60 * 1_000),
131131
});
132132
expect(isAutoSettlementCandidate(snoozed, NOW_MS)).toBe(false);
133-
expect(isAutoSettlementCandidate(shell({ ...snoozed, status: "failed" }), NOW_MS)).toBe(true);
133+
expect(
134+
isAutoSettlementCandidate(
135+
shell({ ...snoozed, status: "failed", latestRunCompletedAt: at(-30 * 60 * 1_000) }),
136+
NOW_MS,
137+
),
138+
).toBe(true);
134139
expect(
135140
isAutoSettlementCandidate(
136141
shell({ ...snoozed, latestRunCompletedAt: at(-30 * 60 * 1_000) }),
137142
NOW_MS,
138143
),
139144
).toBe(true);
145+
expect(
146+
isAutoSettlementCandidate(
147+
shell({ ...snoozed, status: "failed", latestRunCompletedAt: at(-2 * 60 * 60 * 1_000) }),
148+
NOW_MS,
149+
),
150+
).toBe(false);
151+
expect(
152+
isAutoSettlementCandidate(
153+
shell({ ...snoozed, status: "failed", latestRunCompletedAt: snoozed.snoozedAt }),
154+
NOW_MS,
155+
),
156+
).toBe(false);
157+
expect(
158+
isAutoSettlementCandidate(
159+
shell({ ...snoozed, status: "failed", latestRunCompletedAt: null }),
160+
NOW_MS,
161+
),
162+
).toBe(false);
140163
// Expired snooze is no longer a park.
141164
expect(isAutoSettlementCandidate(shell({ ...snoozed, snoozedUntil: at(-1) }), NOW_MS)).toBe(
142165
true,

‎apps/server/src/orchestration-v2/ThreadSettlementService.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export function isAutoSettlementCandidate(
112112
// one still parked on its wake time keeps its stronger statement.
113113
const snoozedAtMs = toMillis(thread.snoozedAt);
114114
const completedAtMs = toMillis(thread.latestRunCompletedAt);
115-
const wokeOnError = thread.status === "failed";
115+
const wokeOnError =
116+
thread.status === "failed" &&
117+
(snoozedAtMs === null || (completedAtMs !== null && completedAtMs > snoozedAtMs));
116118
const wokeOnCompletion =
117119
snoozedAtMs !== null && completedAtMs !== null && completedAtMs > snoozedAtMs;
118120
return wokeOnError || wokeOnCompletion;

0 commit comments

Comments
 (0)