Skip to content

Commit 63563e1

Browse files
fix(server): a failed task read fails the coalesced delivery before dispatch
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a23949f commit 63563e1

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

‎apps/server/src/scheduledTasks/ScheduledTaskService.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,13 +2330,9 @@ export const layer = Layer.effect(
23302330
yield* remove;
23312331
continue;
23322332
}
2333-
// A running row was already sent, so recovery keeps the prompt it was sent with.
2334-
// A failed load falls back to the snapshot and runTask fails the delivery.
2335-
const current =
2336-
entry.state === "dispatching"
2337-
? yield* findTask(taskId).pipe(Effect.orElseSucceed(() => null))
2338-
: null;
23392333
const prepared = yield* Effect.gen(function* () {
2334+
// A running row was already sent, so recovery keeps the prompt it was sent with.
2335+
const current = entry.state === "dispatching" ? yield* findTask(taskId) : null;
23402336
const snapshot = yield* decodePendingTask(entry.task_json);
23412337
// The snapshot keeps the identity runTask checks; the prompt is the one saved now.
23422338
const task =

‎apps/server/src/scheduledTasks/ScheduledTaskService.webhook.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,8 +1121,11 @@ it.effect("a coalesced window fails its delivery when the task row cannot be rea
11211121
assert.equal((yield* sql`SELECT 1 FROM scheduled_task_webhook_pending`).length, 0);
11221122
const [delivery] = yield* sql<{
11231123
outcome: string;
1124-
}>`SELECT outcome FROM scheduled_task_webhook_deliveries`;
1124+
error: string | null;
1125+
}>`SELECT outcome, error FROM scheduled_task_webhook_deliveries`;
11251126
assert.equal(delivery?.outcome, "dispatch_failed");
1127+
// Failing before dispatch means a later successful read cannot send the stale snapshot.
1128+
assert.equal(delivery?.error, "The pending webhook payload could not be prepared.");
11261129
}),
11271130
{ workers },
11281131
);

0 commit comments

Comments
 (0)