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
fix(brain): activate scheduler on startup and fix first-run catch-up
Adam Eivye7b2c216713c
diff --git a/.changelog/v0.12.x.md b/.changelog/v0.12.x.mdindex e2f2aeb305..61a3b1aef4 100644--- a/.changelog/v0.12.x.md+++ b/.changelog/v0.12.x.md@@ -616,6 +616,10 @@ This release adds branch management and automated release workflow capabilities- `client/src/components/agents/tabs/ToolsTab.jsx` — Cooldown timer state, interval tick, formatted countdown in rate limit pills and Publish button, `.catch()` on publish handlers- `client/src/components/agents/tabs/OverviewTab.jsx` — Matching cooldown timer state and countdown display in Quick Actions rate limit pills+### Brain — Scheduler Initialization & First-Run Catch-Up+- **Scheduler activation**: Brain scheduler (`startBrainScheduler()`) was defined but never called on server startup — daily digests and weekly reviews would never run automatically. Added initialization call in `server/index.js` alongside other service initializers.+- **First-run catch-up fix**: When `lastDailyDigest` or `lastWeeklyReview` was `null` (never run before), the catch-up logic returned `false`, meaning the scheduler would only trigger if the server happened to be running at the exact scheduled minute. Now treats `null` as "never run" and catches up immediately if past the scheduled time.+## Fixes### Digital Twin — Aesthetic Taste Questionnairediff --git a/server/index.js b/server/index.jsindex 24964c95a2..b3f2ca3f8c 100644--- a/server/index.js+++ b/server/index.js@@ -46,6 +46,7 @@ import { errorEvents } from './lib/errorHandler.js';import './services/subAgentSpawner.js'; // Initialize CoS agent spawnerimport * as automationScheduler from './services/automationScheduler.js';import * as agentActionExecutor from './services/agentActionExecutor.js';+import { startBrainScheduler } from './services/brainScheduler.js';import { createAIToolkit } from 'portos-ai-toolkit/server';import { createPortOSProviderRoutes } from './routes/providers.js';import { createPortOSRunsRoutes } from './routes/runs.js';@@ -207,6 +208,9 @@ initScriptRunner().catch(err => console.error(`❌ Script runner init failed: ${automationScheduler.init().catch(err => console.error(`❌ Agent scheduler init failed: ${err.message}`));agentActionExecutor.init();+// Initialize brain scheduler for daily digests and weekly reviews+startBrainScheduler();+// 404 handlerapp.use((req, res) => {res.status(404).json({diff --git a/server/services/brainScheduler.js b/server/services/brainScheduler.jsindex a4915b85fd..92e7a66d57 100644--- a/server/services/brainScheduler.js+++ b/server/services/brainScheduler.js@@ -57,30 +57,29 @@ function isWeeklyReviewTime(settings, now) {* Check if daily digest was missed (should have run today but didn't)*/function isDailyDigestMissed(settings, now) {- if (!settings.lastDailyDigest) return false;-- const lastRun = new Date(settings.lastDailyDigest);const { hours, minutes } = parseTime(settings.dailyDigestTime);// Create target time for todayconst todayTarget = new Date(now);todayTarget.setHours(hours, minutes, 0, 0);- // If current time is past today's target and last run was before today- if (now > todayTarget) {- const lastRunDate = lastRun.toDateString();- const todayDate = now.toDateString();- return lastRunDate !== todayDate;- }+ // Only consider catch-up if we're past today's target time+ if (now <= todayTarget) return false;- return false;+ // Never run before — catch up now+ if (!settings.lastDailyDigest) return true;++ // Last run was before today — catch up+ const lastRun = new Date(settings.lastDailyDigest);+ return lastRun.toDateString() !== now.toDateString();}/*** Check if weekly review was missed*/function isWeeklyReviewMissed(settings, now) {- if (!settings.lastWeeklyReview) return false;+ // Never run before — catch up now+ if (!settings.lastWeeklyReview) return true;const lastRun = new Date(settings.lastWeeklyReview);const daysSinceLastRun = Math.floor((now - lastRun) / (24 * 60 * 60 * 1000));