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 (codex): exempt perpetual tasks from the spawn-time cooldown too
Adam Eivye50d2dd5c0d8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 6a27e4d8f4..40826289b6 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -10,7 +10,7 @@- **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`)+- **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) tasks now **bypass the per-app review cooldown** at BOTH the queue gate AND the spawn gate — their work-detector park is the throttle, not the cooldown window. (The queue-only fix wasn't enough: the refill would queue the next perpetual task, but the spawn loop then re-checked the same `lastReviewedAt` cooldown and skipped it until the window expired, so the drain still stalled one item in.) A shared `isCooldownExemptTask` predicate now gates the cooldown in both spawn engines (`dequeueNextTask` and `evaluateTasks`) and their dry-run planners, covering pipeline continuations and perpetual drains alike; it accepts `metadata.perpetual` as both the in-memory boolean and the string `"true"` it round-trips to through COS-TASKS.md. So a hand-triggered `claim-issue`/`claim-work` keeps claiming issues back-to-back until the queue is empty, exactly like a scheduled one, and the same paths run on the post-startup sweep so a perpetual task with actionable work 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`, `server/services/cos.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`)diff --git a/server/services/cos.js b/server/services/cos.jsindex 91d9c95e8e..69f9693c2d 100644--- a/server/services/cos.js+++ b/server/services/cos.js@@ -88,6 +88,7 @@ import {generateManagedAppImprovementTaskForType,blockIfExceedsMaxSpawns,selectDryRunAutoApproved,+ isCooldownExemptTask,countRunningAgentsByProject,isWithinProjectLimit,checkStagePrecondition,@@ -855,6 +856,7 @@ async function dequeueNextTask() {perProjectLimit,spawnProjectCounts,isOnCooldown: (appId) => isAppOnCooldown(appId, state.config.appReviewCooldownMs),+ cooldownExempt: isCooldownExemptTask,extraSkip: isDisabledAnalysisType});for (const task of wouldSpawn) {@@ -871,8 +873,12 @@ async function dequeueNextTask() {emitLog('info', `System task skipped — task type '${analysisType}' is disabled`, { taskId: task.id });continue;}+ // Pipeline continuations AND perpetual drains bypass the per-app cooldown+ // (see isCooldownExemptTask) — otherwise a perpetual task the refill just+ // queued is skipped here until the 30-min window expires, stalling the+ // manually-triggered back-to-back drain one item in.const appId = task.metadata?.app;- if (appId) {+ if (appId && !isCooldownExemptTask(task)) {const onCooldown = await isAppOnCooldown(appId, state.config.appReviewCooldownMs);if (onCooldown) continue;}diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex 1c9de95a7a..5461b1cb57 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -63,6 +63,34 @@ export function exceedsMaxSpawns(task) {return (Number(task.metadata?.totalSpawnCount) || 0) >= MAX_TOTAL_SPAWNS;}+/**+ * A task that must BYPASS the per-app review cooldown at spawn time. Two classes+ * qualify, for the same reason — the cooldown is not their throttle:+ * - **Pipeline continuations** (`metadata.pipeline.currentStage > 0`) — a+ * multi-stage pipeline's own stage gating sequences the work.+ * - **Perpetual drains** (`metadata.perpetual`) — the work-detector park is the+ * throttle (see `queueEligibleImprovementTasks` / agentCompletion.js). Without+ * this, a perpetual task the refill just *queued* (after correctly bypassing+ * the queue-path cooldown) would still be skipped here at the spawn gate,+ * because the on-demand "Run" path stamped `lastReviewedAt` and these gates+ * read it — so a manually-triggered perpetual drain stalls one item in.+ *+ * `metadata.perpetual` is a bare boolean set upstream, but it round-trips through+ * COS-TASKS.md as the STRING `"true"` (taskParser serializes non-string/-object+ * metadata via `String(value)`; only arrays/objects like `pipeline` get the JSON+ * sentinel that preserves their type). So accept BOTH the in-memory boolean and+ * the re-parsed string — a `=== true` check alone would silently miss the+ * persisted-then-reloaded task, which is exactly the one the spawn gate sees.+ *+ * Shared by both spawn engines (`dequeueNextTask` in cos.js and `evaluateTasks`+ * here) and their dry-run planners so the cooldown-exempt set can't drift.+ */+export function isCooldownExemptTask(task) {+ const meta = task?.metadata;+ if (!meta) return false;+ return meta.pipeline?.currentStage > 0 || meta.perpetual === true || meta.perpetual === 'true';+}+/*** Dry-run eligibility pass over auto-approved system tasks. Walks the tasks in* file order applying the SAME gates execute mode uses — global slot cap,@@ -558,7 +586,7 @@ async function spawnPriority2AutoApproved(ctx) {perProjectLimit,spawnProjectCounts,isOnCooldown: (appId) => isAppOnCooldown(appId, state.config.appReviewCooldownMs),- cooldownExempt: (task) => task.metadata?.pipeline?.currentStage > 0+ cooldownExempt: isCooldownExemptTask});for (const task of wouldSpawn) {emitLog('info', `[dry-run] CoS auto-run would spawn system task: ${task.id}`, { taskId: task.id, domainAutonomy: 'cos' });@@ -571,10 +599,10 @@ async function spawnPriority2AutoApproved(ctx) {if (await blockIfExceedsMaxSpawns(task, 'internal')) continue;- // Check if task's app is on cooldown (pipeline continuations bypass cooldown)+ // Check if task's app is on cooldown (pipeline continuations AND perpetual+ // drains bypass cooldown — see isCooldownExemptTask).const appId = task.metadata?.app;- const isPipelineContinuation = task.metadata?.pipeline?.currentStage > 0;- if (appId && !isPipelineContinuation) {+ if (appId && !isCooldownExemptTask(task)) {const onCooldown = await isAppOnCooldown(appId, state.config.appReviewCooldownMs);if (onCooldown) {emitLog('debug', `Skipping system task ${task.id} - app ${appId} on cooldown`);diff --git a/server/services/cosTaskGenerator.test.js b/server/services/cosTaskGenerator.test.jsindex f55d218f69..04d071d01b 100644--- a/server/services/cosTaskGenerator.test.js+++ b/server/services/cosTaskGenerator.test.js@@ -15,7 +15,7 @@ import { describe, it, expect } from 'vitest';import { readFileSync } from 'fs';import { fileURLToPath } from 'url';import { dirname, join } from 'path';-import { selectDryRunAutoApproved, exceedsMaxSpawns, resolveIssueAuthorFilterBlock } from './cosTaskGenerator.js';+import { selectDryRunAutoApproved, exceedsMaxSpawns, resolveIssueAuthorFilterBlock, isCooldownExemptTask } from './cosTaskGenerator.js';import { MAX_TOTAL_SPAWNS } from '../lib/validation.js';const __dirname = dirname(fileURLToPath(import.meta.url));@@ -27,8 +27,11 @@ const noCooldown = () => Promise.resolve(false);// The unit tests above exercise selectDryRunAutoApproved with synthetic hooks;// these source-level guards pin that each ENGINE wires the hook set matching-// its own execute path — so a future edit can't silently swap or drop a hook-// (e.g. give dequeue the pipeline cooldown bypass it doesn't have in execute).+// its own execute path — so a future edit can't silently swap or drop a hook.+// Both engines now share the `isCooldownExemptTask` predicate (pipeline+// continuations AND perpetual drains bypass the cooldown), so a dry-run plan+// matches its execute path; the only remaining asymmetry is `extraSkip`+// (dequeue's disabled-analysis-type gate), which evaluateTasks does not have.describe('dry-run hook wiring matches each engine execute path', () => {// Isolate each engine's selectDryRunAutoApproved call site.const callSite = (src) => {@@ -39,18 +42,57 @@ describe('dry-run hook wiring matches each engine execute path', () => {return src.slice(start, src.indexOf('});', start) + 3);};- it('dequeueNextTask (cos.js) passes extraSkip (disabled-analysis-type) but NOT cooldownExempt', () => {+ it('dequeueNextTask (cos.js) passes the shared cooldownExempt AND extraSkip (disabled-analysis-type)', () => {const site = callSite(COS_SRC);expect(site).toContain('extraSkip: isDisabledAnalysisType');- expect(site).not.toContain('cooldownExempt');+ // dequeue must exempt perpetual/pipeline tasks from cooldown in its dry-run+ // plan too, mirroring its execute gate — otherwise the plan over-reports a+ // perpetual drain as "would skip (cooldown)" that execute actually spawns.+ expect(site).toContain('cooldownExempt: isCooldownExemptTask');});- it('evaluateTasks (cosTaskGenerator.js) passes cooldownExempt (pipeline continuation) but NOT extraSkip', () => {+ it('evaluateTasks (cosTaskGenerator.js) passes the shared cooldownExempt but NOT extraSkip', () => {const site = callSite(GEN_SRC);- expect(site).toContain('cooldownExempt:');- expect(site).toContain('pipeline?.currentStage > 0');+ expect(site).toContain('cooldownExempt: isCooldownExemptTask');expect(site).not.toContain('extraSkip');});++ it('both engines gate their EXECUTE cooldown check on isCooldownExemptTask', () => {+ // The spawn gate (not just the dry-run planner) must consult the shared+ // predicate, or a perpetual task the refill queued is skipped at spawn time+ // until the 30-min window expires — the manually-triggered-drain stall.+ expect(COS_SRC).toMatch(/if\s*\(appId\s*&&\s*!isCooldownExemptTask\(task\)\)/);+ expect(GEN_SRC).toMatch(/if\s*\(appId\s*&&\s*!isCooldownExemptTask\(task\)\)/);+ });+});++// isCooldownExemptTask is the single source of truth for "this task bypasses the+// per-app review cooldown." The perpetual-string case is the subtle one: a+// perpetual task is queued with `metadata.perpetual === true`, but that bare+// boolean round-trips through COS-TASKS.md as the STRING "true" (taskParser+// serializes non-object metadata via String()), and the spawn gate reads the+// re-parsed task — so a `=== true`-only check would miss exactly the task the+// gate sees.+describe('isCooldownExemptTask', () => {+ it('exempts pipeline continuations (currentStage > 0)', () => {+ expect(isCooldownExemptTask({ metadata: { pipeline: { currentStage: 2 } } })).toBe(true);+ });+ it('does NOT exempt a pipeline task still at stage 0', () => {+ expect(isCooldownExemptTask({ metadata: { pipeline: { currentStage: 0 } } })).toBe(false);+ });+ it('exempts a perpetual task as an in-memory boolean true', () => {+ expect(isCooldownExemptTask({ metadata: { perpetual: true } })).toBe(true);+ });+ it('exempts a perpetual task as the re-parsed string "true" (COS-TASKS.md round-trip)', () => {+ expect(isCooldownExemptTask({ metadata: { perpetual: 'true' } })).toBe(true);+ });+ it('does NOT exempt an ordinary app task', () => {+ expect(isCooldownExemptTask({ metadata: { app: 'app-1', analysisType: 'security-audit' } })).toBe(false);+ });+ it('is null-safe for a task with no metadata', () => {+ expect(isCooldownExemptTask(null)).toBe(false);+ expect(isCooldownExemptTask({})).toBe(false);+ });});// The `{reviewers}` prompt token is what tasks like claim-issue use to tell the