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 (claude): on-demand bypasses pause in evaluateTasks too
Adam Eivy434d535c061c
diff --git a/server/services/cos.test.js b/server/services/cos.test.jsindex 8fcfe0a3b5..44229c1a25 100644--- a/server/services/cos.test.js+++ b/server/services/cos.test.js@@ -684,6 +684,32 @@ describe('cos.js source — priority + capacity invariants', () => {expect(idleIdx, 'spawnPriority4IdleReview must run after feature agents').toBeGreaterThan(featureIdx);});+ it('on-demand (Priority 0) bypasses the global pause in BOTH engines', () => {+ // A global pause stops scheduled/autonomous/user spawning, but an explicit+ // user "Run" queues an on-demand request that must still fire. So in each+ // engine the pause gate must sit AFTER Priority 0, not at the top — moving it+ // back to the top is the regression this pins.+ const dequeueFn = extractFnBody(COS_SRC, COS_SRC.indexOf('async function dequeueNextTask'));+ const evalFn = extractFnBody(GEN_SRC, GEN_SRC.indexOf('export async function evaluateTasks'));++ // dequeueNextTask: the `if (paused) return` gate appears AFTER the on-demand+ // loop (`onDemandRequests`), and `paused` is NOT returned-on before it.+ const dqOnDemandIdx = dequeueFn.indexOf('onDemandRequests');+ const dqPauseGateIdx = dequeueFn.search(/if\s*\(\s*paused\s*\)\s*return/);+ expect(dqOnDemandIdx, 'dequeueNextTask must process onDemandRequests').toBeGreaterThan(-1);+ expect(dqPauseGateIdx, 'dequeueNextTask must keep an `if (paused) return` gate').toBeGreaterThan(-1);+ expect(dqPauseGateIdx, 'pause gate must come AFTER the on-demand loop').toBeGreaterThan(dqOnDemandIdx);++ // evaluateTasks: Priority 0 runs unconditionally; Priorities 1+ are wrapped in+ // an `if (!paused)` block that begins after spawnPriority0OnDemand.+ const evOnDemandIdx = evalFn.indexOf('spawnPriority0OnDemand(ctx)');+ const evPauseGateIdx = evalFn.search(/if\s*\(\s*!\s*paused\s*\)/);+ const evUserIdx = evalFn.indexOf('spawnPriority1UserTasks(ctx)');+ expect(evOnDemandIdx, 'evaluateTasks must invoke spawnPriority0OnDemand').toBeGreaterThan(-1);+ expect(evPauseGateIdx, 'evaluateTasks must gate the lower tiers on !paused').toBeGreaterThan(evOnDemandIdx);+ expect(evUserIdx, 'user/autonomous tiers must sit inside the !paused gate').toBeGreaterThan(evPauseGateIdx);+ });+it('per-project cap defaults to global cap when unset', () => {// The fallback `state.config.maxConcurrentAgentsPerProject || state.config.maxConcurrentAgents`// is the safety net for older state.json files that pre-date thediff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex 6d70ac7f30..cf656d87d4 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -621,12 +621,11 @@ export async function evaluateTasks(options) {const { initialStartup = false } = options || {};if (!isDaemonRunning()) return;- // Check if paused - skip evaluation if so+ // A global pause stops scheduled/autonomous/user spawning, but NOT explicit+ // user triggers: on-demand requests (Priority 0) are still drained while+ // paused so a manual "Run" (or a force-evaluate) fires. The user/autonomous+ // tiers below are gated on `!paused` — parity with dequeueNextTask in cos.js.const paused = (await loadState()).paused || false;- if (paused) {- emitLog('debug', 'CoS is paused - skipping evaluation');- return;- }// Update evaluation timestamp with lock to prevent race conditionsconst state = await withStateLock(async () => {@@ -708,23 +707,31 @@ export async function evaluateTasks(options) {autonomousSlotCeiling: availableSlots};- // Priorities 0–1 spend against the global slot cap.+ // Priority 0 (on-demand) spends against the global slot cap and runs even when+ // paused — an explicit user "Run" bypasses the global pause.await spawnPriority0OnDemand(ctx);- await spawnPriority1UserTasks(ctx);-- // Ceiling for AUTONOMOUS admissions this cycle (#711). On-demand + user tasks- // are already in `tasksToSpawn` and never count against the CoS action budget,- // so the autonomous sections below may add at most `autonomousActionsRemaining`- // more. With no action cap this equals `availableSlots`, so the default path is- // unchanged. The autonomous tiers use this in place of `availableSlots`.- ctx.autonomousSlotCeiling = Math.min(availableSlots, tasksToSpawn.length + autonomousActionsRemaining);-- // Priorities 2, 3, 3.6, 4 spend against the lower autonomous ceiling.- await spawnPriority2AutoApproved(ctx);- await maybeQueueImprovementTasks(ctx);- await spawnPriority3Missions(ctx);- await spawnPriority36FeatureAgents(ctx);- await spawnPriority4IdleReview(ctx);++ // Every tier below is scheduled/autonomous/user work that the global pause+ // stops. When paused we skip them and let the shared spawn loop below emit just+ // the on-demand tasks Priority 0 collected.+ if (!paused) {+ // Priority 1 spends against the global slot cap.+ await spawnPriority1UserTasks(ctx);++ // Ceiling for AUTONOMOUS admissions this cycle (#711). On-demand + user tasks+ // are already in `tasksToSpawn` and never count against the CoS action budget,+ // so the autonomous sections below may add at most `autonomousActionsRemaining`+ // more. With no action cap this equals `availableSlots`, so the default path is+ // unchanged. The autonomous tiers use this in place of `availableSlots`.+ ctx.autonomousSlotCeiling = Math.min(availableSlots, tasksToSpawn.length + autonomousActionsRemaining);++ // Priorities 2, 3, 3.6, 4 spend against the lower autonomous ceiling.+ await spawnPriority2AutoApproved(ctx);+ await maybeQueueImprovementTasks(ctx);+ await spawnPriority3Missions(ctx);+ await spawnPriority36FeatureAgents(ctx);+ await spawnPriority4IdleReview(ctx);+ }// Emit evaluation statusconst pendingUserCount = userTaskData.grouped?.pending?.length || 0;