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: hold `completed` immune from un-completion in the challenge merge branch (#2441)
Adam Eivyc4f789bb230c
diff --git a/server/services/cosTaskMerge.js b/server/services/cosTaskMerge.jsindex 18c0334ae0..7e3e1af8d4 100644--- a/server/services/cosTaskMerge.js+++ b/server/services/cosTaskMerge.js@@ -52,12 +52,15 @@ import { PRIORITY_VALUES } from '../lib/taskParser.js';// distinct rank so two DIFFERENT statuses never tie (full convergence); the only// genuine tie is same-status-both-sides, where the content is already equivalent.//-// `challenged` (#2441) sits ABOVE in_progress (a fresh dispute is newer truth than-// a stale in_progress snapshot on the other peer) but BELOW the terminal states:-// a `completed` or `blocked`/escalated resolution supersedes an unresolved-// challenge, so those still win the merge. It is NOT terminal (the dispute-// resolves back to pending or forward to blocked), so it keeps a live claim the-// same way in_progress does.+// `challenged` (#2441) is placed above in_progress and below the terminal states,+// but NOTE its rank is only a fallback: the challenge lifecycle is non-monotonic+// (upheld regresses challenged→pending; blocked↔challenged both directions are+// legal), so `pickContentBase` resolves any pairing where exactly one side is+// `challenged` by newest `updatedAt` — NOT by this rank — with `completed` held+// immune there. This rank still governs challenged-vs-challenged-adjacent cases+// that never actually arise (both-challenged goes to the same-status path). It is+// NOT terminal (the dispute resolves back to pending or forward to blocked), so it+// keeps a live claim the same way in_progress does.const STATUS_RANK = Object.freeze({ completed: 5, blocked: 4, challenged: 3, in_progress: 2, pending: 1 });const statusRank = (status) => STATUS_RANK[status] || 0;const isTerminalStatus = (status) => status === 'completed' || status === 'blocked';@@ -142,6 +145,14 @@ function pickContentBase(local, remote) {const lChallenged = local.status === 'challenged';const rChallenged = remote.status === 'challenged';if (lChallenged !== rChallenged) {+ // `completed` is truly terminal and must NEVER regress — once either peer+ // marks a task done, the other adopts it (rule 2 monotonic completion). So a+ // `completed` counterpart wins outright, even against a newer `challenged`+ // snapshot the other peer raised before completion propagated. `blocked` stays+ // on the timestamp path below: blocked→challenged (re-dispute) and+ // challenged→blocked (escalation) are both legal, so recency decides.+ if (local.status === 'completed') return local;+ if (remote.status === 'completed') return remote;const luc = updatedAtMs(local);const ruc = updatedAtMs(remote);if (luc !== ruc) return ruc > luc ? remote : local;diff --git a/server/services/cosTaskMerge.test.js b/server/services/cosTaskMerge.test.jsindex c214a9b3da..b027d22235 100644--- a/server/services/cosTaskMerge.test.js+++ b/server/services/cosTaskMerge.test.js@@ -273,6 +273,15 @@ describe('mergeTaskLists', () => {expect(mergeTaskLists(stale, resolved, { now: NOW })[0].status).toBe('blocked');});+ it('a completed task is NEVER un-completed by a newer challenge (monotonic completion)', () => {+ // Cross-peer: B completes at t=100, A challenges at t=200 before B's+ // completion propagates. `completed` must win despite the newer challenge.+ const completed = [stamped('task-c', 'completed', past(1000))];+ const newerChallenge = [stamped('task-c', 'challenged', future(1000))];+ expect(mergeTaskLists(completed, newerChallenge, { now: NOW })[0].status).toBe('completed');+ expect(mergeTaskLists(newerChallenge, completed, { now: NOW })[0].status).toBe('completed');+ });+it('on equal/absent stamps, prefers the resolved (non-challenged) side deterministically', () => {const challenged = [task('task-c', 'challenged')];const blocked = [task('task-c', 'blocked')];