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

docs(cos): clarify Run Now daily budget accounting (#12577)

[._.]/ Adam Eivycf67da09c7ed
diff --git a/server/services/cosAgentLifecycle.js b/server/services/cosAgentLifecycle.js
index 03a76904f8..b098839128 100644
--- a/server/services/cosAgentLifecycle.js
+++ b/server/services/cosAgentLifecycle.js
@@ -279,9 +279,9 @@ export async function completeAgent(agentId, result = {}) {
return completed;
}
- // Daily CoS budget accounting (#711): count only AUTONOMOUS runs (non-user
- // tasks) — the same set the CoS auto-run gate withholds when over budget —
- // toward the domain's actions/minutes ledger. Recorded outside the state lock
+ // Daily CoS budget accounting (#711): all non-user runs, including on-demand
+ // work that bypasses the auto-run mode gate and pause, count toward the
+ // domain's actions/minutes ledger. Recorded outside the state lock
// (separate ledger file + write tail) so it never serializes against state.json.
//
// This MUST land before the `agent:completed` emit below: that event's handler
diff --git a/server/services/cosAgentLifecycle.test.js b/server/services/cosAgentLifecycle.test.js
index 458b6e5db5..77bf487366 100644
--- a/server/services/cosAgentLifecycle.test.js
+++ b/server/services/cosAgentLifecycle.test.js
@@ -357,7 +357,10 @@ describe('completeAgent budget-ledger ordering (#1683)', () => {
cosEvents.removeAllListeners('agent:completed');
});
- it('records the autonomous action usage BEFORE emitting agent:completed', async () => {
+ it.each([
+ ['scheduled', { taskType: 'scheduled' }],
+ ['on-demand', { taskType: 'internal', onDemand: true }],
+ ])('records %s action usage BEFORE emitting agent:completed', async (_kind, metadata) => {
// The agent:completed handler schedules dequeueNextTask(), whose daily
// action-budget gate reads the usage ledger. If the emit beats the ledger
// write, the gate counts stale usage and can admit one spawn past the cap.
@@ -369,7 +372,7 @@ describe('completeAgent budget-ledger ordering (#1683)', () => {
mockCosState.state.agents[agentId] = {
id: agentId,
status: 'running',
- metadata: { taskType: 'scheduled' }
+ metadata
};
await completeAgent(agentId, { success: true, duration: 1200 });
diff --git a/server/services/cosTaskGenerator.budget.test.js b/server/services/cosTaskGenerator.budget.test.js
new file mode 100644
index 0000000000..ea999c0aa3
--- /dev/null
+++ b/server/services/cosTaskGenerator.budget.test.js
@@ -0,0 +1,25 @@
+import { expect, it, vi } from 'vitest';
+
+vi.mock('./domainUsage.js', async (actual) => ({
+ ...await actual(),
+ getDomainBudgetStatus: async () => ({
+ budget: { maxActionsPerDay: 6 },
+ usage: { actions: 1 },
+ exceeded: null,
+ }),
+}));
+
+import { resolveAutonomyBudget } from './cosTaskGenerator.js';
+
+it('reserves daily actions for all in-flight on-demand origins while exempting user tasks (#12577)', async () => {
+ const running = [
+ // Older requests omit the origin; they still count as non-user work.
+ ...[undefined, 'user', 'refill', 'quota-burn'].map(onDemandOrigin => ({
+ metadata: { taskType: 'internal', onDemand: true, onDemandOrigin },
+ })),
+ { metadata: { taskType: 'user' } },
+ ];
+
+ expect(await resolveAutonomyBudget({ config: { domainAutonomy: { cos: 'execute' } } }, running))
+ .toEqual({ cosAutonomyMode: 'execute', autonomousActionsRemaining: 1 });
+});
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index 45d5e0a856..a1812aaa6c 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -505,9 +505,11 @@ export async function unblockExpiredCooldowns(userTaskData, cosTaskData) {
* many autonomous admissions the autonomous tiers may add this cycle.
*
* Off/dry-run withhold all AUTOMATIC internal spawns (auto-approved system
- * tasks, feature-agent, idle-review); user and on-demand tasks are
- * unaffected. Usage is tallied in completeAgent for autonomous runs only, so a
- * pure dry-run never accrues; user/on-demand spawns are already past this gate.
+ * tasks, feature-agent, idle-review). User and on-demand tasks bypass this mode
+ * gate; on-demand tasks also bypass the global pause. All non-user runs,
+ * including on-demand work, count toward the daily actions/minutes ledger in
+ * completeAgent and the in-flight action allowance here. A pure dry-run never
+ * accrues usage.
*
* @returns {Promise<{ cosAutonomyMode: string, autonomousActionsRemaining: number }>}
*/
@@ -706,11 +708,12 @@ export async function admitPendingUserTasks({ pendingUserTasks, instanceId }, ad
}
/**
- * Priority 0: On-demand task requests (highest priority — user explicitly
- * requested these). Reads the live schedule's `onDemandRequests`, clears each
+ * Priority 0: On-demand task requests, including user, refill and quota-burn
+ * origins. Reads the live schedule's `onDemandRequests`, clears each
* as it is processed, and admits any produced task (deduped) through the
- * cycle's shared `spawnAdapter`. Runs against the global slot cap — on-demand
- * work never counts against the autonomous action budget.
+ * cycle's shared `spawnAdapter`. On-demand work bypasses the auto-run mode gate
+ * and global pause, but uses global slots and counts toward the daily budget
+ * like other non-user runs.
*
* Returns the schedule the drain loaded so `evaluateTasks` can hand it to
* Priority 2 explicitly (its disabled-analysis-type gate) instead of a second
@@ -998,11 +1001,12 @@ export async function evaluateTasks(options) {
// 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`.
+ // Ceiling for AUTOMATIC admissions this cycle (#711). User and on-demand
+ // tasks already bypassed the mode gate; on-demand also bypasses pause. The
+ // automatic tiers may add at most `autonomousActionsRemaining` more tasks.
+ // On-demand runs still count as non-user work in the completion ledger and
+ // subsequent in-flight allowance; only user tasks are exempt. With no action
+ // cap this equals `availableSlots`.
const autonomousSlotCeiling = Math.min(availableSlots, tasksToSpawn.length + autonomousActionsRemaining);
// Priorities 2, 3.6, 4 spend against the lower autonomous ceiling.