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): wire CD category into route schema + conflict resolver, reject writes to tombstoned projects (#1564)
[._.]/ Adam Eivybc659fa5ea6f
diff --git a/server/routes/instances.js b/server/routes/instances.jsindex 281470cf90..b85605f417 100644--- a/server/routes/instances.js+++ b/server/routes/instances.js@@ -65,6 +65,7 @@ const syncCategoriesSchema = z.object({artists: z.boolean().optional(),albums: z.boolean().optional(),tracks: z.boolean().optional(),+ creativeDirectorProjects: z.boolean().optional(),catalog: z.boolean().optional()}).optional();diff --git a/server/services/conflictJournalResolver.js b/server/services/conflictJournalResolver.jsindex c68f9d8f0b..c46d7fd358 100644--- a/server/services/conflictJournalResolver.js+++ b/server/services/conflictJournalResolver.js@@ -35,6 +35,7 @@ import { updateUniverse, ERR_NOT_FOUND as UNIVERSE_NOT_FOUND } from './universeBimport { updateSeries, ERR_NOT_FOUND as SERIES_NOT_FOUND } from './pipeline/series.js';import { updateCollection, getCollection, ERR_NOT_FOUND as COLLECTION_NOT_FOUND } from './mediaCollections.js';import { updateIssue, ERR_NOT_FOUND as ISSUE_NOT_FOUND } from './pipeline/issues.js';+import { updateProject } from './creativeDirector/local.js';export const ERR_NOT_FOUND = 'CONFLICT_JOURNAL_NOT_FOUND';export const ERR_VALIDATION = 'CONFLICT_JOURNAL_VALIDATION';@@ -77,7 +78,11 @@ async function applyToRecord(kind, recordId, patch, { replace = false } = {}) {// the route maps it to a clean 409 ("discard the entry") instead of a 500.const translateGone = (err) => {if (err?.code === UNIVERSE_NOT_FOUND || err?.code === SERIES_NOT_FOUND- || err?.code === COLLECTION_NOT_FOUND || err?.code === ISSUE_NOT_FOUND) {+ || err?.code === COLLECTION_NOT_FOUND || err?.code === ISSUE_NOT_FOUND+ // Creative Director's updateProject throws a generic ServerError+ // 'NOT_FOUND' (no module-specific export) when the row is missing OR+ // tombstoned — both mean the conflict target is gone.+ || err?.code === 'NOT_FOUND') {throw makeErr(`The ${kind} this conflict targets no longer exists — discard the entry.`, ERR_TARGET_GONE);}throw err;@@ -113,6 +118,13 @@ async function applyToRecord(kind, recordId, patch, { replace = false } = {}) {// overwritten. (`runHistory` is intentionally recomputed, not rolled back —// it tracks the live undo-history, which a faithful restore should preserve.)await updateIssue(recordId, patch).catch(translateGone);+ } else if (kind === 'creativeDirectorProject') {+ // updateProject does a wholesale spread (`{ ...project, ...patch }`), so the+ // restorable scalars + treatment in the snapshot patch overwrite the live+ // values faithfully — restore-all and merge-fields both apply through the+ // same path. updateProject validates `status` and rejects a tombstoned row+ // (404 → translateGone → ERR_TARGET_GONE).+ await updateProject(recordId, patch).catch(translateGone);} else {throw makeErr(`Unsupported conflict kind: ${kind}`, ERR_VALIDATION);}diff --git a/server/services/creativeDirector/projectsDB.js b/server/services/creativeDirector/projectsDB.jsindex 97dfdf1595..f147fe754f 100644--- a/server/services/creativeDirector/projectsDB.js+++ b/server/services/creativeDirector/projectsDB.js@@ -126,7 +126,13 @@ async function withLockedProject(id, mutate, { allowMissing = false } = {}) {[id],);const project = rowToProject(sel.rows[0]);- if (!project) {+ // A tombstoned project (#1564 soft-delete) is treated as gone for every+ // user-facing mutator — without this, a PATCH / scene / treatment update+ // after deletion would resurrect the row, bump updatedAt, and re-push a+ // modified tombstone to peers while getProject/deleteProject 404 the same id.+ // mergeProjectsFromSync (peer tombstone apply) bypasses this path via its own+ // persist, so receiving a tombstone still works.+ if (!project || project.deleted) {if (allowMissing) return { __missing: true };throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });}diff --git a/server/services/creativeDirector/projectsFile.js b/server/services/creativeDirector/projectsFile.jsindex 27efcd35d6..1dc91c23b8 100644--- a/server/services/creativeDirector/projectsFile.js+++ b/server/services/creativeDirector/projectsFile.js@@ -83,7 +83,9 @@ export async function createProject(input) {export async function updateProject(id, patch) {const all = await loadAll();const idx = all.findIndex((p) => p.id === id);- if (idx < 0) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });+ // Missing OR tombstoned (#1564 soft-delete) → gone for user-facing mutators, so a+ // post-delete write can't resurrect + re-push a modified tombstone.+ if (idx < 0 || all[idx].deleted) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });all[idx] = applyProjectPatch(all[idx], patch);await saveAll(all);return all[idx];@@ -157,7 +159,9 @@ export async function pruneTombstonedProjects(olderThanMs) {export async function setTreatment(id, treatmentInput) {const all = await loadAll();const idx = all.findIndex((p) => p.id === id);- if (idx < 0) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });+ // Missing OR tombstoned (#1564 soft-delete) → gone for user-facing mutators, so a+ // post-delete write can't resurrect + re-push a modified tombstone.+ if (idx < 0 || all[idx].deleted) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });all[idx] = applyTreatment(all[idx], treatmentInput);await saveAll(all);return all[idx];@@ -166,7 +170,9 @@ export async function setTreatment(id, treatmentInput) {export async function updateScene(id, sceneId, patch) {const all = await loadAll();const idx = all.findIndex((p) => p.id === id);- if (idx < 0) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });+ // Missing OR tombstoned (#1564 soft-delete) → gone for user-facing mutators, so a+ // post-delete write can't resurrect + re-push a modified tombstone.+ if (idx < 0 || all[idx].deleted) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });const { project, updated } = applySceneUpdate(all[idx], sceneId, patch);all[idx] = project;await saveAll(all);@@ -176,7 +182,9 @@ export async function updateScene(id, sceneId, patch) {export async function recordRun(id, runEntry) {const all = await loadAll();const idx = all.findIndex((p) => p.id === id);- if (idx < 0) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });+ // Missing OR tombstoned (#1564 soft-delete) → gone for user-facing mutators, so a+ // post-delete write can't resurrect + re-push a modified tombstone.+ if (idx < 0 || all[idx].deleted) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });const { project, run } = appendRun(all[idx], runEntry);all[idx] = project;await saveAll(all);@@ -186,7 +194,9 @@ export async function recordRun(id, runEntry) {export async function updateRun(id, runId, patch) {const all = await loadAll();const idx = all.findIndex((p) => p.id === id);- if (idx < 0) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });+ // Missing OR tombstoned (#1564 soft-delete) → gone for user-facing mutators, so a+ // post-delete write can't resurrect + re-push a modified tombstone.+ if (idx < 0 || all[idx].deleted) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });const { project, updated } = applyRunUpdate(all[idx], runId, patch);if (updated === null) return null;all[idx] = project;diff --git a/server/services/creativeDirector/projectsFile.test.js b/server/services/creativeDirector/projectsFile.test.jsindex 776a16bf1d..b425143475 100644--- a/server/services/creativeDirector/projectsFile.test.js+++ b/server/services/creativeDirector/projectsFile.test.js@@ -108,6 +108,15 @@ describe('projectsFile federation merge', () => {expect(await file.getProject('cd-1', { includeDeleted: true })).toMatchObject({ deleted: true });});+ it('rejects user-facing mutators on a tombstoned project (no resurrect-then-push)', async () => {+ await file.mergeProjectsFromSync([project('cd-1')]);+ await file.deleteProject('cd-1');+ await expect(file.updateProject('cd-1', { styleSpec: 'zombie' })).rejects.toMatchObject({ code: 'NOT_FOUND' });+ await expect(file.setTreatment('cd-1', { logline: 'x', synopsis: 'y', scenes: [] })).rejects.toMatchObject({ code: 'NOT_FOUND' });+ // Still gone (the rejected writes left no trace).+ expect(await file.getProject('cd-1', { includeDeleted: true })).toMatchObject({ deleted: true, styleSpec: '' });+ });+it('pruneTombstonedProjects hard-removes old tombstones and evicts the base hash', async () => {await file.mergeProjectsFromSync([project('cd-1', { updatedAt: '2026-06-23T00:00:00.000Z', deleted: true, deletedAt: '2026-06-23T00:00:00.000Z' })]);const res = await file.pruneTombstonedProjects(Date.parse('2030-01-01T00:00:00.000Z'));