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

feat: immediate task execution for user tasks and slot-free dequeue

Adam Eivy78314610258a
diff --git a/.changelog/v0.11.x.md b/.changelog/v0.11.x.md
index d4de6b8df0..f9312f9934 100644
--- a/.changelog/v0.11.x.md
+++ b/.changelog/v0.11.x.md
@@ -78,6 +78,12 @@ This release focuses on security improvements, bug fixes for the AI runner syste
### Autofixer App Replaced with PortOS Default
- Replaced the standalone Autofixer app with PortOS default app in sample data to avoid confusion
+### Immediate Task Execution for User Tasks
+- **Instant Spawn**: User-submitted tasks now start immediately when agent slots are available, instead of waiting up to 60 seconds for the next evaluation interval
+- **Slot-Free Dequeue**: When an agent completes and frees a slot, the next pending task is immediately dequeued and spawned without waiting for the evaluation cycle
+- **Priority Preserved**: Dequeue on slot free checks user tasks first, then auto-approved system tasks, maintaining the existing priority order
+- **Evaluation Interval Preserved**: The periodic evaluation interval continues to handle system task generation, idle reviews, and mission tasks — immediate execution is specifically for dequeuing pending work
+
## 🔧 Improvements
### Live Output Streaming for Claude CLI Agents
diff --git a/server/services/cos.js b/server/services/cos.js
index 84bd94f912..36e9887047 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -2555,9 +2555,87 @@ export async function addTask(taskData, taskType = 'user') {
await writeFile(filePath, markdown);
cosEvents.emit('tasks:changed', { type: taskType, action: 'added', task: newTask });
+
+ // Immediately attempt to spawn user tasks if slots are available
+ // This avoids waiting for the next evaluation interval (which is meant for system task generation)
+ if (taskType === 'user') {
+ setImmediate(() => tryImmediateSpawn(newTask));
+ }
+
return newTask;
}
+/**
+ * Attempt to immediately spawn a newly added user task if there are available agent slots.
+ * This bypasses the evaluation interval for user-submitted tasks so they start instantly.
+ */
+async function tryImmediateSpawn(task) {
+ if (!daemonRunning) return;
+
+ const paused = await isPaused();
+ if (paused) return;
+
+ const state = await loadState();
+ const runningAgents = Object.values(state.agents).filter(a => a.status === 'running').length;
+ const availableSlots = state.config.maxConcurrentAgents - runningAgents;
+
+ if (availableSlots <= 0) {
+ emitLog('debug', `⏳ Queued task ${task.id} - no available slots (${runningAgents}/${state.config.maxConcurrentAgents})`);
+ return;
+ }
+
+ emitLog('info', `⚡ Immediate spawn: ${task.id} (${task.priority || 'MEDIUM'})`, {
+ taskId: task.id,
+ availableSlots
+ });
+ cosEvents.emit('task:ready', { ...task, taskType: 'user' });
+}
+
+/**
+ * When an agent completes (freeing a slot), immediately try to dequeue and spawn the next pending task.
+ * Checks user tasks first, then auto-approved system tasks.
+ */
+async function dequeueNextTask() {
+ if (!daemonRunning) return;
+
+ const paused = await isPaused();
+ if (paused) return;
+
+ const state = await loadState();
+ const runningAgents = Object.values(state.agents).filter(a => a.status === 'running').length;
+ const availableSlots = state.config.maxConcurrentAgents - runningAgents;
+
+ if (availableSlots <= 0) return;
+
+ // Check user tasks first (highest priority)
+ const userTaskData = await getUserTasks();
+ const pendingUserTasks = userTaskData.grouped?.pending || [];
+
+ for (const task of pendingUserTasks) {
+ emitLog('info', `⚡ Dequeue on slot free: ${task.id} (${task.priority || 'MEDIUM'})`, {
+ taskId: task.id,
+ availableSlots
+ });
+ cosEvents.emit('task:ready', { ...task, taskType: 'user' });
+ return; // One at a time — let the next completion trigger more
+ }
+
+ // No user tasks — check auto-approved system tasks
+ const cosTaskData = await getCosTasks();
+ const autoApproved = cosTaskData.autoApproved || [];
+
+ for (const task of autoApproved) {
+ const appId = task.metadata?.app;
+ if (appId) {
+ const onCooldown = await isAppOnCooldown(appId, state.config.appReviewCooldownMs);
+ if (onCooldown) continue;
+ }
+ emitLog('info', `⚡ Dequeue system task on slot free: ${task.id}`, { taskId: task.id, availableSlots });
+ cosEvents.emit('task:ready', { ...task, taskType: 'internal' });
+ return;
+ }
+}
+
const PRIORITY_VALUES = {
'CRITICAL': 4,
'HIGH': 3,
@@ -2741,6 +2819,11 @@ export async function approveTask(taskId) {
async function init() {
await ensureDirectories();
+ // When an agent completes, immediately try to dequeue the next pending task
+ cosEvents.on('agent:completed', () => {
+ setImmediate(() => dequeueNextTask());
+ });
+
const state = await loadState();
// Auto-start if alwaysOn mode is enabled (or legacy autoStart)