Skip to content

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

withhold a recovered user row from the unattended spawn in both engines (#7300)

[._.]/ Adam Eivy873408585b84
diff --git a/server/services/cos.js b/server/services/cos.js
index e0688cc8fe..27ee8ecc2e 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -159,7 +159,7 @@ import {
// predicate are shared with the scheduler unit tests so they exercise the real
// guards instead of a local replica. The async tiers stay here as
// `spawnDequeuePriorityN(ctx)` helpers.
-import { closeStolenIdleReviewCard, createDequeueCapacity, countRunningAgentsByLocalEndpoint, isIdleTierEligible } from './cosDequeue.js';
+import { closeStolenIdleReviewCard, createDequeueCapacity, countRunningAgentsByLocalEndpoint, isIdleTierEligible, isUserTaskRunnableUnattended } from './cosDequeue.js';
import { buildLocalEndpointSlotContext, localEndpointCapacityError } from './cosLocalEndpointSlots.js';
import {
initializePersistentMindSupervisor,
@@ -1053,6 +1053,13 @@ async function spawnDequeuePriority1UserTasks(ctx) {
emitLog('debug', `Skipping user task ${task.id} — ${skipReason}`, { taskId: task.id });
continue;
}
+ // A user row that says it is NOT auto-approved is withheld from the unattended
+ // spawn (#7300) — see isUserTaskRunnableUnattended for why, and for why the
+ // rule lives in cosDequeue.js rather than once per engine.
+ if (!isUserTaskRunnableUnattended(task)) {
+ emitLog('debug', `Skipping user task ${task.id} — recovered row is not auto-approved`, { taskId: task.id });
+ continue;
+ }
if (await blockIfExceedsMaxSpawns(task, 'user')) continue;
const userTask = { ...task, taskType: 'user' };
if (!capacity.canSpawn(userTask)) continue;
diff --git a/server/services/cos.test.js b/server/services/cos.test.js
index 308ec06307..8eb432a147 100644
--- a/server/services/cos.test.js
+++ b/server/services/cos.test.js
@@ -36,7 +36,7 @@ import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { firstLine, isPerpetualRefillCandidate, perpetualRefillPlan } from './cos.js';
import { canQueueImprovementTasks, DEFAULT_STATE } from './cosState.js';
-import { createDequeueCapacity, countRunningAgentsByLocalEndpoint, isIdleTierEligible } from './cosDequeue.js';
+import { createDequeueCapacity, countRunningAgentsByLocalEndpoint, isIdleTierEligible, isUserTaskRunnableUnattended } from './cosDequeue.js';
import {
createLocalEndpointSlotContext,
cloudSwarmThreadCapacity,
@@ -112,6 +112,9 @@ function priorityDequeue(buckets, capacity, { paused = false } = {}) {
const committed = ['onDemand', 'idle'].includes(bucketName);
for (const task of buckets[bucketName] || []) {
if (capacity.spawned >= capacity.availableSlots) return;
+ // The user tier withholds a row that says it is not auto-approved (#7300),
+ // through the same predicate both production engines call.
+ if (bucketName === 'user' && !isUserTaskRunnableUnattended(task)) continue;
if (!(committed ? capacity.canSpawnCommitted(task) : capacity.canSpawn(task))) continue;
capacity.trackSpawn(task);
admitted.push({ ...task, _bucket: bucketName });
@@ -1288,6 +1291,43 @@ describe('cos.js source — priority + capacity invariants', () => {
expect(fnBody).toMatch(/if\s*\(\s*availableSlots\s*<=\s*0\s*\)/);
});
+ it('user tier withholds a recovered row, in BOTH spawn engines (#7300)', () => {
+ // A user row parses auto-approved unless the parser took its RECOVERY path,
+ // which cannot tell a genuine legacy row from a task-shaped sentence inside a
+ // legacy multi-line description body. This tier otherwise spawns every pending
+ // row, so without the predicate that sentence becomes an unattended agent run.
+ const state = makeState({ maxConcurrentAgents: 5 });
+ const capacity = makeCapacityTracker(state);
+
+ const buckets = {
+ onDemand: [],
+ user: [
+ { ...task('task-note'), autoApproved: false },
+ { ...task('task-real'), autoApproved: true },
+ task('task-fieldless'),
+ ],
+ autoSystem: [],
+ idle: [],
+ };
+
+ // `undefined` is not a hold — a row that never carried the field still runs,
+ // so the guard narrows nothing that was already running.
+ expect(priorityDequeue(buckets, capacity).map(t => t.id)).toEqual(['task-real', 'task-fieldless']);
+
+ // Both engines run their own user tier, so the rule has to be called in each —
+ // one is a fix, two is the fix. The shared body is cosDequeue.js's.
+ const cosTier = extractFnBody(COS_SRC, COS_SRC.indexOf('async function spawnDequeuePriority1UserTasks'));
+ const genTier = extractFnBody(GEN_SRC, GEN_SRC.indexOf('async function spawnPriority1UserTasks'));
+ for (const [label, body, emit] of [
+ ['cos.js', cosTier, "cosEvents.emit('task:ready', userTask)"],
+ ['cosTaskGenerator.js', genTier, 'tasksToSpawn.push(userTask)'],
+ ]) {
+ const guardIdx = body.indexOf('isUserTaskRunnableUnattended(task)');
+ expect(guardIdx, `${label} user tier must consult isUserTaskRunnableUnattended`).toBeGreaterThan(-1);
+ expect(body.indexOf(emit), `${label} must admit the task only after the guard`).toBeGreaterThan(guardIdx);
+ }
+ });
+
it('dequeueNextTask orchestrates the spawnDequeuePriority* tiers in priority order', () => {
// dequeueNextTask (cos.js) decomposes each priority tier into a named
// `spawnDequeuePriorityN(ctx)` helper (issue #2530), mirroring evaluateTasks.
diff --git a/server/services/cosDequeue.js b/server/services/cosDequeue.js
index 089b11db55..e5893326a2 100644
--- a/server/services/cosDequeue.js
+++ b/server/services/cosDequeue.js
@@ -172,3 +172,25 @@ export async function closeStolenIdleReviewCard(cardId, admittedTask) {
const { finishPreflightDispatch } = await import('./preflightTaskCard.js');
return finishPreflightDispatch(cardId, admittedTask?.id ?? null);
}
+
+/**
+ * Priority 1 (user) tier: is this pending user row runnable unattended?
+ *
+ * The user tier otherwise spawns EVERY pending row, so `autoApproved` carried no
+ * weight in the user file — and that is exactly where its `false` is most
+ * informative. A strict row always parses auto-approved, so `false` on a user row
+ * can only come from the parser's RECOVERY match (taskParser.js), which cannot
+ * tell a genuine legacy row from a task-shaped SENTENCE sitting at column 0 inside
+ * a legacy multi-line description body (#7300). Spawning that is an agent run
+ * minted from prose. The row is preserved and stays pending for a human.
+ *
+ * `undefined` is NOT that claim — a task built without the field (most user rows)
+ * stays runnable, so this narrows nothing that was already running.
+ *
+ * Lives beside `isIdleTierEligible` for the same reason: both spawn engines run
+ * their own copy of the user tier, and anything the two must agree on belongs in
+ * ONE body rather than in a pair of blocks a grep test has to police.
+ */
+export function isUserTaskRunnableUnattended(task) {
+ return task?.autoApproved !== false;
+}
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index f742148ddd..bf4d0835ef 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -48,7 +48,7 @@ import { getActiveApps, getAppTaskTypeOverrides } from './apps.js';
// The single Priority-0 on-demand loop body, shared with the dequeueNextTask
// engine in cos.js so the two can no longer drift (#6618).
import { drainOnDemandRequests } from './onDemandDrain.js';
-import { closeStolenIdleReviewCard, isIdleTierEligible } from './cosDequeue.js';
+import { closeStolenIdleReviewCard, isIdleTierEligible, isUserTaskRunnableUnattended } from './cosDequeue.js';
import { resolveAgentProviderPin } from './appTaskProviderPin.js';
import { getTaskTypeConfidence } from './taskLearning.js';
import { classifySafetyKind, requiresSafetyApproval } from './taskLearning/safetyKind.js';
@@ -918,6 +918,13 @@ async function spawnPriority1UserTasks(ctx) {
emitLog('debug', `Skipping user task ${task.id} — ${skipReason}`, { taskId: task.id });
continue;
}
+ // A user row that says it is NOT auto-approved is withheld from the unattended
+ // spawn (#7300) — see isUserTaskRunnableUnattended for why, and for why the
+ // rule lives in cosDequeue.js rather than once per engine.
+ if (!isUserTaskRunnableUnattended(task)) {
+ emitLog('debug', `Skipping user task ${task.id} — recovered row is not auto-approved`, { taskId: task.id });
+ continue;
+ }
if (await blockIfExceedsMaxSpawns(task, 'user')) continue;
const userTask = { ...task, taskType: 'user' };
if (!canSpawnTask(userTask)) {