Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/server/src/orchestration-v2/ThreadSettlementService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,36 @@ describe("isAutoSettlementCandidate", () => {
snoozedAt: at(-60 * 60 * 1_000),
});
expect(isAutoSettlementCandidate(snoozed, NOW_MS)).toBe(false);
expect(isAutoSettlementCandidate(shell({ ...snoozed, status: "failed" }), NOW_MS)).toBe(true);
expect(
isAutoSettlementCandidate(
shell({ ...snoozed, status: "failed", latestRunCompletedAt: at(-30 * 60 * 1_000) }),
NOW_MS,
),
).toBe(true);
expect(
isAutoSettlementCandidate(
shell({ ...snoozed, latestRunCompletedAt: at(-30 * 60 * 1_000) }),
NOW_MS,
),
).toBe(true);
expect(
isAutoSettlementCandidate(
shell({ ...snoozed, status: "failed", latestRunCompletedAt: at(-2 * 60 * 60 * 1_000) }),
NOW_MS,
),
).toBe(false);
expect(
isAutoSettlementCandidate(
shell({ ...snoozed, status: "failed", latestRunCompletedAt: snoozed.snoozedAt }),
NOW_MS,
),
).toBe(false);
expect(
isAutoSettlementCandidate(
shell({ ...snoozed, status: "failed", latestRunCompletedAt: null }),
NOW_MS,
),
).toBe(false);
// Expired snooze is no longer a park.
expect(isAutoSettlementCandidate(shell({ ...snoozed, snoozedUntil: at(-1) }), NOW_MS)).toBe(
true,
Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/orchestration-v2/ThreadSettlementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export function isAutoSettlementCandidate(
// one still parked on its wake time keeps its stronger statement.
const snoozedAtMs = toMillis(thread.snoozedAt);
const completedAtMs = toMillis(thread.latestRunCompletedAt);
const wokeOnError = thread.status === "failed";
const wokeOnError =
thread.status === "failed" &&
(snoozedAtMs === null || (completedAtMs !== null && completedAtMs > snoozedAtMs));
const wokeOnCompletion =
snoozedAtMs !== null && completedAtMs !== null && completedAtMs > snoozedAtMs;
return wokeOnError || wokeOnCompletion;
Expand Down
Loading