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): thread ignoreTaskId through the idle-review generator too
[._.]/ Adam Eivy352b7e89699a
diff --git a/server/services/cos.js b/server/services/cos.jsindex 4738eb3f59..74e3ac522e 100644--- a/server/services/cos.js+++ b/server/services/cos.js@@ -1006,7 +1006,7 @@ async function spawnDequeuePriority3Missions(ctx) {* tasks, idle review on, auto-run in execute).*/async function spawnDequeuePriority4IdleReview(ctx) {- const { state, capacity } = ctx;+ const { state, capacity, ignoreTaskId } = ctx;if (!isIdleTierEligible({spawned: capacity.spawned,@@ -1018,7 +1018,7 @@ async function spawnDequeuePriority4IdleReview(ctx) {const freshCosTasks = await getCosTasks();const pendingSystemTasks = freshCosTasks.autoApproved?.length || 0;if (pendingSystemTasks === 0) {- const idleTask = await generateIdleReviewTask(state);+ const idleTask = await generateIdleReviewTask(state, { ignoreTaskId });if (idleTask && capacity.canSpawn(idleTask, ctx.autonomousSpawnCeiling)) {cosEvents.emit('task:ready', idleTask);capacity.trackSpawn(idleTask);@@ -1039,7 +1039,15 @@ async function spawnDequeuePriority4IdleReview(ctx) {* 4. Idle review task (if idleReviewEnabled)* Returns silently when idle — no log noise.*/-async function dequeueNextTask() {+/**+ * `ignoreTaskId` names a task that just completed but may still read+ * `pending`/`in_progress` on disk — `agent:completed` fires from `completeAgent`,+ * before the completion flow's `updateTask` settles it. Generators that count+ * in-flight work (quota-burn's dispatch tally, #3179) must exclude it or they+ * charge the finished run twice. Only the completion continuation passes it; every+ * other caller runs outside that window and correctly leaves it null.+ */+async function dequeueNextTask({ ignoreTaskId = null } = {}) {if (!isDaemonRunning()) return;// A global pause stops scheduled/autonomous spawning, but NOT explicit user@@ -1071,7 +1079,8 @@ async function dequeueNextTask() {hasPendingUserTasks: false,taskSchedule: null,cosAutonomyMode: null,- autonomousSpawnCeiling: availableSlots+ autonomousSpawnCeiling: availableSlots,+ ignoreTaskId};// Priority 0 (on-demand) runs even when paused — an explicit user "Run"@@ -1186,7 +1195,10 @@ export async function init() {setImmediate(() => {refillPerpetualForCompletedAgent(agent).catch(err => console.error(`❌ Perpetual refill after ${agent?.id} failed: ${err.message}`))- .then(() => dequeueNextTask())+ // Same window as the refill above: this runs before the completing+ // task's `updateTask` settles it, so the idle tier's generator must+ // exclude it from any in-flight tally (#3179).+ .then(() => dequeueNextTask({ ignoreTaskId: agent?.taskId })).catch(err => console.error(`❌ Dequeue after ${agent?.id} completion failed: ${err.message}`));});diff --git a/server/services/cos.test.js b/server/services/cos.test.jsindex 28012e7a42..ee0e3c8224 100644--- a/server/services/cos.test.js+++ b/server/services/cos.test.js@@ -1264,9 +1264,17 @@ describe('cos.js source — agent:completed triggers perpetual refill', () => {const onIdx = COS_SRC.indexOf("cosEvents.on('agent:completed'");const handlerSlice = COS_SRC.slice(onIdx, onIdx + 1400);expect(- /refillPerpetualForCompletedAgent\(agent\)[\s\S]*\.then\(\s*\(\)\s*=>\s*dequeueNextTask\(\)\s*\)/.test(handlerSlice),+ /refillPerpetualForCompletedAgent\(agent\)[\s\S]*\.then\(\s*\(\)\s*=>\s*dequeueNextTask\(/.test(handlerSlice),'handler must run dequeueNextTask in a .then() AFTER the refill resolves').toBe(true);+ // Both generators on this continuation must skip the completing task, which+ // still reads pending/in_progress until updateTask settles it (#3179): the+ // refill excludes it via queueEligibleImprovementTasks, and the dequeue's+ // idle-review tier via this argument.+ expect(+ /dequeueNextTask\(\{\s*ignoreTaskId:\s*agent\?\.taskId\s*\}\)/.test(handlerSlice),+ 'the post-refill dequeue must pass the completing task id as ignoreTaskId'+ ).toBe(true);// The old standalone `setImmediate(() => dequeueNextTask())` must be gone —// its presence would race the refill.expect(diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex d412d6057f..28eb1ecf17 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -1219,7 +1219,7 @@ export async function evaluateTasks(options) {* @param {Object} state - Current CoS state* @returns {Object|null} Generated task or null if nothing to do*/-export async function generateIdleReviewTask(state) {+export async function generateIdleReviewTask(state, { ignoreTaskId = null } = {}) {if (!isImprovementEnabled(state)) {emitLog('debug', 'Improvement tasks are disabled');return null;@@ -1250,7 +1250,7 @@ export async function generateIdleReviewTask(state) {});emitLog('info', `Generating improvement task for ${nextApp.name}`, { appId: nextApp.id });- const idleTask = await generateManagedAppImprovementTask(nextApp, state);+ const idleTask = await generateManagedAppImprovementTask(nextApp, state, { ignoreTaskId });// Only bind the active marker once a real task exists.if (idleTask) {await bindAppReviewAgent(nextApp.id, `idle-review-${Date.now()}`);@@ -1709,7 +1709,7 @@ export function applyAppWorktreeDefault(metadata, app) {}}-async function generateManagedAppImprovementTask(app, state) {+async function generateManagedAppImprovementTask(app, state, { ignoreTaskId = null } = {}) {const { getAppActivityById, updateAppActivity } = await import('./appActivity.js');const taskSchedule = await import('./taskSchedule.js');@@ -1761,7 +1761,7 @@ async function generateManagedAppImprovementTask(app, state) {// with the literal {prData}/{referenceData} markers and never poll. The// recordExecution + activity bump above already accounted for the idle// spawn; the per-type generator does not record execution itself.- return generateManagedAppImprovementTaskForType(nextType, app, state);+ return generateManagedAppImprovementTaskForType(nextType, app, state, { ignoreTaskId });}/**diff --git a/server/services/cosTaskGenerator.test.js b/server/services/cosTaskGenerator.test.jsindex 9a61797c7d..7bb244bdf0 100644--- a/server/services/cosTaskGenerator.test.js+++ b/server/services/cosTaskGenerator.test.js@@ -886,3 +886,25 @@ describe('ignoreTaskId reaches the in-flight-counting gates (#3179)', () => {expect(seen[0]).toMatchObject({ taskType: 'quota-burn', ignoreTaskId: 'sys-finishing' });});});++/**+ * BOTH generators reachable from the `agent:completed` continuation must carry+ * ignoreTaskId: the refill (queueEligibleImprovementTasks) AND the idle-review+ * tier that `dequeueNextTask` runs on the same continuation. The idle path was+ * missed on the first pass — it dropped the id and re-charged the completing+ * burn, skipping a dispatch the family was entitled to (#3179).+ */+describe('ignoreTaskId reaches BOTH completion-continuation generators (#3179)', () => {+ it('the idle-review chain threads ignoreTaskId end to end', () => {+ expect(GEN_SRC).toMatch(/export async function generateIdleReviewTask\(state, \{ ignoreTaskId = null \} = \{\}\)/);+ expect(GEN_SRC).toContain('generateManagedAppImprovementTask(nextApp, state, { ignoreTaskId })');+ expect(GEN_SRC).toMatch(/async function generateManagedAppImprovementTask\(app, state, \{ ignoreTaskId = null \} = \{\}\)/);+ expect(GEN_SRC).toContain('generateManagedAppImprovementTaskForType(nextType, app, state, { ignoreTaskId })');+ });++ it('cos.js passes the completing task id into the dequeue that follows the refill', () => {+ expect(COS_SRC).toContain('dequeueNextTask({ ignoreTaskId: agent?.taskId })');+ expect(COS_SRC).toMatch(/async function dequeueNextTask\(\{ ignoreTaskId = null \} = \{\}\)/);+ expect(COS_SRC).toContain('generateIdleReviewTask(state, { ignoreTaskId })');+ });+});