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

test: tighten CoS admission parity coverage (#6767)

[._.]/ Adam Eivyf11703319d4e
diff --git a/server/services/cos.js b/server/services/cos.js
index be256232e1..bb15b69870 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -21,7 +21,7 @@ import { join } from 'path';
import { getActiveProvider } from './providers.js';
import { isInternalTaskId } from '../lib/taskParser.js';
import { isRetryHeld, isStaleRetryHold } from '../lib/taskRetryHold.js';
-import { isAppOnCooldown, clearStaleActiveAgents } from './appActivity.js';
+import { clearStaleActiveAgents } from './appActivity.js';
// The single Priority-0 on-demand loop body, shared with the evaluateTasks
// engine in cosTaskGenerator.js so the two can no longer drift (#6618).
import { drainOnDemandRequests } from './onDemandDrain.js';
diff --git a/server/services/cos.test.js b/server/services/cos.test.js
index 0297fbfc16..ff3c947578 100644
--- a/server/services/cos.test.js
+++ b/server/services/cos.test.js
@@ -1595,6 +1595,7 @@ describe('cos.js source — priority + capacity invariants', () => {
// (issue #2530) — both still live in the cos.js module, so scope to it.
const dequeueSrc = COS_SRC;
const dequeueP2 = extractFnBody(COS_SRC, COS_SRC.indexOf('async function spawnDequeuePriority2AutoApproved'));
+ const budgetResolver = extractFnBody(GEN_SRC, GEN_SRC.indexOf('export async function resolveAutonomyBudget'));
// evaluateTasks resolves the mode in `resolveAutonomyBudget` and fences each
// autonomous tier inside its spawnPriority* helper (issue #1082) — both still
// live in the cosTaskGenerator module, so scope to the whole engine source.
@@ -1602,8 +1603,8 @@ describe('cos.js source — priority + capacity invariants', () => {
expect(dequeueP2, 'dequeue Priority 2 must call the shared budget resolver').toMatch(/resolveAutonomyBudget\(/);
expect(evalFn, 'evaluateTasks must call the shared budget resolver').toMatch(/resolveAutonomyBudget\(/);
- expect(GEN_SRC, 'the one budget resolver must read the CoS autonomy mode')
- .toMatch(/export async function resolveAutonomyBudget[\s\S]*getDomainMode\(state\.config, 'cos'\)/);
+ expect(budgetResolver, 'the one budget resolver must read the CoS autonomy mode')
+ .toMatch(/getDomainMode\(state\.config, 'cos'\)/);
// evaluateTasks fences autonomous spawns inline on `cosAutonomyMode === 'execute'`.
expect(evalFn, `evaluateTasks must fence autonomous spawns on cosAutonomyMode === 'execute'`).toMatch(/cosAutonomyMode\s*===\s*['"]execute['"]/);
// Dequeue's mission/idle tiers gate through the shared predicates, and its
diff --git a/server/services/cosPriority2Parity.test.js b/server/services/cosPriority2Parity.test.js
index b40fb67ace..1566db78c1 100644
--- a/server/services/cosPriority2Parity.test.js
+++ b/server/services/cosPriority2Parity.test.js
@@ -6,6 +6,7 @@ const mocks = vi.hoisted(() => ({
emit: vi.fn(),
emitLog: vi.fn(),
recordDecision: vi.fn(async () => {}),
+ cooldownAppId: null,
}));
vi.mock('./cosEvents.js', () => ({
@@ -48,6 +49,10 @@ vi.mock('./decisionLog.js', async (importActual) => ({
...(await importActual()),
recordDecision: (...args) => mocks.recordDecision(...args),
}));
+vi.mock('./appActivity.js', async (importActual) => ({
+ ...(await importActual()),
+ isAppOnCooldown: async (appId) => appId === mocks.cooldownAppId,
+}));
vi.mock('./prWatcher.js', async (importActual) => ({
...(await importActual()),
sweepPendingMergePrs: async () => ({ merged: 0, escalated: 0, timedOut: 0 }),
@@ -117,6 +122,7 @@ function resetFixtures(mode = 'execute') {
awaitingApproval: [],
grouped: { pending: [], blocked: [] },
};
+ mocks.cooldownAppId = null;
}
beforeEach(() => {
@@ -166,3 +172,28 @@ describe.each(engines)('%s Priority-2 public boundary', (_name, run) => {
expect(dryRunIds()).toEqual(executeIds);
});
});
+
+it('keeps cooldown decision logging in the evaluate adapter only', async () => {
+ const blockedTask = { ...ordinaryTask('cooldown-task', 'enabled'), metadata: { analysisType: 'enabled', app: 'app-a' } };
+ mocks.cooldownAppId = 'app-a';
+ mocks.cosTaskData.autoApproved = [blockedTask];
+
+ await evaluateTasks();
+
+ expect(readyIds()).toEqual([]);
+ expect(mocks.recordDecision).toHaveBeenCalledWith(
+ 'cooldown_active',
+ expect.stringContaining('cooldown-task'),
+ expect.objectContaining({ taskId: 'cooldown-task', appId: 'app-a' }),
+ );
+
+ vi.clearAllMocks();
+ resetFixtures();
+ mocks.cooldownAppId = 'app-a';
+ mocks.cosTaskData.autoApproved = [blockedTask];
+
+ await dequeueNextTask();
+
+ expect(readyIds()).toEqual([]);
+ expect(mocks.recordDecision).not.toHaveBeenCalled();
+});
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index f071b6ee4b..a042fd2507 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -767,7 +767,10 @@ const analysisTypeForTask = (task) => task.metadata?.analysisType || task.metada
function isDisabledAnalysisType(task, taskSchedule) {
const analysisType = analysisTypeForTask(task);
- return Boolean(analysisType) && !taskSchedule.tasks[analysisType]?.enabled;
+ // The shared drain contract always supplies a schedule. If that contract is
+ // ever violated, fail closed for scheduled analysis work without aborting the
+ // rest of the evaluation cycle.
+ return Boolean(analysisType) && taskSchedule?.tasks?.[analysisType]?.enabled !== true;
}
/**
diff --git a/server/services/cosTaskGenerator.test.js b/server/services/cosTaskGenerator.test.js
index 0333fef056..cece2955e7 100644
--- a/server/services/cosTaskGenerator.test.js
+++ b/server/services/cosTaskGenerator.test.js
@@ -215,12 +215,22 @@ describe('claim reviewer resolution', () => {
// these source-level guards pin that both engines route through the ONE shared
// Priority-2 pass, whose dry-run hook set matches its own execute gates.
describe('dry-run hook wiring matches the shared execute path', () => {
+ const between = (src, startMarker, endMarker) => {
+ const start = src.indexOf(startMarker);
+ expect(start, `missing start marker: ${startMarker}`).toBeGreaterThan(-1);
+ const end = src.indexOf(endMarker, start);
+ expect(end, `missing end marker: ${endMarker}`).toBeGreaterThan(start);
+ return src.slice(start, end);
+ };
+
const callSite = () => {
// Anchor on the CALL (`await selectDryRunAutoApproved(`), not the function
// definition (`export async function selectDryRunAutoApproved(`).
const start = GEN_SRC.indexOf('await selectDryRunAutoApproved(');
expect(start, 'selectDryRunAutoApproved must be called').toBeGreaterThan(-1);
- return GEN_SRC.slice(start, GEN_SRC.indexOf('});', start) + 3);
+ const end = GEN_SRC.indexOf('});', start);
+ expect(end, 'selectDryRunAutoApproved call must close').toBeGreaterThan(start);
+ return GEN_SRC.slice(start, end + 3);
};
it('the shared pass applies cooldown exemption and disabled-analysis-type gates', () => {
@@ -233,9 +243,9 @@ describe('dry-run hook wiring matches the shared execute path', () => {
});
it('both engines delegate Priority 2 to admitAutoApprovedSystemTasks', () => {
- expect(COS_SRC.slice(COS_SRC.indexOf('async function spawnDequeuePriority2AutoApproved'), COS_SRC.indexOf('/**\n * Priority 3', COS_SRC.indexOf('async function spawnDequeuePriority2AutoApproved'))))
+ expect(between(COS_SRC, 'async function spawnDequeuePriority2AutoApproved', '/**\n * Priority 3'))
.toContain('admitAutoApprovedSystemTasks(');
- expect(GEN_SRC.slice(GEN_SRC.indexOf('async function spawnPriority2AutoApproved'), GEN_SRC.indexOf('/**\n * Background:', GEN_SRC.indexOf('async function spawnPriority2AutoApproved'))))
+ expect(between(GEN_SRC, 'async function spawnPriority2AutoApproved', '/**\n * Background:'))
.toContain('admitAutoApprovedSystemTasks(');
});