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 (agy): a commission deleted on another machine never stopped this machine's work
[._.]/ Adam Eivy9b8a1f079a82
diff --git a/server/services/creativeCommissions/projectControl.js b/server/services/creativeCommissions/projectControl.jsindex 7156304ede..31b3be1bb4 100644--- a/server/services/creativeCommissions/projectControl.js+++ b/server/services/creativeCommissions/projectControl.js@@ -232,6 +232,13 @@ export async function reconcileCommissionProjects({ id, action, fields } = {}) {}const commission = await readCommission(id);if (!commission) return { action: 'noop' };+ // Tombstoned, but reached here on some action other than 'delete' (a restore+ // that lost the LWW, a hand-fired event). Deleted outranks everything else:+ // restarting a dead commission's stages would re-dispatch work the user removed.+ if (commission.deleted) {+ await stopCommissionProjects(id, { reason: 'Creative commission deleted', commission });+ return { action: 'stopped' };+ }if (commission.enabled === false) {await stopCommissionProjects(id, { reason: 'Creative commission paused', commission });return { action: 'stopped' };diff --git a/server/services/creativeCommissions/projectControl.test.js b/server/services/creativeCommissions/projectControl.test.jsindex c0f04195f0..1409802cd4 100644--- a/server/services/creativeCommissions/projectControl.test.js+++ b/server/services/creativeCommissions/projectControl.test.js@@ -315,6 +315,19 @@ describe('reconcileCommissionProjects', () => {expect(retireRunsMock).not.toHaveBeenCalled();});+ it('stops (never restarts) a TOMBSTONED commission reached on a non-delete action', async () => {+ // A restore that lost the LWW, or a synced tombstone arriving as an update:+ // deleted outranks everything, or we re-dispatch work the user removed.+ readRawMock.mockResolvedValue(commission({ deleted: true, enabled: true }));+ listProjectsByCommissionIdMock.mockResolvedValue([wedged()]);++ const result = await reconcileCommissionProjects({ id: 'commission-1', action: 'update', fields: ['assignment'] });++ expect(result).toEqual({ action: 'stopped' });+ expect(stopProjectMock).toHaveBeenCalledWith('cd-1', expect.objectContaining({ reason: 'Creative commission deleted' }));+ expect(retireRunsMock).not.toHaveBeenCalled();+ });+it('restarts (never stops) the stages of an enabled commission whose provider changed', async () => {readRawMock.mockResolvedValue(commission());listProjectsByCommissionIdMock.mockResolvedValue([wedged()]);diff --git a/server/services/creativeCommissions/store.js b/server/services/creativeCommissions/store.jsindex abd3e49710..bff427b999 100644--- a/server/services/creativeCommissions/store.js+++ b/server/services/creativeCommissions/store.js@@ -925,6 +925,13 @@ export async function mergeCommissionsFromSync(remoteRecords, { source = { via:if (!Array.isArray(remoteRecords)) return { applied: false, count: 0 };const store = commissionStore();let changed = 0;+ // Commissions whose tombstone arrived in THIS batch. The batch event below+ // carries no id, so the project reconciler can't act on it — but a delete the+ // user performed on another machine still has to stop the work THIS machine is+ // running for that commission (the projects live here; only the brief travels).+ // Collected on the transition only: re-emitting for an already-tombstoned record+ // on every sync would re-stop a project the user had since resumed.+ const newlyDeleted = [];for (const remote of remoteRecords) {const id = remote?.id;if (!isStr(id) || !COMMISSION_ID_RE.test(id)) continue;@@ -938,12 +945,14 @@ export async function mergeCommissionsFromSync(remoteRecords, { source = { via:}await store.writeRaw(id, next);await setSyncBaseHash(CREATIVE_COMMISSION_KIND, next.id, contentHashForRecord(CREATIVE_COMMISSION_KIND, next));+ if (next.deleted === true && local?.deleted !== true) newlyDeleted.push(id);return true;});if (applied) changed += 1;}await flushBaseHashes();if (changed > 0) commissionEvents.emit('commission:changed', { action: 'merge' });+ for (const id of newlyDeleted) commissionEvents.emit('commission:changed', { id, action: 'delete' });return changed === 0 ? { applied: false, count: 0 } : { applied: true, count: changed };}diff --git a/server/services/creativeCommissions/store.test.js b/server/services/creativeCommissions/store.test.jsindex e89d4b3ebc..c5d76bc1e1 100644--- a/server/services/creativeCommissions/store.test.js+++ b/server/services/creativeCommissions/store.test.js@@ -222,6 +222,39 @@ describe('createCommission', () => {});});+describe('mergeCommissionsFromSync — synced tombstone stops local work', () => {+ const capture = async (fn) => {+ const seen = [];+ const onChange = (e) => seen.push(e);+ commissionEvents.on('commission:changed', onChange);+ try { await fn(); } finally { commissionEvents.off('commission:changed', onChange); }+ return seen;+ };++ it('emits a per-id delete when a tombstone arrives, so the receiver stops the projects IT owns', async () => {+ // Only the brief travels; the projects live on whichever machine minted them.+ // The batch 'merge' event carries no id, so without this the reconciler no-ops+ // and a commission deleted on another machine keeps generating here forever.+ const created = await createCommission(validInput());+ const events = await capture(() => mergeCommissionsFromSync([{+ ...created, deleted: true, deletedAt: '2030-01-01T00:00:00.000Z',+ briefUpdatedAt: '2030-01-01T00:00:00.000Z', updatedAt: '2030-01-01T00:00:00.000Z',+ }]));+ expect(events).toContainEqual({ id: created.id, action: 'delete' });+ });++ it('does NOT re-emit for a tombstone it already holds — a re-sync must not re-stop resumed work', async () => {+ const created = await createCommission(validInput());+ const tombstone = {+ ...created, deleted: true, deletedAt: '2030-01-01T00:00:00.000Z',+ briefUpdatedAt: '2030-01-01T00:00:00.000Z', updatedAt: '2030-01-01T00:00:00.000Z',+ };+ await mergeCommissionsFromSync([tombstone]);+ const events = await capture(() => mergeCommissionsFromSync([tombstone]));+ expect(events.filter((e) => e.action === 'delete')).toEqual([]);+ });+});+describe('updateCommission — changed-field event payload', () => {// The project reconciler (creativeCommissions/projectControl.js) keys on this// payload to decide whether to tear down a commission's in-flight LLM stages.