Skip to content

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

address review (codex): scope missed-slot catch-up to when the reminder config last changed

Adam Eivya028ec98abed
diff --git a/server/services/meatspacePost.js b/server/services/meatspacePost.js
index 537cfb788a..b05e7f5825 100644
--- a/server/services/meatspacePost.js
+++ b/server/services/meatspacePost.js
@@ -99,6 +99,17 @@ export async function getPostConfig() {
export async function updatePostConfig(updates) {
const config = await getPostConfig();
const merged = deepMerge(config, updates);
+ if (updates?.reminder) {
+ // Stamp WHEN the reminder's enabled/time settings last changed. Read by
+ // meatspacePostReminder.js's missed-slot catch-up: a cron occurrence
+ // that fell before this timestamp happened under a DIFFERENT (possibly
+ // disabled) configuration, so replaying it after a restart would nag for
+ // a slot the current settings never actually owned — e.g. enabling the
+ // reminder for an already-past time today, then restarting later that
+ // same day, would otherwise catch up a slot the reminder wasn't even
+ // active for.
+ merged.reminder = { ...merged.reminder, updatedAt: new Date().toISOString() };
+ }
await ensureMeatspaceDir();
await atomicWrite(CONFIG_FILE, merged);
console.log(`🧪 POST config updated`);
diff --git a/server/services/meatspacePost.test.js b/server/services/meatspacePost.test.js
index a0e94d019f..587362fddd 100644
--- a/server/services/meatspacePost.test.js
+++ b/server/services/meatspacePost.test.js
@@ -573,7 +573,28 @@ describe('updatePostConfig — postConfigEvents', () => {
config: merged,
updates: { reminder: { enabled: true, time: '09:00' } },
});
- expect(merged.reminder).toEqual({ enabled: true, time: '09:00' });
+ expect(merged.reminder).toMatchObject({ enabled: true, time: '09:00' });
+ });
+
+ // Regression (codex review finding on #2015): the missed-slot catch-up in
+ // meatspacePostReminder.js needs to know WHEN the reminder's settings last
+ // changed, so it can tell "a slot that happened under the current config"
+ // apart from "a slot that happened before the user even set this up."
+ it('stamps reminder.updatedAt whenever the reminder slice is part of the patch', async () => {
+ const before = Date.now();
+ const merged = await updatePostConfig({ reminder: { enabled: true, time: '09:00' } });
+ const after = Date.now();
+
+ expect(merged.reminder.updatedAt).toBeDefined();
+ const stampedMs = new Date(merged.reminder.updatedAt).getTime();
+ expect(stampedMs).toBeGreaterThanOrEqual(before);
+ expect(stampedMs).toBeLessThanOrEqual(after);
+ });
+
+ it('does not stamp reminder.updatedAt for a patch that does not touch the reminder slice', async () => {
+ const merged = await updatePostConfig({ adaptive: { enabled: true } });
+
+ expect(merged.reminder.updatedAt).toBeUndefined();
});
it('still emits for updates unrelated to the reminder — subscribers decide what to react to', async () => {
diff --git a/server/services/meatspacePostReminder.js b/server/services/meatspacePostReminder.js
index 1f3bdb9d50..e4f46b2314 100644
--- a/server/services/meatspacePostReminder.js
+++ b/server/services/meatspacePostReminder.js
@@ -130,17 +130,33 @@ export async function firePostReminderIfIncomplete() {
* 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 on a rare false-positive gate.
+ * calendar day removes that ambiguity outright.
+ *
+ * `reminderUpdatedAt` (from `config.reminder.updatedAt`, stamped by
+ * updatePostConfig whenever the reminder slice is saved) additionally guards
+ * against replaying a slot the CURRENT settings never actually owned: if the
+ * user enables the reminder (or changes its time) for an already-past time
+ * today, then the server happens to restart later that same day, the most
+ * recent occurrence still falls on today's local day — but it happened
+ * before this configuration took effect, under whatever settings (possibly
+ * disabled) were active at that moment. Absent `updatedAt` (older on-disk
+ * configs saved before this field existed), skip the guard rather than
+ * blocking catch-up outright — there's no information to restrict it, and
+ * that's the existing behavior those installs already have.
+ * `firePostReminderIfIncomplete` itself is idempotent (completedToday +
+ * already-notified-today guards), so calling it here is safe even on a rare
+ * false-positive gate.
*/
-async function catchUpMissedSlot(cron, timezone) {
+async function catchUpMissedSlot(cron, timezone, reminderUpdatedAt) {
const now = Date.now();
const prevRun = parseCronToPrevRun(cron, new Date(now), timezone);
if (!prevRun) return;
+ const prevRunMs = prevRun.getTime();
const todayStr = todayInTimezone(timezone);
- if (!isOnLocalDay(prevRun.getTime(), timezone, todayStr)) return;
+ if (!isOnLocalDay(prevRunMs, timezone, todayStr)) return;
+
+ if (reminderUpdatedAt && prevRunMs < new Date(reminderUpdatedAt).getTime()) return;
console.log(`🔔 POST reminder: missed slot detected (${prevRun.toISOString()}) — catching up now`);
await firePostReminderIfIncomplete();
@@ -160,7 +176,7 @@ async function catchUpMissedSlot(cron, timezone) {
*/
export async function registerPostReminderSchedule({ catchUpMissedSlot: shouldCatchUp = false } = {}) {
const config = await getPostConfig();
- const { enabled, time } = config.reminder || {};
+ const { enabled, time, updatedAt } = config.reminder || {};
if (!enabled) {
cancel(POST_REMINDER_EVENT_ID);
@@ -189,7 +205,7 @@ export async function registerPostReminderSchedule({ catchUpMissedSlot: shouldCa
console.log(`🔔 POST reminder: registered daily at ${time} (${timezone})`);
if (shouldCatchUp) {
- await catchUpMissedSlot(cron, timezone);
+ await catchUpMissedSlot(cron, timezone, updatedAt);
}
}
diff --git a/server/services/meatspacePostReminder.test.js b/server/services/meatspacePostReminder.test.js
index 28dd0d788c..1ce46a82ac 100644
--- a/server/services/meatspacePostReminder.test.js
+++ b/server/services/meatspacePostReminder.test.js
@@ -200,6 +200,56 @@ describe('registerPostReminderSchedule', () => {
expect(getPostSessions).not.toHaveBeenCalled();
});
+ // Regression (codex review finding): a same-day missed slot is only a
+ // genuine miss if the CURRENT reminder settings actually owned it. If the
+ // user enables the reminder (or changes its time) for an already-past
+ // time today, then the server restarts later that same day for unrelated
+ // reasons, the slot still falls on today's local day — but it happened
+ // before this configuration existed, so replaying it would nag for a
+ // period the reminder wasn't even active for.
+ it('does not fire when the missed slot occurred before the reminder config was last saved', async () => {
+ getPostConfig.mockResolvedValue({
+ reminder: { enabled: true, time: '09:00', updatedAt: '2026-07-01T10:00:00.000Z' }
+ });
+ todayInTimezone.mockReturnValue('2026-07-01');
+ getLocalParts.mockReturnValue({ year: 2026, month: 7, day: 1 });
+ // The 09:00 slot happened BEFORE the 10:00 config save.
+ parseCronToPrevRun.mockReturnValue(new Date('2026-07-01T09:00:00.000Z'));
+
+ await registerPostReminderSchedule({ catchUpMissedSlot: true });
+
+ expect(addNotification).not.toHaveBeenCalled();
+ expect(getPostSessions).not.toHaveBeenCalled();
+ });
+
+ it('fires when the missed slot occurred after the reminder config was last saved', async () => {
+ getPostConfig.mockResolvedValue({
+ reminder: { enabled: true, time: '09:00', updatedAt: '2026-06-01T00:00:00.000Z' }
+ });
+ getPostSessions.mockResolvedValue([]);
+ todayInTimezone.mockReturnValue('2026-07-01');
+ getLocalParts.mockReturnValue({ year: 2026, month: 7, day: 1 });
+ parseCronToPrevRun.mockReturnValue(new Date('2026-07-01T09:00:00.000Z'));
+
+ await registerPostReminderSchedule({ catchUpMissedSlot: true });
+
+ expect(addNotification).toHaveBeenCalledTimes(1);
+ });
+
+ it('fires regardless of slot timing when the config predates the updatedAt field (backward compat)', async () => {
+ // Older on-disk configs saved before this field existed have no
+ // `updatedAt` at all — absence must not block catch-up outright.
+ getPostConfig.mockResolvedValue({ reminder: { enabled: true, time: '09:00' } });
+ getPostSessions.mockResolvedValue([]);
+ todayInTimezone.mockReturnValue('2026-07-01');
+ getLocalParts.mockReturnValue({ year: 2026, month: 7, day: 1 });
+ parseCronToPrevRun.mockReturnValue(new Date('2026-07-01T09:00:00.000Z'));
+
+ await registerPostReminderSchedule({ catchUpMissedSlot: true });
+
+ expect(addNotification).toHaveBeenCalledTimes(1);
+ });
+
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');