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): perpetual picks bypass per-app review cooldown so manual triggers keep draining
Adam Eivy0627353da571
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex b931f791c8..6a27e4d8f4 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -10,6 +10,8 @@- **Perpetual schedules now actually drain back-to-back — the next run fires the moment the previous one finishes, instead of stalling until the next hourly check.** The `perpetual` mode promised "re-queue on completion," and the cooldown-skip that supports it was wired, but the completion *trigger* itself was missing: when a perpetual agent (e.g. `claim-issue`) finished, the `agent:completed` handler only ran `dequeueNextTask`, which drains *already-queued* work and never regenerates perpetual tasks. The only thing that re-queued them was the `cos-improvement-check` timer — and a "ready" (unparked) perpetual task doesn't even shorten that timer (its delay is gated on `status:'scheduled'` tasks only), so when a perpetual task was the only enabled schedule the next run waited up to a full hour (`MAX_CHECK_INTERVAL`) despite open, actionable work. The `agent:completed` handler now refills the perpetual queue immediately after a perpetual-schedule agent completes **successfully** (a failed run is left to task-retry/backoff and the recheck cadence, so the daemon can't spin through back-to-back failures), sequenced *before* the generic dequeue so the next perpetual task is on the queue before any freed slot is filled, and gated identically to the timer (daemon running, not paused, idle-review on, CoS auto-run = `execute`), reusing `queueEligibleImprovementTasks` so per-app cooldown, the one-pending-per-app cap, the concurrency limits, and the work-detector park all still apply — i.e. it converges to the same empty/parked state, just without the up-to-an-hour gap between items. The completing task is still `in_progress` on disk when the refill runs (the event fires before its status is persisted), so its id is threaded through as `ignoreTaskId` to keep the duplicate scan from rejecting the identical-first-line re-queue. (`server/services/cos.js`, `server/services/cosState.js`, `server/services/cosJobScheduler.js`, `server/services/cosTaskGenerator.js`, `server/services/cosTaskStore.js`)+- **A *manually-triggered* perpetual task now continues the drain instead of running exactly once.** The back-to-back refill landed for perpetual tasks the scheduler queued, but a perpetual task you kicked off by hand (CoS → Schedule → **Run**) still stopped after a single run. The cause: the on-demand "Run" path (like the idle-review loop) stamps the app's `lastReviewedAt` at spawn time to guard against a re-pick storm — and the per-app review cooldown gate inside `queueEligibleImprovementTasks` reads that stamp. So when the refill fired on completion (minutes later, well inside the 30-minute cooldown window), the just-run app read as "on cooldown" and the next item was skipped — even though completion already correctly skips the cooldown *bump* for perpetual work. Perpetual (drain-until-done) picks now **bypass the per-app review cooldown entirely** in the queue path — their work-detector park is the throttle, not the cooldown window — so a hand-triggered `claim-issue`/`claim-work` keeps claiming issues back-to-back until the queue is empty, exactly like a scheduled one. The same queue path runs on the post-startup sweep, so a perpetual task with actionable work also resumes its drain on daemon start instead of waiting for the next hourly check. Non-perpetual rotation types keep the cooldown gate unchanged. (`server/services/cosTaskGenerator.js`)+- **Feature Agents moved from Dev Tools to the Chief of Staff section.** The Feature Agents page (`/feature-agents`) now lives under the Chief of Staff sidebar group alongside the other agent-management pages, rather than buried in Dev Tools. The route is unchanged — only the sidebar grouping and the ⌘K / voice nav section label moved. (`client/src/components/Layout.jsx`, `server/lib/navManifest.js`)- **The CoS → Schedule page is now a scannable card grid instead of a flat expandable list.** Each task type renders as a status card you can read at a glance — a colored status dot (active / on-demand / waiting-on-deps / disabled), a **next-run countdown** ("in 3h", "Mon 9:00") that was previously computed server-side but never shown, an app-coverage bar with the enabled/total count kept front-and-center, and last-run/run-count. Cards sort by status then soonest next run (so what's about to run rises to the top), the All/Enabled toggle is replaced by per-status filters (Active / On-Demand / Waiting / Disabled), and a name filter box jumps to a task quickly. A **Run** button sits on each card — for app-targeting tasks it opens an app picker so the on-demand run carries app context (just like the old per-task controls), and falls back to a plain global run for tasks with no managed apps; **Configure** opens a slide-over drawer with the full per-task settings (interval, provider/model, prompt, agent options, dependencies, pipeline stages, and per-app overrides) — the same controls as before, now in a focused panel that's deep-linkable via `?task=` and closes on Esc/backdrop. Mobile collapses the grid to a single column.diff --git a/server/services/cos.test.js b/server/services/cos.test.jsindex dd524c4fa2..88e018367e 100644--- a/server/services/cos.test.js+++ b/server/services/cos.test.js@@ -941,6 +941,36 @@ describe('cos.js source — priority + capacity invariants', () => {fnBody,'queue path must not call the disk-reading isAppOnCooldown per app').not.toMatch(/await\s+isAppOnCooldown\(/);++ // Perpetual (drain-until-done) picks must BYPASS the per-app review+ // cooldown — their work-detector park is the throttle, not the cooldown+ // window. The spawn-time `markAppReviewCooldown` stamp (on-demand manual+ // trigger + idle-review loop) writes `lastReviewedAt`, so without the+ // bypass the back-to-back refill after a perpetual completion reads its own+ // app as on-cooldown and stalls — a manually-triggered perpetual task then+ // runs once instead of continuing the drain. Pin two halves: (a) the+ // cooldown gate is guarded by a non-perpetual predicate, and (b) the gate+ // is resolved AFTER getNextTaskType (so the picked type's reason is known+ // before the cooldown decision). `getNextTaskType` tags perpetual picks+ // with reason `perpetual-drain`.+ const cooldownIdx = fnBody.indexOf('isAppActivityOnCooldown(');+ const nextTypeIdx = fnBody.indexOf('getNextTaskType(');+ expect(+ nextTypeIdx,+ 'getNextTaskType must be resolved before the cooldown gate so perpetual picks can bypass it'+ ).toBeGreaterThan(-1);+ expect(+ cooldownIdx > nextTypeIdx,+ 'the per-app cooldown gate must come AFTER getNextTaskType so it can bypass perpetual picks'+ ).toBe(true);+ expect(+ fnBody,+ 'queue path must bypass the cooldown gate for perpetual-drain picks (reason === "perpetual-drain")'+ ).toMatch(/perpetual-drain/);+ expect(+ fnBody,+ 'the cooldown gate must be guarded so it only applies to non-perpetual picks'+ ).toMatch(/!\s*\w*[Pp]erpetual\w*\s*&&\s*isAppActivityOnCooldown\(/);});it('generateManagedAppImprovementTaskForType defers updateAppActivity until after gates', () => {diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex a46a716544..1c9de95a7a 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -1034,9 +1034,10 @@ export async function queueEligibleImprovementTasks(state, cosTaskData, { ignore// would still surface here; both gates treat `undefined` as// "no activity yet."const appActivity = activitySnapshot.apps?.[app.id];- if (isAppActivityOnCooldown(appActivity, state.config.appReviewCooldownMs)) continue;- // Get next eligible improvement type for this app. `getNextTaskType`+ // Resolve the next eligible improvement type for this app BEFORE the+ // per-app cooldown gate — the picked type's interval decides whether the+ // cooldown even applies (see the perpetual bypass below). `getNextTaskType`// falls back to ROTATION when nothing is time-due, and the rotation// pointer is derived from the `lastType` argument — without it, the// rotation always restarts from index 0 and starves every other@@ -1048,6 +1049,21 @@ export async function queueEligibleImprovementTasks(state, cosTaskData, { ignoreif (!nextTypeResult) continue;const nextType = nextTypeResult.taskType;+ // Perpetual (drain-until-done) picks BYPASS the per-app review cooldown:+ // their work-detector park IS the throttle (taskSchedule.parkPerpetual),+ // and agentCompletion.js already skips the post-completion cooldown bump+ // for them. But the spawn-time `markAppReviewCooldown` stamp (written by+ // BOTH the on-demand manual-trigger path and the idle-review loop) sets+ // `lastReviewedAt`, which `isAppActivityOnCooldown` reads. Without this+ // bypass, the back-to-back refill fired right after a perpetual run reads+ // its OWN app as "on cooldown" (lastReviewedAt is minutes old, the window+ // is 30 min) and skips the re-queue — so a manually-triggered perpetual+ // task runs exactly once and stalls instead of continuing the drain. The+ // cooldown still gates non-perpetual rotation types. `getNextTaskType`+ // tags every perpetual pick with reason `perpetual-drain`.+ const isPerpetualDrain = nextTypeResult.reason === 'perpetual-drain';+ if (!isPerpetualDrain && isAppActivityOnCooldown(appActivity, state.config.appReviewCooldownMs)) continue;+const taskKey = `app:${app.id}:${nextType}`;if (existingTaskTypes.has(taskKey)) {emitLog('debug', `Improvement task ${nextType} for ${app.name} already queued`);