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
address review (codex): dedupe blocked investigations too; mirror merged affectedTasks into survivor description
[._.]/ Adam Eivybf7479b233cf
diff --git a/server/services/cosTaskMerge.js b/server/services/cosTaskMerge.jsindex 6cafeb73af..ff975753f2 100644--- a/server/services/cosTaskMerge.js+++ b/server/services/cosTaskMerge.js@@ -278,11 +278,24 @@ function normalizeAdopted(task) {};}-// (rule 4) The terminal status an OPEN investigation loser is flipped to when a-// same-fingerprint winner is chosen. `completed` (not `blocked`) — the duplicate-// is subsumed, not stuck; it needs no further work. Marked with `supersededBy` so-// the collapse is auditable and the pass stays idempotent (a superseded copy is-// terminal, so it never re-enters the open-duplicate set on the next sweep).+// (rule 4) The statuses at which an investigation is still OPEN — a live dedup+// candidate that suppresses new same-cause creates. MUST mirror+// agentErrorAnalysis.OPEN_INVESTIGATION_STATUSES (can't import it — that module+// depends on cosTaskStore, which imports THIS module, so the import would cycle;+// kept in sync by this comment). Crucially this INCLUDES `blocked`: a blocked+// investigation still tracks its failure cause, so two `blocked` (or blocked ++// pending) same-fingerprint copies are exactly the pile-up this pass must collapse+// — filtering on the merge module's terminal set (completed AND blocked) would let+// them escape. Only `completed` (the status a superseded loser is flipped to) is+// settled, which keeps the pass idempotent: a collapsed loser never re-enters the+// open set on the next sweep.+const OPEN_INVESTIGATION_STATUSES = new Set(['pending', 'in_progress', 'challenged', 'blocked']);+const isOpenInvestigation = (task) => OPEN_INVESTIGATION_STATUSES.has(task.status);++// The terminal status an OPEN investigation loser is flipped to when a+// same-fingerprint winner is chosen. `completed` — the duplicate is subsumed, not+// stuck; it needs no further work. Marked with `supersededBy` so the collapse is+// auditable and the pass stays idempotent (see the open-status note above).const SUPERSEDED_STATUS = 'completed';const SUPERSEDED_BY_KEY = 'supersededBy';@@ -297,8 +310,9 @@ const affectedTaskIds = (task) => {};/**- * Choose the surviving row among the OPEN (non-terminal) copies of one- * investigation fingerprint. An `in_progress` copy wins outright so an in-flight+ * Choose the surviving row among the OPEN copies (pending/in_progress/challenged/+ * blocked — see OPEN_INVESTIGATION_STATUSES) of one investigation fingerprint. An+ * `in_progress` copy wins outright so an in-flight* investigation (an agent is running it) is never orphaned by the collapse; if* MORE than one is `in_progress` (two peers both spawned in the sub-second claim* window), return null to skip the collapse this sweep — both run to completion@@ -337,7 +351,7 @@ function dedupeInvestigations(tasks) {const rewrites = new Map(); // original task ref -> replacementfor (const group of groups.values()) {- const open = group.filter((t) => !isTerminalStatus(t.status));+ const open = group.filter(isOpenInvestigation);if (open.length === 0) continue;// Act on a genuine open duplicate, OR to re-fold a prior collapse whose// survivor a mid-propagation per-id LWW may have reverted to a partial@@ -359,9 +373,26 @@ function dedupeInvestigations(tasks) {const affectedChanged =unionAffected.length !== currentAffected.length ||unionAffected.some((id, i) => id !== currentAffected[i]);- if (affectedChanged && unionAffected.length > 0) {++ // Also surface the peer-contributed ids in the survivor's DESCRIPTION, not+ // just metadata: the investigation agent/user reads the body (the metadata+ // union is what the isReapableInvestigation reaper consumes, but "What+ // unblocks" only lists ids the body mentions). Mirrors agentErrorAnalysis's+ // local same-fingerprint path, which appends an "Also blocks" line per new id.+ // Append only ids not already textually present (idempotent), in the sorted+ // union order (deterministic) — so both peers reach the identical body and no+ // agentId/timestamp enters the text to break convergence.+ const currentDesc = survivor.description || '';+ const missingMentions = unionAffected.filter((id) => !currentDesc.includes(`\`${id}\``));+ const appended = missingMentions+ .map((id) => `\n- Also blocks task \`${id}\` (same cause; merged across federated peers).`)+ .join('');+ const newDesc = currentDesc + appended;++ if ((affectedChanged || appended) && unionAffected.length > 0) {rewrites.set(survivor, {...survivor,+ description: newDesc,metadata: { ...(survivor.metadata || {}), [AFFECTED_TASKS_KEY]: unionAffected },});}diff --git a/server/services/cosTaskMerge.test.js b/server/services/cosTaskMerge.test.jsindex c93051ccff..44d0413f42 100644--- a/server/services/cosTaskMerge.test.js+++ b/server/services/cosTaskMerge.test.js@@ -310,6 +310,7 @@ describe('mergeTaskLists', () => {...(overrides.metadata || {}),},...(overrides.priority ? { priority: overrides.priority } : {}),+ ...(overrides.description ? { description: overrides.description } : {}),});it('collapses two same-fingerprint OPEN investigations from two peers to one active row', () => {@@ -405,6 +406,63 @@ describe('mergeTaskLists', () => {}});+ it('collapses two blocked same-fingerprint copies (blocked is an OPEN investigation status)', () => {+ // agentErrorAnalysis treats `blocked` as an open investigation, so two blocked+ // copies for one cause are the same pile-up — they must collapse, not escape.+ const local = [inv('sys-a', 'blocked', 'fp-1', { affectedTasks: ['task-1'] })];+ const remote = [inv('sys-b', 'blocked', 'fp-1', { affectedTasks: ['task-2'] })];+ for (const merged of [+ mergeTaskLists(local, remote, { now: NOW }),+ mergeTaskLists(remote, local, { now: NOW }),+ ]) {+ const byId = Object.fromEntries(merged.map((t) => [t.id, t]));+ expect(byId['sys-a'].status).toBe('blocked'); // lower id survives, still blocked+ expect(byId['sys-b'].status).toBe('completed'); // loser superseded+ expect(byId['sys-b'].metadata.supersededBy).toBe('sys-a');+ expect(byId['sys-a'].metadata.affectedTasks).toEqual(['task-1', 'task-2']);+ }+ });++ it('collapses a blocked + pending same-fingerprint pair', () => {+ const local = [inv('sys-a', 'blocked', 'fp-1')];+ const remote = [inv('sys-b', 'pending', 'fp-1')];+ const merged = mergeTaskLists(local, remote, { now: NOW });+ const open = merged.filter((t) => t.metadata?.investigationFingerprint === 'fp-1' && t.status !== 'completed');+ expect(open).toHaveLength(1);+ });++ it('surfaces peer-contributed affected tasks in the survivor DESCRIPTION (not just metadata)', () => {+ // The investigation agent/user reads the body; the local path appends an+ // "Also blocks" line per new id. The federation collapse mirrors that so the+ // survivor names every blocked task, deterministically and idempotently.+ const local = [inv('sys-a', 'pending', 'fp-1', { affectedTasks: ['task-1'] })]; // default body `desc sys-a`+ const remote = [inv('sys-b', 'pending', 'fp-1', { affectedTasks: ['task-2'] })];+ const once = mergeTaskLists(local, remote, { now: NOW });+ const survivor = once.find((t) => t.id === 'sys-a');+ expect(survivor.description).toContain('Also blocks task `task-2`');+ // task-1 is the survivor's own id — not re-appended as a peer contribution+ // unless it was already absent from the body; the default body doesn't mention+ // it, so it IS appended once. Re-merging must NOT append it (or task-2) again.+ const twice = mergeTaskLists(once, [], { now: NOW });+ const survivor2 = twice.find((t) => t.id === 'sys-a');+ expect(survivor2.description).toBe(survivor.description); // idempotent+ const occurrences = (survivor2.description.match(/Also blocks task `task-2`/g) || []).length;+ expect(occurrences).toBe(1);+ });++ it('does not append a description line already present in the body', () => {+ // The survivor's body already mentions task-2 — the collapse must not duplicate it.+ const local = [inv('sys-a', 'pending', 'fp-1', {+ affectedTasks: ['task-1'],+ description: 'Investigate failure. Original task `task-2` is affected.',+ })];+ const remote = [inv('sys-b', 'pending', 'fp-1', { affectedTasks: ['task-2'] })];+ const merged = mergeTaskLists(local, remote, { now: NOW });+ const survivor = merged.find((t) => t.id === 'sys-a');+ const occurrences = (survivor.description.match(/`task-2`/g) || []).length;+ expect(occurrences).toBe(1); // already present — not re-appended+ });+it('does not collapse a single open investigation (no duplicate)', () => {const local = [inv('sys-a', 'pending', 'fp-1', { affectedTasks: ['task-1'] })];const merged = mergeTaskLists(local, [], { now: NOW });