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): converge metadata-only task edits + hash editable fields
[._.]/ Adam Eivyde0cd9120d29
diff --git a/server/services/cosTaskMerge.js b/server/services/cosTaskMerge.jsindex cf45f72f28..a8c147e685 100644--- a/server/services/cosTaskMerge.js+++ b/server/services/cosTaskMerge.js@@ -117,13 +117,37 @@ function pickContentBase(local, remote) {const lp = PRIORITY_VALUES[local.priority] || 0;const rp = PRIORITY_VALUES[remote.priority] || 0;if (lp !== rp) return rp > lp ? remote : local;- if ((local.description || '') !== (remote.description || '')) {- return (remote.description || '') > (local.description || '') ? remote : local;+ // Same status + priority: break the tie over ALL remaining editable content+ // (description, approval flags, AND non-claim metadata — `app`, `context`,+ // `reviewers`, `useWorktree`, … which all affect how a task is spawned) via a+ // canonical, side-independent signature so a content-only edit converges.+ // Claim metadata is excluded — it's resolved separately by lease in resolveClaim.+ const ls = contentSignature(local);+ const rs = contentSignature(remote);+ if (ls === rs) return local; // identical content — keep local (no-op)+ return rs > ls ? remote : local;+}++/**+ * Canonical, side-independent signature of a task's editable content used to+ * break a same-status/same-priority merge tie. Sorts metadata keys (so two+ * representations of the same logical metadata compare equal) and excludes the+ * claim keys (resolved separately by lease). Two machines computing this over the+ * same pair therefore pick the same winner, so a content-only edit converges.+ */+function contentSignature(task) {+ const md = (task.metadata && typeof task.metadata === 'object') ? task.metadata : {};+ const nonClaim = {};+ for (const key of Object.keys(md).sort()) {+ if (CLAIM_METADATA_KEYS.includes(key)) continue;+ nonClaim[key] = md[key];}- // Last resort: compare the remaining federated fields as a stable string so any- // residual difference (e.g. approval flags on an internal task) still converges.- const sig = (t) => JSON.stringify([t.approvalRequired ?? null, t.autoApproved ?? null]);- return sig(remote) > sig(local) ? remote : local;+ return JSON.stringify([+ task.description || '',+ task.approvalRequired ?? null,+ task.autoApproved ?? null,+ nonClaim,+ ]);}/**diff --git a/server/services/cosTaskMerge.test.js b/server/services/cosTaskMerge.test.jsindex c3ad642023..cf166b7bb2 100644--- a/server/services/cosTaskMerge.test.js+++ b/server/services/cosTaskMerge.test.js@@ -151,6 +151,23 @@ describe('mergeTaskLists', () => {expect(fromA.description).toBe(fromB.description);});+ it('converges on a same-status metadata-only edit (e.g. app/context changed)', () => {+ const a = [task('task-1', 'pending', { metadata: { app: 'BookLoom', context: 'ctx-A' } })];+ const b = [task('task-1', 'pending', { metadata: { app: 'PortOS', context: 'ctx-B' } })];+ const [fromA] = mergeTaskLists(a, b, { now: NOW });+ const [fromB] = mergeTaskLists(b, a, { now: NOW });+ expect(fromA.metadata.app).toBe(fromB.metadata.app);+ expect(fromA.metadata.context).toBe(fromB.metadata.context);+ });++ it('treats metadata with different key order as identical (no spurious winner flip)', () => {+ const a = [task('task-1', 'pending', { metadata: { app: 'X', context: 'Y' } })];+ const b = [task('task-1', 'pending', { metadata: { context: 'Y', app: 'X' } })];+ const [merged] = mergeTaskLists(a, b, { now: NOW });+ // Same logical content → keeps local, no churn.+ expect(merged.metadata).toEqual({ app: 'X', context: 'Y' });+ });+it('adopts a remote-only task whose metadata is absent without crashing (cross-version peer)', () => {// The wire schema marks metadata optional, so a forked/older peer may omit it.const remote = [{ id: 'task-x', taskType: 'user', status: 'pending', priority: 'LOW', description: 'd' }];diff --git a/server/services/sharing/cosTasksSync.test.js b/server/services/sharing/cosTasksSync.test.jsindex d1f89e355d..c3c49b8b3d 100644--- a/server/services/sharing/cosTasksSync.test.js+++ b/server/services/sharing/cosTasksSync.test.js@@ -90,6 +90,17 @@ describe('buildCosTasksPayload', () => {expect(after).not.toBe(before);});+ it('listHash flips on a same-status description or approval-flag edit (so the receiver re-pulls)', async () => {+ vi.mocked(getUserTasks).mockResolvedValue({ tasks: [task('task-a', 'pending', { description: 'original' })] });+ const before = (await buildCosTasksPayload()).listHash;+ vi.mocked(getUserTasks).mockResolvedValue({ tasks: [task('task-a', 'pending', { description: 'EDITED' })] });+ const afterDesc = (await buildCosTasksPayload()).listHash;+ expect(afterDesc).not.toBe(before);+ vi.mocked(getUserTasks).mockResolvedValue({ tasks: [task('task-a', 'pending', { description: 'original', autoApproved: true })] });+ const afterApproval = (await buildCosTasksPayload()).listHash;+ expect(afterApproval).not.toBe(before);+ });+it('returns an empty payload when there are no tasks', async () => {const p = await buildCosTasksPayload();expect(p.tasks).toEqual([]);diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.jsindex 611fe8d948..75c520b6f4 100644--- a/server/services/sharing/peerSync.js+++ b/server/services/sharing/peerSync.js@@ -3380,13 +3380,16 @@ export async function buildCosTasksPayload() {console.log(`⚠️ peerSync: cos-tasks payload hit the ${COS_TASKS_ENTRY_CAP}-entry cap — truncating (some tasks won't federate this tick)`);entries = entries.slice(0, COS_TASKS_ENTRY_CAP);}- // Deterministic order so the listHash converges across machines regardless of- // file/section order. Hash the lifecycle-relevant fields (incl. claim metadata)- // so a claim/renewal/status change flips the hash and re-triggers a merge,- // while pure reordering does not.+ // Deterministic order so the listHash is stable across ticks regardless of+ // file/section order. Hash EVERY field the receiver's merge can act on —+ // status, priority, description, approval flags, and metadata (incl. claim+ // metadata) — so any edit the merge would propagate flips the hash and+ // re-triggers a sweep. Omitting description/approval here would let a receiver+ // short-circuit `unchanged` and never pull a same-status content edit until the+ // forced-revalidation window. Pure reordering does not change the hash.entries.sort((a, b) => (a.taskType < b.taskType ? -1 : a.taskType > b.taskType ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0));const listHash = createHash('sha256')- .update(entries.map((e) => `${e.taskType}:${e.id}:${e.status}:${e.priority}:${JSON.stringify(e.metadata || {})}`).join('\n'))+ .update(entries.map((e) => `${e.taskType}:${e.id}:${e.status}:${e.priority}:${e.description || ''}:${e.approvalRequired ?? ''}:${e.autoApproved ?? ''}:${JSON.stringify(e.metadata || {})}`).join('\n')).digest('hex');return { schemaVersion: PORTOS_SCHEMA_VERSIONS.cosTasks, listHash, tasks: entries };}