Skip to content

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

fix([issue-842]): address claude + codex review

Adam Eivyb51f14af4ed7
diff --git a/client/src/components/writers-room/CdBridgePanel.jsx b/client/src/components/writers-room/CdBridgePanel.jsx
index 7a9e2d349b..238e0fbc11 100644
--- a/client/src/components/writers-room/CdBridgePanel.jsx
+++ b/client/src/components/writers-room/CdBridgePanel.jsx
@@ -79,7 +79,7 @@ export default function CdBridgePanel({ workId, liveMode, getCursorContext, onLi
if (!res?.project) return;
onLinked?.(res.project.id);
toast.success('Sent to Creative Director');
- navigate(`/creative-director/${encodeURIComponent(res.project.id)}/overview`);
+ navigate(`/media/creative-director/${encodeURIComponent(res.project.id)}/overview`);
}, [proposal, sending, onLinked, navigate, mountedRef]);
// When live mode flips off, clear any stale proposal so the panel doesn't
diff --git a/client/src/components/writers-room/WorkEditor.jsx b/client/src/components/writers-room/WorkEditor.jsx
index 5424330c15..6ee1cbd563 100644
--- a/client/src/components/writers-room/WorkEditor.jsx
+++ b/client/src/components/writers-room/WorkEditor.jsx
@@ -442,7 +442,7 @@ export default function WorkEditor({ work, onChange, onToggleExercise, exerciseO
const handleOpenInCreativeDirector = () => {
if (!work.cdProjectId) return;
- navigate(`/creative-director/${encodeURIComponent(work.cdProjectId)}/overview`);
+ navigate(`/media/creative-director/${encodeURIComponent(work.cdProjectId)}/overview`);
};
const commitTitle = async () => {
diff --git a/server/services/writersRoom/liveDirector.js b/server/services/writersRoom/liveDirector.js
index a249ab1d04..fb6826bf01 100644
--- a/server/services/writersRoom/liveDirector.js
+++ b/server/services/writersRoom/liveDirector.js
@@ -19,7 +19,8 @@ import {
getWork, resolveLiveMode, recordLiveModeUsage, recordLiveModeRenderUsage, utcDayKey,
linkToCreativeDirector,
} from './local.js';
-import { createProject, setTreatment, deleteProject } from '../creativeDirector/local.js';
+import { createProject, setTreatment, deleteProject, updateProject } from '../creativeDirector/local.js';
+import { deleteCollection } from '../mediaCollections.js';
import { defaultVideoModelId } from '../videoGen/local.js';
import { badRequest } from './_shared.js';
@@ -162,9 +163,16 @@ function shapeProposal(parsed) {
.filter(Boolean)
.slice(0, MAX_BRIDGE_SCENES);
if (scenes.length < MIN_BRIDGE_SCENES) return null;
+ const logline = typeof parsed?.logline === 'string' ? parsed.logline.trim().slice(0, 500) : '';
+ const synopsis = typeof parsed?.synopsis === 'string' ? parsed.synopsis.trim().slice(0, 5000) : '';
+ // logline + synopsis are REQUIRED by the send schema (and CD's treatment
+ // schema) with min(1). Returning a proposal missing either would render a
+ // live "Send" button that then 400s — so treat a missing-headline response
+ // as "no usable treatment" (null), the same as too-few scenes.
+ if (!logline || !synopsis) return null;
return {
- logline: typeof parsed?.logline === 'string' ? parsed.logline.trim().slice(0, 500) : '',
- synopsis: typeof parsed?.synopsis === 'string' ? parsed.synopsis.trim().slice(0, 5000) : '',
+ logline,
+ synopsis,
styleSpec: typeof parsed?.styleSpec === 'string' ? parsed.styleSpec.trim().slice(0, 5000) : '',
scenes,
};
@@ -253,17 +261,27 @@ export async function sendToCreativeDirector(workId, { proposal } = {}) {
// it so the route can return the seeded project without a re-read.
let withTreatment;
try {
- withTreatment = await setTreatment(project.id, {
+ await setTreatment(project.id, {
logline: proposal.logline,
synopsis: proposal.synopsis,
scenes,
});
+ // setTreatment flips a fresh project to 'rendering', but nothing here
+ // enqueues a render — the orchestrator only runs on an explicit
+ // POST /:id/start. A 'rendering' project also hides the detail page's
+ // "Start" button (it shows only for 'draft'/'failed'), which would strand
+ // the bridged project as "active" with no way to kick it off. Reset to
+ // 'draft' so the user reviews it in Creative Director and starts rendering
+ // deliberately (no surprise GPU/provider spend from the bridge itself).
+ withTreatment = await updateProject(project.id, { status: 'draft' });
await linkToCreativeDirector(workId, { projectId: project.id });
} catch (err) {
- // Roll back the orphaned project so a validation/link failure doesn't leave
- // a treatment-less project behind with no manifest link. Best-effort —
- // swallow the cleanup error so the original cause reaches the caller.
+ // Roll back the orphaned project AND its auto-created media collection so a
+ // setTreatment/link failure doesn't leave a treatment-less project or a
+ // dangling empty collection behind with no manifest link. Best-effort —
+ // swallow cleanup errors so the original cause reaches the caller.
await deleteProject(project.id).catch(() => {});
+ if (project.collectionId) await deleteCollection(project.collectionId).catch(() => {});
throw err;
}
diff --git a/server/services/writersRoom/liveDirector.test.js b/server/services/writersRoom/liveDirector.test.js
index 54cb98f160..688546d122 100644
--- a/server/services/writersRoom/liveDirector.test.js
+++ b/server/services/writersRoom/liveDirector.test.js
@@ -21,11 +21,15 @@ vi.mock('../../lib/stageRunner.js', () => ({ runStagedLLM: (...a) => runStagedLL
const createProject = vi.fn();
const setTreatment = vi.fn();
const deleteProject = vi.fn();
+const updateProject = vi.fn();
vi.mock('../creativeDirector/local.js', () => ({
createProject: (...a) => createProject(...a),
setTreatment: (...a) => setTreatment(...a),
deleteProject: (...a) => deleteProject(...a),
+ updateProject: (...a) => updateProject(...a),
}));
+const deleteCollection = vi.fn();
+vi.mock('../mediaCollections.js', () => ({ deleteCollection: (...a) => deleteCollection(...a) }));
vi.mock('../videoGen/local.js', () => ({ defaultVideoModelId: () => 'ltxv-default' }));
const local = await import('./local.js');
@@ -41,6 +45,8 @@ beforeEach(() => {
createProject.mockReset();
setTreatment.mockReset();
deleteProject.mockReset();
+ updateProject.mockReset();
+ deleteCollection.mockReset();
});
afterEach(() => {
@@ -243,6 +249,20 @@ describe('suggestCdBridge', () => {
expect(res.usage.count).toBe(1); // reached the LLM → charged
});
+ it('returns a null proposal when logline/synopsis is missing (would fail the send schema)', async () => {
+ // 2 usable scenes but no headline — the send schema requires logline +
+ // synopsis min(1), so a proposal missing them must not render a live Send.
+ runStagedLLM.mockResolvedValue({ content: { logline: '', synopsis: '', styleSpec: 'z', scenes: [
+ { intent: 'a', prompt: 'shot a' }, { intent: 'b', prompt: 'shot b' },
+ ] } });
+ const work = await createWork({ title: 'Headless' });
+ await updateWork(work.id, { liveMode: { enabled: true } });
+
+ const res = await suggestCdBridge(work.id, { before: 'something' });
+ expect(res.proposal).toBeNull();
+ expect(res.usage.count).toBe(1); // reached the LLM → charged
+ });
+
it('shares the daily budget with suggestContinuation (one pool, not two)', async () => {
runStagedLLM.mockResolvedValue(BRIDGE_RESPONSE);
const work = await createWork({ title: 'Shared' });
@@ -274,9 +294,10 @@ describe('sendToCreativeDirector', () => {
],
};
- it('creates a project, seeds the treatment, and records the manifest link', async () => {
- createProject.mockResolvedValue({ id: 'cd-1' });
- setTreatment.mockImplementation(async (id, treatment) => ({ id, treatment }));
+ it('creates a project, seeds the treatment, resets to draft, and records the manifest link', async () => {
+ createProject.mockResolvedValue({ id: 'cd-1', collectionId: 'col-1' });
+ setTreatment.mockImplementation(async (id, treatment) => ({ id, treatment, status: 'rendering' }));
+ updateProject.mockImplementation(async (id, patch) => ({ id, ...patch }));
const work = await createWork({ title: 'My Draft' });
const res = await sendToCreativeDirector(work.id, { proposal: PROPOSAL });
@@ -289,22 +310,27 @@ describe('sendToCreativeDirector', () => {
const [, treatment] = setTreatment.mock.calls[0];
expect(treatment.scenes[0]).toMatchObject({ sceneId: 'sc-1', order: 0, useContinuationFromPrior: false });
expect(treatment.scenes[1]).toMatchObject({ sceneId: 'sc-2', order: 1, useContinuationFromPrior: true });
- expect(res.project).toMatchObject({ id: 'cd-1' });
+ // setTreatment forces 'rendering' but the bridge resets to 'draft' so the
+ // user can Start it deliberately — the returned project reflects the reset.
+ expect(updateProject).toHaveBeenCalledWith('cd-1', { status: 'draft' });
+ expect(res.project).toMatchObject({ id: 'cd-1', status: 'draft' });
// The bridge link is persisted on the work manifest.
const reloaded = await getWork(work.id);
expect(reloaded.cdProjectId).toBe('cd-1');
});
- it('rolls back the orphaned project when setTreatment fails, and leaves the work unlinked', async () => {
- createProject.mockResolvedValue({ id: 'cd-orphan' });
+ it('rolls back the orphaned project AND its media collection when setTreatment fails', async () => {
+ createProject.mockResolvedValue({ id: 'cd-orphan', collectionId: 'col-orphan' });
setTreatment.mockRejectedValue(new Error('treatment invalid'));
deleteProject.mockResolvedValue({ ok: true });
+ deleteCollection.mockResolvedValue({ ok: true });
const work = await createWork({ title: 'Doomed' });
await expect(sendToCreativeDirector(work.id, { proposal: PROPOSAL }))
.rejects.toThrow(/treatment invalid/);
expect(deleteProject).toHaveBeenCalledWith('cd-orphan');
+ expect(deleteCollection).toHaveBeenCalledWith('col-orphan');
const reloaded = await getWork(work.id);
expect(reloaded.cdProjectId ?? null).toBeNull();