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
feat(cos): add per-project agent concurrency limits
Adam Eivya9e48360725a
diff --git a/.changelog/v0.14.x.md b/.changelog/v0.14.x.mdindex c8a3214d17..0bcc326b09 100644--- a/.changelog/v0.14.x.md+++ b/.changelog/v0.14.x.md@@ -29,6 +29,12 @@ This release adds Ghostty terminal theme integration and a project update workfl### Agent Card App Badge- **App name visible on agent cards** — running and completed agent cards now display a cyan badge showing which app the agent is working on (e.g., "portos", "kalshibot"), with workspace path tooltip on hover+### Per-Project Agent Concurrency Limits+- **`maxConcurrentAgentsPerProject` config** — new setting that caps how many agents can run simultaneously for any single project, preventing one app from hogging all available slots+- **Dual-limit enforcement** — the existing `maxConcurrentAgents` acts as the global cap, while the new per-project limit ensures fair distribution across projects+- **Autonomy level presets updated** — Standby (1/1), Assistant (2/1), Manager (3/2), YOLO (5/3) now include per-project defaults+- **ConfigTab UI** — new "Max Agents Per Project" row in the configuration panel with tooltip explaining the behavior+### System Health Widget- **Dashboard health overview** — new widget at the top of the dashboard showing server uptime, memory/CPU usage, PM2 process status, and app health at a glance- **Color-coded status indicators** — healthy (green), warning (yellow), or critical (red) based on system metricsdiff --git a/client/src/components/cos/constants.js b/client/src/components/cos/constants.jsindex de689d7bd0..d0d893d46b 100644--- a/client/src/components/cos/constants.js+++ b/client/src/components/cos/constants.js@@ -70,6 +70,7 @@ export const AUTONOMY_LEVELS = [params: {evaluationIntervalMs: 300000, // 5 minmaxConcurrentAgents: 1,+ maxConcurrentAgentsPerProject: 1,selfImprovementEnabled: false,appImprovementEnabled: false,proactiveMode: false,@@ -86,6 +87,7 @@ export const AUTONOMY_LEVELS = [params: {evaluationIntervalMs: 120000, // 2 minmaxConcurrentAgents: 2,+ maxConcurrentAgentsPerProject: 1,selfImprovementEnabled: true,appImprovementEnabled: false,proactiveMode: false,@@ -102,6 +104,7 @@ export const AUTONOMY_LEVELS = [params: {evaluationIntervalMs: 60000, // 1 minmaxConcurrentAgents: 3,+ maxConcurrentAgentsPerProject: 2,selfImprovementEnabled: true,appImprovementEnabled: true,proactiveMode: false,@@ -118,6 +121,7 @@ export const AUTONOMY_LEVELS = [params: {evaluationIntervalMs: 30000, // 30 secmaxConcurrentAgents: 5,+ maxConcurrentAgentsPerProject: 3,selfImprovementEnabled: true,appImprovementEnabled: true,proactiveMode: true,diff --git a/client/src/components/cos/tabs/ConfigTab.jsx b/client/src/components/cos/tabs/ConfigTab.jsxindex 31ccc29fa5..70a1097faf 100644--- a/client/src/components/cos/tabs/ConfigTab.jsx+++ b/client/src/components/cos/tabs/ConfigTab.jsx@@ -29,6 +29,7 @@ const LEVEL_COLORS = {const PARAM_LABELS = {evaluationIntervalMs: 'Eval',maxConcurrentAgents: 'Agents',+ maxConcurrentAgentsPerProject: 'Per Project',selfImprovementEnabled: 'Self',appImprovementEnabled: 'App',proactiveMode: 'Proactive',@@ -136,6 +137,7 @@ export default function ConfigTab({ config, onUpdate, onEvaluate, avatarStyle, sevaluationIntervalMs: config?.evaluationIntervalMs || 60000,healthCheckIntervalMs: config?.healthCheckIntervalMs || 900000,maxConcurrentAgents: config?.maxConcurrentAgents || 3,+ maxConcurrentAgentsPerProject: config?.maxConcurrentAgentsPerProject || 2,maxProcessMemoryMb: config?.maxProcessMemoryMb || 2048,autoStart: config?.autoStart || false,selfImprovementEnabled: config?.selfImprovementEnabled ?? true,@@ -230,7 +232,16 @@ export default function ConfigTab({ config, onUpdate, onEvaluate, avatarStyle, stype="number"inputValue={formData.maxConcurrentAgents}onChange={v => setFormData(f => ({ ...f, maxConcurrentAgents: v }))}- tooltip="Maximum number of AI agents that can run simultaneously"+ tooltip="Maximum total number of AI agents that can run simultaneously across all projects"+ />+ <ConfigRow+ label="Max Agents Per Project"+ value={formData.maxConcurrentAgentsPerProject}+ editing={editing}+ type="number"+ inputValue={formData.maxConcurrentAgentsPerProject}+ onChange={v => setFormData(f => ({ ...f, maxConcurrentAgentsPerProject: v }))}+ tooltip="Maximum agents per individual project — prevents one project from using all available slots"/><ConfigRowlabel="Max Process Memory"diff --git a/data.sample/cos/state.json b/data.sample/cos/state.jsonindex c68d6f3745..356e9b7559 100644--- a/data.sample/cos/state.json+++ b/data.sample/cos/state.json@@ -6,6 +6,7 @@"evaluationIntervalMs": 60000,"healthCheckIntervalMs": 900000,"maxConcurrentAgents": 3,+ "maxConcurrentAgentsPerProject": 2,"maxProcessMemoryMb": 2048,"maxTotalProcesses": 50,"mcpServers": [diff --git a/docs/features/chief-of-staff.md b/docs/features/chief-of-staff.mdindex 7eb582fd6c..d99c54a303 100644--- a/docs/features/chief-of-staff.md+++ b/docs/features/chief-of-staff.md@@ -76,7 +76,8 @@ The `selectModelForTask` function routes tasks to appropriate model tiers:|---------|---------|-------------|| evaluationIntervalMs | 60000 | Task evaluation interval (1 minute) || healthCheckIntervalMs | 900000 | Health check interval (15 minutes) |-| maxConcurrentAgents | 3 | Max parallel agents |+| maxConcurrentAgents | 3 | Max parallel agents (global) |+| maxConcurrentAgentsPerProject | 2 | Max parallel agents per project || maxProcessMemoryMb | 2048 | Memory alert threshold || autoStart | false | Start on server boot || selfImprovementEnabled | true | Allow self-analysis |diff --git a/server/services/cos.js b/server/services/cos.jsindex b81ebb2cbe..24516392d1 100644--- a/server/services/cos.js+++ b/server/services/cos.js@@ -88,6 +88,7 @@ const DEFAULT_CONFIG = {evaluationIntervalMs: 60000, // 1 minute - stay active, check frequentlyhealthCheckIntervalMs: 900000, // 15 minutesmaxConcurrentAgents: 3,+ maxConcurrentAgentsPerProject: 2, // Per-project limit (prevents one project hogging all slots)maxProcessMemoryMb: 2048, // Alert if any process exceeds thismaxTotalProcesses: 50, // Alert if total PM2 processes exceed thismcpServers: [@@ -492,6 +493,30 @@ async function resetOrphanedTasks() {}}+/**+ * Count running agents grouped by project (app ID).+ * Agents without an app (self-improvement, PortOS tasks) are grouped under '_self'.+ */+function countRunningAgentsByProject(agents) {+ const counts = {};+ for (const agent of Object.values(agents)) {+ if (agent.status !== 'running') continue;+ const project = agent.metadata?.taskApp || agent.metadata?.app || '_self';+ counts[project] = (counts[project] || 0) + 1;+ }+ return counts;+}++/**+ * Check if a task would exceed the per-project concurrency limit.+ * Returns true if the task can be spawned (within limit), false otherwise.+ */+function isWithinProjectLimit(task, agentsByProject, perProjectLimit) {+ const project = task.metadata?.app || '_self';+ const current = agentsByProject[project] || 0;+ return current < perProjectLimit;+}+/*** Evaluate tasks and decide what to spawn*@@ -521,9 +546,11 @@ export async function evaluateTasks() {// Get both user and CoS tasksconst { user: userTaskData, cos: cosTaskData } = await getAllTasks();- // Count running agents and available slots+ // Count running agents and available slots (global + per-project)const runningAgents = Object.values(state.agents).filter(a => a.status === 'running').length;const availableSlots = state.config.maxConcurrentAgents - runningAgents;+ const perProjectLimit = state.config.maxConcurrentAgentsPerProject || state.config.maxConcurrentAgents;+ const agentsByProject = countRunningAgentsByProject(state.agents);if (availableSlots <= 0) {emitLog('warn', `Max concurrent agents reached (${runningAgents}/${state.config.maxConcurrentAgents})`);@@ -532,6 +559,20 @@ export async function evaluateTasks() {}const tasksToSpawn = [];+ // Track per-project counts including tasks we're about to spawn in this batch+ const spawnProjectCounts = { ...agentsByProject };++ // Helper: check if a task can spawn (within both global and per-project limits)+ const canSpawnTask = (task) => {+ if (tasksToSpawn.length >= availableSlots) return false;+ const project = task.metadata?.app || '_self';+ return (spawnProjectCounts[project] || 0) < perProjectLimit;+ };+ // Helper: track a spawned task's project+ const trackSpawn = (task) => {+ const project = task.metadata?.app || '_self';+ spawnProjectCounts[project] = (spawnProjectCounts[project] || 0) + 1;+ };// Priority 0: On-demand task requests (highest priority - user explicitly requested these)const taskSchedule = await import('./taskSchedule.js');@@ -594,8 +635,9 @@ export async function evaluateTasks() {task = await generateManagedAppImprovementTaskForType(request.taskType, targetApp, state);}- if (task) {+ if (task && canSpawnTask(task)) {tasksToSpawn.push(task);+ trackSpawn(task);}}}@@ -604,7 +646,13 @@ export async function evaluateTasks() {const pendingUserTasks = userTaskData.grouped?.pending || [];for (const task of pendingUserTasks) {if (tasksToSpawn.length >= availableSlots) break;- tasksToSpawn.push({ ...task, taskType: 'user' });+ const userTask = { ...task, taskType: 'user' };+ if (!canSpawnTask(userTask)) {+ emitLog('debug', `⏳ Queued user task ${task.id} - per-project limit reached for ${task.metadata?.app || '_self'}`);+ continue;+ }+ tasksToSpawn.push(userTask);+ trackSpawn(userTask);}// Priority 2: Auto-approved system tasks (if slots available)@@ -623,7 +671,13 @@ export async function evaluateTasks() {}}- tasksToSpawn.push({ ...task, taskType: 'internal' });+ const sysTask = { ...task, taskType: 'internal' };+ if (!canSpawnTask(sysTask)) {+ emitLog('debug', `⏳ Queued system task ${task.id} - per-project limit reached for ${appId || '_self'}`);+ continue;+ }+ tasksToSpawn.push(sysTask);+ trackSpawn(sysTask);}}@@ -647,7 +701,7 @@ export async function evaluateTasks() {for (const missionTask of missionTasks) {if (tasksToSpawn.length >= availableSlots) break;// Convert mission task to COS task format- tasksToSpawn.push({+ const cosTask = {id: missionTask.id,description: missionTask.description,priority: missionTask.priority?.toUpperCase() || 'MEDIUM',@@ -655,7 +709,10 @@ export async function evaluateTasks() {metadata: missionTask.metadata,taskType: 'internal',approvalRequired: !missionTask.autoApprove- });+ };+ if (!canSpawnTask(cosTask)) continue;+ tasksToSpawn.push(cosTask);+ trackSpawn(cosTask);emitLog('info', `Generated mission task: ${missionTask.id} (${missionTask.metadata?.missionName})`, {missionId: missionTask.metadata?.missionId,appId: missionTask.metadata?.appId@@ -673,7 +730,9 @@ export async function evaluateTasks() {for (const job of dueJobs) {if (tasksToSpawn.length >= availableSlots) break;const task = await generateTaskFromJob(job);+ if (!canSpawnTask(task)) continue;tasksToSpawn.push(task);+ trackSpawn(task);emitLog('info', `Autonomous job due: ${job.name} (${job.reason})`, {jobId: job.id,category: job.category@@ -690,8 +749,9 @@ export async function evaluateTasks() {const pendingSystemTasks = freshCosTasks.autoApproved?.length || 0;if (pendingSystemTasks === 0) {const idleTask = await generateIdleReviewTask(state);- if (idleTask) {+ if (idleTask && canSpawnTask(idleTask)) {tasksToSpawn.push(idleTask);+ trackSpawn(idleTask);}}}@@ -2882,6 +2942,15 @@ async function tryImmediateSpawn(task) {return;}+ // Check per-project limit+ const perProjectLimit = state.config.maxConcurrentAgentsPerProject || state.config.maxConcurrentAgents;+ const agentsByProject = countRunningAgentsByProject(state.agents);+ if (!isWithinProjectLimit(task, agentsByProject, perProjectLimit)) {+ const project = task.metadata?.app || '_self';+ emitLog('debug', `⏳ Queued task ${task.id} - per-project limit reached for ${project} (${agentsByProject[project] || 0}/${perProjectLimit})`);+ return;+ }+emitLog('info', `⚡ Immediate spawn: ${task.id} (${task.priority || 'MEDIUM'})`, {taskId: task.id,availableSlots@@ -2905,11 +2974,15 @@ async function dequeueNextTask() {if (availableSlots <= 0) return;+ const perProjectLimit = state.config.maxConcurrentAgentsPerProject || state.config.maxConcurrentAgents;+ const agentsByProject = countRunningAgentsByProject(state.agents);+// Check user tasks first (highest priority)const userTaskData = await getUserTasks();const pendingUserTasks = userTaskData.grouped?.pending || [];for (const task of pendingUserTasks) {+ if (!isWithinProjectLimit(task, agentsByProject, perProjectLimit)) continue;emitLog('info', `⚡ Dequeue on slot free: ${task.id} (${task.priority || 'MEDIUM'})`, {taskId: task.id,availableSlots@@ -2928,6 +3001,7 @@ async function dequeueNextTask() {const onCooldown = await isAppOnCooldown(appId, state.config.appReviewCooldownMs);if (onCooldown) continue;}+ if (!isWithinProjectLimit(task, agentsByProject, perProjectLimit)) continue;emitLog('info', `⚡ Dequeue system task on slot free: ${task.id}`, { taskId: task.id, availableSlots });cosEvents.emit('task:ready', { ...task, taskType: 'internal' });return;