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(cos): wake daemon at a perpetual task's per-app recheck boundary
Adam Eivy82e4437926a2
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 4884014cc0..df20537ee2 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -34,6 +34,8 @@## Fixed+- **A perpetual scheduled task with a daily recheck (e.g. `claim-issue` set to perpetual with a `0 9 * * *` recheck) no longer runs up to an hour late — or reads as "didn't run at all."** Perpetual tasks record their "parked until the next recheck" state PER-APP, but the wake-up timer that decides when the daemon next checks for eligible work (`scheduleNextImprovementCheck`) reads only the *global* `shouldRunTask`, which never carries a per-app park — so a parked perpetual task always looked `ready` there and its real next-recheck boundary was invisible. The timer only shortens its delay for tasks it can see as `scheduled`, so nothing ever woke the daemon *at* 9am; the parked drain resumed only on the fallback poll (capped at one hour), which is why a 9am task tended to fire sometime in the 9–10am hour and, if you'd already reached for the manual "Run" by then, looked like it had skipped the schedule entirely. `getUpcomingTasks` now aggregates a perpetual task's per-app park records into one verdict — `ready` if any tracked app is due now (mid-drain or its park already elapsed), otherwise `scheduled` at the soonest per-app recheck — so the daemon schedules a wake-up for that boundary and the drain resumes promptly at the configured time. The change is bounded by the existing one-hour cap (it can only make the wake-up *sooner*, never later) and touches only wake-up timing and the "Upcoming Tasks" display; the actual per-app dispatch decision is unchanged. As a side benefit the Upcoming Tasks widget now shows a fully-parked perpetual task under "scheduled" with its next recheck time, instead of a permanent "ready" that never spawned.+- **Dragging dashboard widgets did nothing on a phone — "Arrange" opened an edit mode with no handles in it.** The grid renderer collapses to a single-column stack below 640px, and drag was switched off entirely there on the reasoning that a phone has no room for positional editing. That is true of *where* a widget sits, but not of *what order* the stack is in — which is the only thing a phone user can see, and the one arrangement question the mobile layout actually answers. Edit mode on mobile now gives each widget a reorder handle (a wider touch target than the desktop pair) that sorts it up and down the stack. The sort runs through `@dnd-kit/sortable`, the same sensor pairing the CoS task list and the universe-builder chips already use, so it arrives with touch, keyboard (focus the handle, press space, then the arrow keys), screen-reader announcements, multi-pointer safety, and auto-scroll past the fold — none of which a hand-rolled pointer gesture would have had. On drop the grid is re-flowed so its reading order matches the new stack order, preserving every widget's width and height: a one-dimensional edit can only be expressed as 2D coordinates by re-packing, so a mobile reorder does re-pack the wide-screen arrangement, and the edit-mode hint now says so rather than leaving it to be discovered.Three things around it were wrong in the same way. The stack rendered in grid-array order, but `placeAndCompact` hoists the moved item to the front of that array on every desktop drag — so a phone showed the most recently moved widget first regardless of where it had been dropped; reading order (`y`, then `x`) is now what both the stack and the DOM/tab order follow. Saving an arrangement left the layout's `widgets` list in its old order, so the layout editor listed widgets in an order the dashboard didn't show; it's rewritten to the grid's reading order on save. And the edit-mode hint picked its wording from a CSS `sm:` breakpoint while the grid picks its mode from its own measured container — page padding makes the container narrower, so in a ~30px band the hint described handles that weren't on screen. The grid reports its mode to the page now, so there is one seam instead of two.diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 941edaf5ea..1bd10663f8 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -1835,6 +1835,43 @@ export async function resetExecutionHistory(taskType, appId = null) {// Upcoming Tasks Preview// ============================================================+/**+ * Aggregate a perpetual task's park records into a single upcoming-eligibility+ * verdict for getUpcomingTasks.+ *+ * Perpetual parks are recorded PER-APP (parkPerpetual is always called with an+ * appId — see applyPerpetualWorkGate / the reconcile blocks in cosTaskGenerator),+ * so the top-level execution record is only a container and never carries its own+ * `parkedUntil` for the app-scoped drains (claim-issue, claim-work, branch-/+ * issue-reconcile). The GLOBAL `shouldRunTask` therefore always reads+ * 'perpetual-drain' (shouldRun:true) even when every app is parked on its recheck+ * cadence — which made getUpcomingTasks report the task 'ready' forever and hid+ * its real next-recheck boundary (e.g. a `recheckCron: '0 9 * * *'`) from+ * scheduleNextImprovementCheck. The daemon then never woke AT 9am; the parked+ * drain only resumed on the ≤1h fallback poll, so a task configured for 9am ran+ * up to an hour late (or read as "didn't run").+ *+ * Derive eligibility from the per-app records instead — plus the top-level record+ * only when it carries its OWN park (a future global-park perpetual; none ship+ * today, but keep it general). Returns:+ * - null → no tracked scope yet (caller keeps its global 'ready' default)+ * - { status:'ready', eligibleAt:now } → some tracked scope is due now (unparked or park elapsed)+ * - { status:'scheduled', eligibleAt:<ms> } → every tracked scope parked; soonest recheck+ */+function perpetualUpcomingEligibility(execution, now) {+ const scopes = Object.values(execution?.perApp || {});+ if (execution?.parkedUntil) scopes.push(execution);+ if (scopes.length === 0) return null;+ let soonest = Infinity;+ for (const rec of scopes) {+ const until = rec?.parkedUntil ? new Date(rec.parkedUntil).getTime() : 0;+ // Unparked (mid-drain) or park already elapsed → this scope is due now.+ if (!until || until <= now) return { status: 'ready', eligibleAt: now };+ if (until < soonest) soonest = until;+ }+ return { status: 'scheduled', eligibleAt: soonest };+}+export async function getUpcomingTasks(limit = 10) {const schedule = await loadSchedule();const now = Date.now();@@ -1861,6 +1898,18 @@ export async function getUpcomingTasks(limit = 10) {eligibleAt = Infinity;}+ // Perpetual tasks park per-app, so the global `check` above can't see the+ // recheck boundary — re-derive status/eligibility from the park records so+ // scheduleNextImprovementCheck wakes the daemon AT the next recheck (e.g. 9am)+ // instead of only on the ≤1h fallback poll. See perpetualUpcomingEligibility.+ if (interval.type === INTERVAL_TYPES.PERPETUAL) {+ const perpetual = perpetualUpcomingEligibility(execution, now);+ if (perpetual) {+ taskStatus = perpetual.status;+ eligibleAt = perpetual.eligibleAt;+ }+ }+if (taskStatus === 'completed') continue;upcoming.push({diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex dea738210f..70361cc7ab 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -111,6 +111,7 @@ import {shouldRunTask,getDueTasks,getNextTaskType,+ getUpcomingTasks,addTemplateTask,getTemplateTasks,deleteTemplateTask,@@ -1471,6 +1472,71 @@ describe('taskSchedule', () => {})})+ // Perpetual tasks park PER-APP, so the global shouldRunTask always reads+ // 'perpetual-drain'. getUpcomingTasks must instead surface the per-app recheck+ // boundary as a 'scheduled' upcoming task — otherwise scheduleNextImprovementCheck+ // (which only shortens its wake-up for 'scheduled' tasks) never wakes the daemon+ // at the recheck cadence (e.g. a 9am recheckCron), and the parked drain resumes+ // only on the ≤1h fallback poll.+ describe('getUpcomingTasks — perpetual recheck boundary', () => {+ it('reports a perpetual task PARKED on every app as scheduled at the soonest recheck', async () => {+ const nineAm = recentNineAm()+ nineAm.setDate(nineAm.getDate() + 1) // next 9am (future)+ const soon = new Date(Date.now() + 30 * 60 * 1000).toISOString() // 30m out+ mockSchedule({+ tasks: { 'claim-issue': { type: 'perpetual', enabled: true, recheckCron: '0 9 * * *' } },+ executions: { 'task:claim-issue': { lastRun: null, count: 0, perApp: {+ 'app-1': { lastRun: null, count: 0, parkedUntil: nineAm.toISOString() },+ 'app-2': { lastRun: null, count: 0, parkedUntil: soon }+ } } }+ })+ const upcoming = await getUpcomingTasks(50)+ const claim = upcoming.find(t => t.taskType === 'claim-issue')+ expect(claim).toBeTruthy()+ expect(claim.status).toBe('scheduled')+ // Soonest of the two per-app parks (app-2, 30m out).+ expect(claim.eligibleAt).toBe(new Date(soon).getTime())+ expect(claim.eligibleIn).toBeGreaterThan(0)+ })++ it('reports the perpetual task ready when any app park has already elapsed', async () => {+ const past = new Date(Date.now() - 60 * 1000).toISOString()+ const future = new Date(Date.now() + 60 * 60 * 1000).toISOString()+ mockSchedule({+ tasks: { 'claim-issue': { type: 'perpetual', enabled: true, recheckCron: '0 9 * * *' } },+ executions: { 'task:claim-issue': { lastRun: null, count: 0, perApp: {+ 'app-1': { lastRun: null, count: 0, parkedUntil: past }, // recheck due now+ 'app-2': { lastRun: null, count: 0, parkedUntil: future }+ } } }+ })+ const upcoming = await getUpcomingTasks(50)+ const claim = upcoming.find(t => t.taskType === 'claim-issue')+ expect(claim.status).toBe('ready')+ expect(claim.eligibleIn).toBeLessThanOrEqual(0)+ })++ it('treats an app mid-drain (park cleared) as ready even if a sibling app is parked', async () => {+ const future = new Date(Date.now() + 60 * 60 * 1000).toISOString()+ mockSchedule({+ tasks: { 'claim-issue': { type: 'perpetual', enabled: true } },+ executions: { 'task:claim-issue': { lastRun: null, count: 0, perApp: {+ 'app-1': { lastRun: null, count: 0 }, // no park → draining+ 'app-2': { lastRun: null, count: 0, parkedUntil: future }+ } } }+ })+ const upcoming = await getUpcomingTasks(50)+ const claim = upcoming.find(t => t.taskType === 'claim-issue')+ expect(claim.status).toBe('ready')+ })++ it('keeps the global ready default for a never-run perpetual task (no per-app records)', async () => {+ mockSchedule({ tasks: { 'claim-issue': { type: 'perpetual', enabled: true } } })+ const upcoming = await getUpcomingTasks(50)+ const claim = upcoming.find(t => t.taskType === 'claim-issue')+ expect(claim.status).toBe('ready')+ })+ })+describe('parkPerpetual / clearPerpetualPark', () => {it('parkPerpetual stamps parkedUntil + reason on the per-app record', async () => {mockSchedule({ tasks: { 'claim-issue': { type: 'perpetual', enabled: true, recheckIntervalMs: 3600000 } } })