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
fix: prevent killed tasks from being requeued
Adam Eivyc810d3ae161d
diff --git a/.changelog/v0.11.x.md b/.changelog/v0.11.x.mdindex 9703e78324..d4de6b8df0 100644--- a/.changelog/v0.11.x.md+++ b/.changelog/v0.11.x.md@@ -70,6 +70,11 @@ This release focuses on security improvements, bug fixes for the AI runner syste- `client/src/components/brain/tabs/InboxTab.jsx` - Socket.IO listener for classification results, classifying section UI- `client/src/components/brain/constants.js` - Added `classifying` status color+### Killed Tasks No Longer Requeue+- **DevTools Kill Integration**: Killing a CoS agent via the DevTools process manager (`DELETE /api/agents/:pid`) now delegates to the CoS `killAgent()` function, which properly blocks the task instead of letting the close handler treat it as a retryable failure+- **Immediate Task Blocking**: Both `terminateAgent()` and `killAgent()` in direct mode now immediately update the task to `blocked` with `user-terminated` category, matching the runner mode behavior. Previously, task blocking was deferred to the close handler, creating a window where server restarts could cause requeue+- **Orphan Handler Guard**: `handleOrphanedTask()` now skips tasks already marked as `user-terminated`, preventing any residual requeue path+### Autofixer App Replaced with PortOS Default- Replaced the standalone Autofixer app with PortOS default app in sample data to avoid confusiondiff --git a/server/services/agents.js b/server/services/agents.jsindex ed9f045319..0b502dbb27 100644--- a/server/services/agents.js+++ b/server/services/agents.js@@ -265,7 +265,9 @@ function formatRuntime(ms) {}/**- * Kill a process by PID+ * Kill a process by PID.+ * If the process is a CoS-spawned agent, delegates to the CoS killAgent+ * to ensure the task is properly blocked instead of requeued.*/export async function killProcess(pid) {// Security: Ensure PID is a valid integer to prevent command injection@@ -274,6 +276,17 @@ export async function killProcess(pid) {throw new Error('Invalid PID provided');}+ // Check if this PID belongs to a CoS-spawned agent+ const spawnedData = spawnedAgentCommands.get(safePid);+ if (spawnedData?.agentId) {+ console.log(`🔪 PID ${safePid} is CoS agent ${spawnedData.agentId}, delegating to CoS killAgent`);+ const { killAgent } = await import('./subAgentSpawner.js');+ const result = await killAgent(spawnedData.agentId);+ if (result.success) return true;+ // Fall through to raw kill if CoS kill failed (agent may have already exited)+ console.log(`⚠️ CoS killAgent failed for ${spawnedData.agentId}: ${result.error}, falling back to raw kill`);+ }+const platform = process.platform;if (platform === 'win32') {diff --git a/server/services/subAgentSpawner.js b/server/services/subAgentSpawner.jsindex 5ad97cf77a..7e1e7fca6c 100644--- a/server/services/subAgentSpawner.js+++ b/server/services/subAgentSpawner.js@@ -13,7 +13,7 @@ import { writeFile, mkdir, readFile } from 'fs/promises';import { existsSync } from 'fs';import { homedir } from 'os';import { v4 as uuidv4 } from 'uuid';-import { cosEvents, registerAgent, updateAgent, completeAgent, appendAgentOutput, getConfig, updateTask, addTask, emitLog } from './cos.js';+import { cosEvents, registerAgent, updateAgent, completeAgent, appendAgentOutput, getConfig, updateTask, addTask, emitLog, getTaskById } from './cos.js';import { startAppCooldown, markAppReviewCompleted } from './appActivity.js';import { isRunnerAvailable, spawnAgentViaRunner, terminateAgentViaRunner, killAgentViaRunner, getAgentStatsFromRunner, initCosRunnerConnection, onCosRunnerEvent, getActiveAgentsFromRunner, getRunnerHealth } from './cosRunnerClient.js';import { getActiveProvider, getProviderById, getAllProviders } from './providers.js';@@ -2033,6 +2033,22 @@ export async function terminateAgent(agentId) {// Mark agent as completed immediately with termination statusawait completeAgent(agentId, { success: false, error: 'Agent terminated by user' });+ // Block task immediately (don't defer to close handler — prevents requeue on server restart)+ if (agent.taskId) {+ const task = await getTaskById(agent.taskId).catch(() => null);+ if (task) {+ await updateTask(agent.taskId, {+ status: 'blocked',+ metadata: {+ ...task.metadata,+ blockedReason: 'Terminated by user',+ blockedCategory: 'user-terminated',+ blockedAt: new Date().toISOString()+ }+ }, task.taskType || 'user');+ }+ }+// Kill the processagent.process.kill('SIGTERM');@@ -2127,6 +2143,22 @@ export async function killAgent(agentId) {// Mark agent as completed immediately with kill statusawait completeAgent(agentId, { success: false, error: 'Agent force killed by user (SIGKILL)' });+ // Block task immediately (don't defer to close handler — prevents requeue on server restart)+ if (agent.taskId) {+ const task = await getTaskById(agent.taskId).catch(() => null);+ if (task) {+ await updateTask(agent.taskId, {+ status: 'blocked',+ metadata: {+ ...task.metadata,+ blockedReason: 'Force killed by user',+ blockedCategory: 'user-terminated',+ blockedAt: new Date().toISOString()+ }+ }, task.taskType || 'user');+ }+ }+// Kill the process immediately with SIGKILLagent.process.kill('SIGKILL');@@ -2324,6 +2356,12 @@ async function handleOrphanedTask(taskId, agentId, getTaskById) {return;}+ // Never requeue tasks that were explicitly terminated by the user+ if (task.status === 'blocked' && task.metadata?.blockedCategory === 'user-terminated') {+ emitLog('info', `⏭️ Skipping orphaned task ${taskId} — user-terminated`, { taskId, agentId });+ return;+ }+// Get current retry count from task metadataconst retryCount = (task.metadata?.orphanRetryCount || 0) + 1;const taskType = task.taskType || 'user';