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

fix: mission and idle tiers must not drop a task at a saturated endpoint (#4834)

[._.]/ Adam Eivya83b10a30379
diff --git a/server/services/cos.js b/server/services/cos.js
index a6e85a7397..f77d5b98f2 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -1183,7 +1183,13 @@ async function spawnDequeuePriority3Missions(ctx) {
taskType: 'internal',
approvalRequired: !missionTask.autoApprove
};
- if (!capacity.canSpawn(cosTask, ctx.autonomousSpawnCeiling)) continue;
+ // `gateLocalEndpoint: false` — same reason as Priority 0 (#4834). Mission
+ // tasks are never written to COS-TASKS.md, and `generateMissionTasks` has
+ // ALREADY flipped the sub-task to `in_progress` and saved the mission by the
+ // time we get here. A denial would drop the only copy of a sub-task that
+ // `generateMissionTask` will never re-pick (it selects `pending` only).
+ // Emitting lets the chokepoint hold it instead.
+ if (!capacity.canSpawn(cosTask, ctx.autonomousSpawnCeiling, { gateLocalEndpoint: false })) continue;
cosEvents.emit('task:ready', cosTask);
capacity.trackSpawn(cosTask);
emitLog('info', `Generated mission task: ${missionTask.id}`, {
@@ -1211,7 +1217,12 @@ async function spawnDequeuePriority4IdleReview(ctx) {
const pendingSystemTasks = freshCosTasks.autoApproved?.length || 0;
if (pendingSystemTasks === 0) {
const idleTask = await generateIdleReviewTask(state, { ignoreTaskId });
- if (idleTask && capacity.canSpawn(idleTask, ctx.autonomousSpawnCeiling)) {
+ // `gateLocalEndpoint: false` — same reason as Priority 0 (#4834).
+ // `generateIdleReviewTask` has already bound the app-review marker and
+ // advanced the 30-minute review cooldown by the time we get here, and only
+ // `holdTask` releases that marker — which requires the emit. A denial would
+ // leave the app reading "in review" indefinitely (issue #978's failure mode).
+ if (idleTask && capacity.canSpawn(idleTask, ctx.autonomousSpawnCeiling, { gateLocalEndpoint: false })) {
cosEvents.emit('task:ready', idleTask);
capacity.trackSpawn(idleTask);
}
diff --git a/server/services/cos.test.js b/server/services/cos.test.js
index ee66bfff18..81be0b00e3 100644
--- a/server/services/cos.test.js
+++ b/server/services/cos.test.js
@@ -104,10 +104,12 @@ function priorityDequeue(buckets, capacity, { paused = false } = {}) {
const ceiling = capacity.availableSlots;
const drain = (bucketName) => {
- // Priority 0 opts OUT of the local-endpoint cap, exactly as production does:
- // a denial there discards the already-cleared on-demand request instead of
- // deferring it, so the task is emitted and the spawner chokepoint holds it.
- const opts = { gateLocalEndpoint: bucketName !== 'onDemand' };
+ // Priorities 0, 3 and 4 opt OUT of the local-endpoint cap, exactly as
+ // production does: a denial there DISCARDS an already-committed task (a
+ // cleared on-demand request, an `in_progress` mission sub-task, a bound
+ // app-review marker) instead of deferring it, so they emit and let the
+ // spawner chokepoint hold.
+ const opts = { gateLocalEndpoint: !['onDemand', 'mission', 'idle'].includes(bucketName) };
for (const task of buckets[bucketName] || []) {
if (capacity.spawned >= capacity.availableSlots) return;
if (!capacity.canSpawn(task, undefined, opts)) continue;
@@ -570,6 +572,49 @@ describe('dequeueNextTask — per-local-endpoint agent cap (#4834)', () => {
expect(holds).toEqual([]);
});
+ it('does NOT suppress a mission or idle task at a saturated endpoint', () => {
+ // Both tiers commit before canSpawn and never persist: Priority 3 has
+ // already flipped the mission sub-task to `in_progress` (and only `pending`
+ // sub-tasks are ever re-picked), Priority 4 has already bound the app-review
+ // marker and advanced its 30-minute cooldown. A denial strands both; the
+ // chokepoint's hold at least releases the marker.
+ const state = makeState({
+ maxConcurrentAgents: 5,
+ runningAgents: [makeRunningAgentOnProvider('lmstudio-tui')],
+ });
+ const { capacity } = makeLocalSlotCapacity(state);
+
+ const spawned = priorityDequeue({
+ onDemand: [],
+ user: [],
+ autoSystem: [],
+ mission: [taskOnProvider('mission-task', 'lmstudio-tui')],
+ idle: [],
+ }, capacity);
+
+ expect(spawned.map(t => t.id)).toEqual(['mission-task']);
+ });
+
+ it('keeps gating the deferrable tiers (1 and 2) at the same endpoint', () => {
+ // The opt-out is scoped to the tiers whose denial is destructive. A
+ // persisted user- or system-queue task stays queued, which is a real defer.
+ const state = makeState({
+ maxConcurrentAgents: 5,
+ runningAgents: [makeRunningAgentOnProvider('lmstudio-tui')],
+ });
+ const { capacity } = makeLocalSlotCapacity(state);
+
+ const spawned = priorityDequeue({
+ onDemand: [],
+ user: [],
+ autoSystem: [taskOnProvider('system-task', 'lmstudio-tui')],
+ mission: [],
+ idle: [],
+ }, capacity);
+
+ expect(spawned).toEqual([]);
+ });
+
it('still gates the SAME task from a deferrable tier', () => {
// The opt-out is scoped to Priority 0. A user-tier task at the same endpoint
// stays queued, because skipping it there is a genuine defer.
@@ -1411,14 +1456,19 @@ describe('cos.js source — priority + capacity invariants', () => {
.toMatch(/getFallbackProvider\(/);
});
- it('Priority 0 opts out of the local-endpoint cap so a Run is never discarded (#4834)', () => {
- // The on-demand tier clears the request and binds the app-review marker
- // before canSpawn, and is the only path that persists the task — a denial
- // there is destructive, not a defer. Pin the opt-out at the call site.
- const p0 = extractFnBody(COS_SRC, COS_SRC.indexOf('async function spawnDequeuePriority0OnDemand'));
- expect(p0).toMatch(/canSpawn\(task,\s*undefined,\s*\{\s*gateLocalEndpoint:\s*false\s*\}\)/);
- // Every other tier keeps the cap: none of them may pass the opt-out.
- for (const tier of ['spawnDequeuePriority1UserTasks', 'spawnDequeuePriority2AutoApproved', 'spawnDequeuePriority3Missions', 'spawnDequeuePriority4IdleReview']) {
+ it('the DESTRUCTIVE-denial tiers opt out of the local-endpoint cap (#4834)', () => {
+ // Priorities 0, 3 and 4 each commit side effects before `canSpawn` and never
+ // persist the task, so a denial DISCARDS it rather than deferring it: the
+ // on-demand request is already cleared, the mission sub-task is already
+ // flipped to `in_progress` (and only `pending` ones are ever re-picked), the
+ // app-review marker is already bound. They emit and let the chokepoint hold.
+ // Priorities 1 and 2 read from persisted queues, so skipping there is a
+ // genuine defer — they keep the cap.
+ for (const tier of ['spawnDequeuePriority0OnDemand', 'spawnDequeuePriority3Missions', 'spawnDequeuePriority4IdleReview']) {
+ const body = extractFnBody(COS_SRC, COS_SRC.indexOf(`async function ${tier}`));
+ expect(body, `${tier} must opt out of the local-endpoint cap`).toMatch(/gateLocalEndpoint:\s*false/);
+ }
+ for (const tier of ['spawnDequeuePriority1UserTasks', 'spawnDequeuePriority2AutoApproved']) {
const body = extractFnBody(COS_SRC, COS_SRC.indexOf(`async function ${tier}`));
expect(body, `${tier} must not opt out of the local-endpoint cap`).not.toMatch(/gateLocalEndpoint:\s*false/);
}
diff --git a/server/services/cosDequeue.js b/server/services/cosDequeue.js
index 704d896472..d11c90a429 100644
--- a/server/services/cosDequeue.js
+++ b/server/services/cosDequeue.js
@@ -46,13 +46,21 @@
* fires on a denial so the scheduler can log queued-no-slot without this module
* importing the event bus.
*
- * `gateLocalEndpoint: false` opts a tier out of that third cap. Priority 0 does,
- * because a denial there is DESTRUCTIVE, not a defer: the on-demand request has
- * already been cleared and the app-review marker bound by the time `canSpawn`
- * runs, so a `false` discards the user's explicit "Run" and strands the marker.
+ * `gateLocalEndpoint: false` opts a tier out of that third cap. Three tiers do,
+ * because a denial there is DESTRUCTIVE rather than a defer — each has already
+ * committed side effects by the time `canSpawn` runs, and none of them persists
+ * the task, so `false` discards the only copy:
+ *
+ * - Priority 0 has cleared the on-demand request and bound the app-review
+ * marker — a denial silently swallows the user's explicit "Run".
+ * - Priority 3 has flipped the mission sub-task to `in_progress` and saved the
+ * mission; `generateMissionTask` only ever re-picks `pending` sub-tasks.
+ * - Priority 4 has bound the app-review marker and advanced the 30-minute
+ * review cooldown (issue #978's failure mode).
+ *
* Emitting instead is strictly better — the authoritative cap at subAgentSpawner's
* `task:ready` chokepoint HOLDS the task (still `pending`, marker released, job
- * reservation freed), which is exactly the outcome this tier cannot produce.
+ * reservation freed), which is exactly the outcome these tiers cannot produce.
* The global/per-project caps carry the same hazard here; that is pre-existing.
*/
export function createDequeueCapacity(state, {