Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(server): retry a one-shot calendar event whose dispatch failed

lmlihengdcb7faef9452
diff --git a/changelog/unreleased/2026-10-11-calendar-one-shot-retry.md b/changelog/unreleased/2026-10-11-calendar-one-shot-retry.md
new file mode 100644
index 00000000..b470f38c
--- /dev/null
+++ b/changelog/unreleased/2026-10-11-calendar-one-shot-retry.md
@@ -0,0 +1,11 @@
+# A one-shot calendar event whose dispatch failed fires again on the next pass
+
+- **Date:** 2026-10-11
+- **Type:** fix
+- **Scope:** `server`
+
+[中文版](2026-10-11-calendar-one-shot-retry.zh.md)
+
+Ported from upstream PenguinHarness (#852, commit `adfa2a19`).
+
+When a one-shot calendar event's dispatch came back skipped — no desk could be opened, or the Task could not be queued — its consumed slot is now released, so the next reconcile pass fires the event again and carries the desk notices that were re-queued with it. Before, the slot stayed consumed and the employee's ticket changes sat in the queue indefinitely, with a single dispatch error on record. The run never started in that case, so the retry cannot fire the event twice; a failure that persists shows as an `error` outcome on every pass. Periodic events are unchanged (their next slot fires regardless), and a one-shot skipped because its employee was budget-paused is still consumed without backfill. `OrgCacheRepo.markCalendarSlot` accepts `null`.
diff --git a/changelog/unreleased/2026-10-11-calendar-one-shot-retry.zh.md b/changelog/unreleased/2026-10-11-calendar-one-shot-retry.zh.md
new file mode 100644
index 00000000..e54ec1a6
--- /dev/null
+++ b/changelog/unreleased/2026-10-11-calendar-one-shot-retry.zh.md
@@ -0,0 +1,11 @@
+# 派发失败的一次性日程项在下一轮重新触发
+
+- **Date:** 2026-10-11
+- **Type:** fix
+- **Scope:** `server`
+
+[English](2026-10-11-calendar-one-shot-retry.md)
+
+移植自上游 PenguinHarness(#852,提交 `adfa2a19`)。
+
+一次性日程项的派发返回 skipped——开不出工位,或 Task 无法入队——时,已消耗的时间槽现在会被释放,于是下一轮对账重新触发该事件,并带上随之重新入队的工位通知。此前该时间槽保持已消耗,员工的工单变化无限期留在队列里,只记下一次派发错误。这种情况下运行从未开始,重试不会让事件触发两次;持续的失败则在每一轮都以 `error` 结果显露出来。周期性日程项不变(下一槽照常触发);因员工被预算暂停而跳过的一次性日程项仍按原规则消耗、不补发。`OrgCacheRepo.markCalendarSlot` 接受 `null`。
diff --git a/changelog/unreleased/2026-10-11-follow-up-queue-cap.md b/changelog/unreleased/2026-10-11-follow-up-queue-cap.md
index f051ab90..e77ba6a8 100644
--- a/changelog/unreleased/2026-10-11-follow-up-queue-cap.md
+++ b/changelog/unreleased/2026-10-11-follow-up-queue-cap.md
@@ -10,4 +10,4 @@ Ported from upstream PenguinHarness (#853, commit `092a595c`).
`POST /api/sessions/:sessionId/tasks` with `queueIfBusy` now refuses the seventeenth queued follow-up with `429 queue_full` instead of enqueuing without bound; the cap is `FOLLOW_UP_QUEUE_LIMIT` (16) per Session. The paths that always ask to queue — an organization's channel mention, or a calendar dispatch to a busy desk — record the refusal as `org_dispatch_failed` and move on (a periodic calendar event fires again at its next slot), so a mention storm or an @all fan-out no longer grows a desk's queue without limit and replays every entry as a model call. The `409 task_in_progress` answer without `queueIfBusy` is unchanged, and draining one entry frees one slot.
-One difference from upstream's entry: this fork has not ported #852 yet, so a **one-shot** calendar event whose dispatch is refused still consumes its slot rather than retrying — see `docs/FORK-PROGRESS.md`.
+One difference from upstream's entry, as of this change: this fork had not ported #852 yet, so a **one-shot** calendar event whose dispatch is refused still consumed its slot rather than retrying. That port has since landed — see `2026-10-11-calendar-one-shot-retry.md`.
diff --git a/packages/server/src/db/repos/organizations.ts b/packages/server/src/db/repos/organizations.ts
index 01cbd698..4ccb8e1c 100644
--- a/packages/server/src/db/repos/organizations.ts
+++ b/packages/server/src/db/repos/organizations.ts
@@ -347,7 +347,7 @@ export class OrgCacheRepo implements OrgCache {
orgId: string,
agentId: string,
name: string,
- slotMs: number,
+ slotMs: number | null,
): void {
this.db
.prepare(
diff --git a/packages/server/src/runtime/organization/reconcile.ts b/packages/server/src/runtime/organization/reconcile.ts
index e7632080..dac0ae13 100644
--- a/packages/server/src/runtime/organization/reconcile.ts
+++ b/packages/server/src/runtime/organization/reconcile.ts
@@ -355,6 +355,21 @@ async function reconcileCalendar(
// back on the queue in their order, so the slot that does fire still carries them.
for (const row of notices) deps.cache.queueDeskNotice(row);
mark("error");
+ // A one-shot event unwinds its consumed slot, or the failure would be the last word:
+ // this dispatch is the only thing that drains the desk notices just re-queued, and a
+ // consumed one-shot slot never comes again. Retrying is safe — the run never started —
+ // and a persistent failure keeps surfacing as mark("error") every pass instead of
+ // stranding the notices with nothing on the errors panel. A periodic event needs no
+ // unwind: its next slot fires regardless.
+ if (def.periodMs === undefined) {
+ deps.cache.markCalendarSlot(
+ key.projectId,
+ key.orgId,
+ key.agentId,
+ key.name,
+ state.lastSlotMs,
+ );
+ }
continue;
}
deps.cache.markCalendarFired(
diff --git a/packages/server/test/organization-runtime.test.ts b/packages/server/test/organization-runtime.test.ts
index 462c6df9..f21ccc2e 100644
--- a/packages/server/test/organization-runtime.test.ts
+++ b/packages/server/test/organization-runtime.test.ts
@@ -1382,6 +1382,47 @@ describe("organization runtime", () => {
expect(started).toHaveLength(1);
});
+ it("retries a one-shot event whose dispatch failed, so desk notices are not stranded", async () => {
+ await createOrg();
+ await hireHr();
+ started.length = 0;
+ // A ticket for HR queues a desk notice; the calendar dispatch is the only thing that
+ // drains the queue.
+ await service.createTicket(
+ P,
+ ORG,
+ { title: "For HR", owner: `agent:${HR}` },
+ { userId: "alice" },
+ );
+ await store.writeCalendarEvent(
+ orgDir(),
+ HR,
+ "sweep",
+ serializeCalendarEvent({
+ prompt: "Sweep the board",
+ enabled: true,
+ startAt: new Date(T0 + 1000).toISOString(),
+ }),
+ );
+ await scheduler.tickOnce(); // registration pass: the start time is still ahead
+ expect(started).toHaveLength(0);
+ nowMs = T0 + 2000;
+ startFails = true;
+ await scheduler.tickOnce(); // the one-shot fires into a failing runner
+ expect(started).toHaveLength(0);
+ expect((await service.calendar(P, ORG)).events[0]!.lastOutcome).toBe("error");
+ // The slot is unwound, so the next pass fires the event and drains the notices.
+ startFails = false;
+ await scheduler.tickOnce();
+ expect(started).toHaveLength(1);
+ const parsed = parseOrgTriggerMessage(started[0]!.text);
+ expect(parsed?.rest).toContain("Sweep the board");
+ expect(parsed?.rest).toContain("For HR");
+ // The one-shot is consumed by the pass that finally succeeded — never fired twice.
+ await scheduler.tickOnce();
+ expect(started).toHaveLength(1);
+ });
+
it("queues behind a busy desk, holds while paused, and consumes silently with the switch off", async () => {
await createOrg();
await hireHr();