Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): gate missed-slot catch-up on today's local calendar day
Adam Eivy02a423363db8
diff --git a/server/services/meatspacePostReminder.js b/server/services/meatspacePostReminder.jsindex e895a3a4ba..1f3bdb9d50 100644--- a/server/services/meatspacePostReminder.js+++ b/server/services/meatspacePostReminder.js@@ -121,25 +121,29 @@ export async function firePostReminderIfIncomplete() {* If today's cron slot has already elapsed (the server was down or just* booted after the scheduled minute), fire the reminder immediately instead* of waiting for tomorrow's tick. Mirrors taskSchedule.js's- * `parseCronToPrevRun`-based catch-up: bound the lookback to ONE cron period- * (the occurrence before the most recent one) so this only ever replays- * "today's" missed slot, never a backlog. `firePostReminderIfIncomplete`+ * `parseCronToPrevRun`-based catch-up, but — unlike a repeating task with no+ * fixed time-of-day — a daily HH:MM reminder's "was a slot missed" question+ * has an exact answer: is the most recent past occurrence ON TODAY'S LOCAL+ * CALENDAR DAY? `parseCronToPrevRun` always returns SOME past occurrence+ * (typically "last night's", which already fired normally) whenever `now` is+ * earlier in the day than the configured time — a bound expressed only in+ * elapsed time (e.g. "within one cron period") can't distinguish "yesterday's+ * slot, already handled" from "today's slot, genuinely missed," and would+ * wrongly fire on every boot before the scheduled hour. Gating on the local+ * calendar day removes that ambiguity outright. `firePostReminderIfIncomplete`* itself is idempotent (completedToday + already-notified-today guards), so- * calling it here is safe even when nothing was actually missed.+ * calling it here is safe even on a rare false-positive gate.*/async function catchUpMissedSlot(cron, timezone) {const now = Date.now();const prevRun = parseCronToPrevRun(cron, new Date(now), timezone);if (!prevRun) return;- const prevRunMs = prevRun.getTime();- const beforePrev = parseCronToPrevRun(cron, new Date(prevRunMs - 60_000), timezone);- const lookbackBound = beforePrev ? beforePrev.getTime() : 0;+ const todayStr = todayInTimezone(timezone);+ if (!isOnLocalDay(prevRun.getTime(), timezone, todayStr)) return;- if (prevRunMs > lookbackBound && prevRunMs <= now) {- console.log(`🔔 POST reminder: missed slot detected (${prevRun.toISOString()}) — catching up now`);- await firePostReminderIfIncomplete();- }+ console.log(`🔔 POST reminder: missed slot detected (${prevRun.toISOString()}) — catching up now`);+ await firePostReminderIfIncomplete();}/**diff --git a/server/services/meatspacePostReminder.test.js b/server/services/meatspacePostReminder.test.jsindex f9a1600d04..28dd0d788c 100644--- a/server/services/meatspacePostReminder.test.js+++ b/server/services/meatspacePostReminder.test.js@@ -162,16 +162,15 @@ describe('registerPostReminderSchedule', () => {getPostConfig.mockResolvedValue({ reminder: { enabled: true, time: '09:00' } });getPostSessions.mockResolvedValue([]);todayInTimezone.mockReturnValue('2026-07-01');- const missedSlot = new Date('2026-07-01T09:00:00.000Z');- const dayBefore = new Date('2026-06-30T09:00:00.000Z');- parseCronToPrevRun.mockReturnValueOnce(missedSlot).mockReturnValueOnce(dayBefore);+ getLocalParts.mockReturnValue({ year: 2026, month: 7, day: 1 }); // prevRun falls on today+ parseCronToPrevRun.mockReturnValue(new Date('2026-07-01T09:00:00.000Z'));await registerPostReminderSchedule({ catchUpMissedSlot: true });expect(addNotification).toHaveBeenCalledTimes(1);});- it('does not fire when there is no elapsed occurrence within the lookback bound', async () => {+ it('does not fire when there is no prior cron occurrence at all', async () => {getPostConfig.mockResolvedValue({ reminder: { enabled: true, time: '09:00' } });parseCronToPrevRun.mockReturnValue(null);@@ -181,14 +180,32 @@ describe('registerPostReminderSchedule', () => {expect(getPostSessions).not.toHaveBeenCalled();});+ // Regression: parseCronToPrevRun always returns SOME past occurrence+ // whenever `now` is earlier in the day than the configured time — e.g. a+ // 09:00 reminder restarted at 07:00 resolves "the most recent past+ // occurrence" to YESTERDAY's 09:00, which already fired normally last+ // night. Without gating on the local calendar day, catchUpMissedSlot+ // would wrongly treat that as a missed slot and fire a spurious reminder+ // on every boot before the scheduled hour — not just on genuine downtime+ // spanning the scheduled minute.+ it('does not fire when the most recent past occurrence is from a prior day', async () => {+ getPostConfig.mockResolvedValue({ reminder: { enabled: true, time: '09:00' } });+ todayInTimezone.mockReturnValue('2026-07-01');+ getLocalParts.mockReturnValue({ year: 2026, month: 6, day: 30 }); // yesterday, not today+ parseCronToPrevRun.mockReturnValue(new Date('2026-06-30T09:00:00.000Z'));++ await registerPostReminderSchedule({ catchUpMissedSlot: true });++ expect(addNotification).not.toHaveBeenCalled();+ expect(getPostSessions).not.toHaveBeenCalled();+ });+it('is idempotent — firePostReminderIfIncomplete still skips when today is already complete', async () => {getPostConfig.mockResolvedValue({ reminder: { enabled: true, time: '09:00' } });todayInTimezone.mockReturnValue('2026-07-01');getPostSessions.mockResolvedValue([{ startedAt: '2026-07-01T15:00:00.000Z' }]);getLocalParts.mockReturnValue({ year: 2026, month: 7, day: 1 });- const missedSlot = new Date('2026-07-01T09:00:00.000Z');- const dayBefore = new Date('2026-06-30T09:00:00.000Z');- parseCronToPrevRun.mockReturnValueOnce(missedSlot).mockReturnValueOnce(dayBefore);+ parseCronToPrevRun.mockReturnValue(new Date('2026-07-01T09:00:00.000Z'));await registerPostReminderSchedule({ catchUpMissedSlot: true });