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

fix: addTask dedup compares on first line so multi-line descriptions match

[._.]/ Adam Eivy33e13f97400a
diff --git a/server/services/cos.js b/server/services/cos.js
index 15a5d3e59d..a2e95d1d7c 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -52,6 +52,11 @@ export { generateReport, getReport, getTodayReport, listReports, listBriefings,
const AGENT_ARCHIVE_RETENTION_DAYS = 90;
const RESUME_DEQUEUE_DELAY_MS = 500;
+// First non-empty line of a string. Used by addTask dedup: stored descriptions
+// are flattened to a single line by generateTasksMarkdown, so the comparison
+// must normalize on the first line to match multi-line inputs.
+export const firstLine = (s) => (s || '').split('\n').map(l => l.trim()).find(l => l) || '';
+
const _execAsync = promisify(exec);
const _execFileAsync = promisify(execFile);
const execAsync = (cmd, opts) => _execAsync(cmd, { ...opts, windowsHide: true });
@@ -2191,14 +2196,14 @@ export async function addTask(taskData, taskType = 'user', { raw = false } = {})
tasks = parseTasksMarkdown(content);
}
- // Reject duplicate: same description already pending or in_progress
- const normalizedDesc = taskData.description.trim().toLowerCase();
+ // Reject duplicate: same first-line description already pending or in_progress.
+ const normalizedDesc = firstLine(taskData.description).toLowerCase();
const duplicate = tasks.find(t =>
(t.status === 'pending' || t.status === 'in_progress') &&
- t.description?.trim().toLowerCase() === normalizedDesc
+ firstLine(t.description).toLowerCase() === normalizedDesc
);
if (duplicate) {
- console.log(`⚠️ Duplicate task rejected: "${taskData.description.substring(0, 60)}" matches ${duplicate.id}`);
+ console.log(`⚠️ Duplicate task rejected: "${normalizedDesc.substring(0, 60)}" matches ${duplicate.id}`);
return { ...duplicate, duplicate: true };
}
diff --git a/server/services/cos.test.js b/server/services/cos.test.js
index de6b312a00..adbab013ed 100644
--- a/server/services/cos.test.js
+++ b/server/services/cos.test.js
@@ -32,6 +32,7 @@ import { describe, it, expect } from 'vitest';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
+import { firstLine } from './cos.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const COS_SRC = readFileSync(join(__dirname, 'cos.js'), 'utf-8');
@@ -648,3 +649,41 @@ describe('cos.js source — priority + capacity invariants', () => {
expect(evalFn).toMatch(/tasksToSpawn\.length\s*===\s*0\s*&&\s*state\.config\.idleReviewEnabled/);
});
});
+
+describe('addTask — first-line dedup', () => {
+ it('returns the first non-empty trimmed line', () => {
+ expect(firstLine('hello\nworld')).toBe('hello');
+ expect(firstLine('\n\n first \nsecond')).toBe('first');
+ expect(firstLine('single')).toBe('single');
+ });
+
+ it('returns empty string for null/undefined/empty input', () => {
+ expect(firstLine(null)).toBe('');
+ expect(firstLine(undefined)).toBe('');
+ expect(firstLine('')).toBe('');
+ expect(firstLine('\n\n\n')).toBe('');
+ });
+
+ it('multi-line and single-line descriptions with the same first line collide', () => {
+ // Repro: handleOrphanedTask builds a multi-line description, but
+ // generateTasksMarkdown flattens it to one line. Without first-line
+ // normalization, addTask's dedup compares the full multi-line input to
+ // the stored single line and never matches — producing N duplicate
+ // [Auto-Fix] tasks, each spawning its own agent.
+ const multi = '[Auto-Fix] Investigate repeated agent orphaning for task X\n\n**Last Orphaned Agent**: agent-aaa';
+ const stored = '[Auto-Fix] Investigate repeated agent orphaning for task X';
+ expect(firstLine(multi).toLowerCase()).toBe(firstLine(stored).toLowerCase());
+ });
+
+ it('addTask uses firstLine for dedup (regression guard)', () => {
+ // addTask's signature destructuring (`{ raw = false } = {}`) confuses the
+ // brace-balanced extractFnBody scanner — slice from the declaration to
+ // the next top-level function instead.
+ const start = COS_SRC.indexOf('export async function addTask');
+ expect(start, 'addTask must exist').toBeGreaterThan(-1);
+ const end = COS_SRC.indexOf('export async function', start + 1);
+ const fnBody = COS_SRC.slice(start, end === -1 ? undefined : end);
+ expect(fnBody).toMatch(/firstLine\(taskData\.description\)/);
+ expect(fnBody).toMatch(/firstLine\(t\.description\)/);
+ });
+});