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

Creative Director background-kick failures now log to stderr with the project id and stack

Adam Eivyf3309968195d
diff --git a/server/routes/creativeDirector.js b/server/routes/creativeDirector.js
index d9759d007a..349f04f693 100644
--- a/server/routes/creativeDirector.js
+++ b/server/routes/creativeDirector.js
@@ -10,6 +10,7 @@
import { Router } from 'express';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { resolveGalleryImage } from '../lib/fileUtils.js';
+import { logFailureWithStack } from '../lib/failureLogging.js';
import {
validateRequest,
creativeDirectorProjectCreateSchema,
@@ -240,7 +241,7 @@ router.post('/:id/auto-cast', asyncHandler(async (req, res) => {
const composable = project && project.status !== 'paused' && project.status !== 'failed';
const composing = Boolean(compose) && composable && Array.isArray(cast) && cast.length > 0 && !project.treatment;
if (composing) {
- startCreativeDirectorProject(req.params.id).catch((e) => console.log(`⚠️ CD auto-compose failed: ${e.message}`));
+ startCreativeDirectorProject(req.params.id).catch((e) => logFailureWithStack(`❌ CD auto-compose failed for ${req.params.id}`, e));
}
// First-pass gen (#1818): when opted in, kick off a catalog portrait render
// for each member auto-cast just added that has no portrait yet. The renders
@@ -252,7 +253,7 @@ router.post('/:id/auto-cast', asyncHandler(async (req, res) => {
if (generateFirstPass && Array.isArray(result.added) && result.added.length > 0) {
firstPass = await enqueueFirstPassPortraits(result.added, project)
.catch((e) => {
- console.log(`⚠️ CD first-pass portraits failed: ${e.message}`);
+ console.warn(`⚠️ CD first-pass portraits failed for ${req.params.id}: ${e.message}`);
return null;
});
}
@@ -266,7 +267,7 @@ router.post('/:id/auto-cast', asyncHandler(async (req, res) => {
if (generateFirstPassMusicBed && project) {
firstPassMusicBed = await enqueueFirstPassMusicBed(project)
.catch((e) => {
- console.log(`⚠️ CD first-pass music bed failed: ${e.message}`);
+ console.warn(`⚠️ CD first-pass music bed failed for ${req.params.id}: ${e.message}`);
return null;
});
}
@@ -306,7 +307,7 @@ router.patch('/:id/plan', asyncHandler(async (req, res) => {
const updated = await setPlan(req.params.id, plan);
const { advanceAfterPlanStepSettled } = await import('../services/creativeDirector/planAdvance.js');
advanceAfterPlanStepSettled(req.params.id)
- .catch((e) => console.log(`⚠️ CD plan advance failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD plan advance failed for ${req.params.id}`, e));
res.json(updated);
}));
@@ -331,7 +332,7 @@ router.post('/:id/directive', asyncHandler(async (req, res) => {
if (!parked) {
const { advanceAfterPlanStepSettled } = await import('../services/creativeDirector/planAdvance.js');
advanceAfterPlanStepSettled(req.params.id)
- .catch((e) => console.log(`⚠️ CD directive advance failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD directive advance failed for ${req.params.id}`, e));
}
res.json(updated);
}));
@@ -347,7 +348,7 @@ router.post('/:id/replan', asyncHandler(async (req, res) => {
const updated = await updateProject(req.params.id, { plan: null, status: 'planning', failureReason: null });
const { advanceAfterPlanStepSettled } = await import('../services/creativeDirector/planAdvance.js');
advanceAfterPlanStepSettled(req.params.id)
- .catch((e) => console.log(`⚠️ CD replan advance failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD replan advance failed for ${req.params.id}`, e));
res.json(updated);
}));
@@ -376,7 +377,7 @@ router.post('/:id/plan/step/:stepId', asyncHandler(async (req, res) => {
}
const { advanceAfterPlanStepSettled } = await import('../services/creativeDirector/planAdvance.js');
advanceAfterPlanStepSettled(req.params.id)
- .catch((e) => console.log(`⚠️ CD plan step ${action} advance failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD plan step ${action} advance failed for ${req.params.id}`, e));
res.json(await getProject(req.params.id));
}));
@@ -395,7 +396,7 @@ router.patch('/:id/scene/:sceneId', asyncHandler(async (req, res) => {
// Fire-and-forget — agent or user just settled a scene; nudge the
// orchestrator so the next scene (or stitch) starts.
const { advanceAfterSceneSettled } = await import('../services/creativeDirector/completionHook.js');
- advanceAfterSceneSettled(req.params.id).catch((e) => console.log(`⚠️ CD scene advance failed: ${e.message}`));
+ advanceAfterSceneSettled(req.params.id).catch((e) => logFailureWithStack(`❌ CD scene advance failed for ${req.params.id}`, e));
}
res.json(updated);
}));
@@ -442,7 +443,7 @@ router.post('/:id/start', asyncHandler(async (req, res) => {
// Fire-and-forget — the orchestrator runs server-side and may spawn an
// agent (treatment / evaluate) or kick off a render directly. The route
// returns immediately; the UI's polling reflects state changes.
- startCreativeDirectorProject(project.id).catch((e) => console.log(`⚠️ CD start failed: ${e.message}`));
+ startCreativeDirectorProject(project.id).catch((e) => logFailureWithStack(`❌ CD start failed for ${project.id}`, e));
res.json({ ok: true, project: await getProject(project.id) });
}));
@@ -466,7 +467,7 @@ router.post('/:id/pause', asyncHandler(async (req, res) => {
// time only, no Claude in the loop.
router.post('/smoke-test', asyncHandler(async (_req, res) => {
const project = await createSmokeTestProject();
- startCreativeDirectorProject(project.id).catch((e) => console.log(`⚠️ CD smoke start failed: ${e.message}`));
+ startCreativeDirectorProject(project.id).catch((e) => logFailureWithStack(`❌ CD smoke start failed for ${project.id}`, e));
res.status(201).json(project);
}));
@@ -488,7 +489,7 @@ router.post('/:id/resume', asyncHandler(async (req, res) => {
// without this the resumed project runs its whole next pass under a banner
// reporting the stop the user just undid.
await updateProject(project.id, { status: restored, failureReason: null });
- startCreativeDirectorProject(project.id).catch((e) => console.log(`⚠️ CD resume failed: ${e.message}`));
+ startCreativeDirectorProject(project.id).catch((e) => logFailureWithStack(`❌ CD resume failed for ${project.id}`, e));
res.json({ ok: true, project: await getProject(project.id) });
}));
diff --git a/server/routes/creativeDirector.test.js b/server/routes/creativeDirector.test.js
index 9613e5ae21..d49b53ee88 100644
--- a/server/routes/creativeDirector.test.js
+++ b/server/routes/creativeDirector.test.js
@@ -450,6 +450,24 @@ describe('creativeDirector routes', () => {
expect(hook.startCreativeDirectorProject).toHaveBeenCalledWith('cd-1');
});
+ it('logs a rejected background kick to stderr with the project id and stack, and still answers 200', async () => {
+ cdService.getProject.mockResolvedValue({ id: 'cd-1', name: 'A', status: 'draft' });
+ cdService.updateProject.mockResolvedValue({});
+ hook.startCreativeDirectorProject.mockRejectedValueOnce(new Error('enqueue exploded'));
+ const errSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
+ try {
+ const r = await request(app).post('/api/creative-director/cd-1/start');
+ await new Promise((resolve) => setImmediate(resolve));
+ expect(r.status).toBe(200);
+ expect(errSpy).toHaveBeenCalledWith(expect.stringContaining('❌ CD start failed for cd-1: enqueue exploded'), expect.stringContaining('enqueue exploded'));
+ expect(logSpy).not.toHaveBeenCalledWith(expect.stringContaining('CD start failed'));
+ } finally {
+ errSpy.mockRestore();
+ logSpy.mockRestore();
+ }
+ });
+
it('resets failed scenes back to pending and re-fires orchestrator', async () => {
cdService.getProject.mockResolvedValueOnce({
id: 'cd-1',
diff --git a/server/services/creativeDirector/completionHook.js b/server/services/creativeDirector/completionHook.js
index 7544a9a36a..4cd0da5c69 100644
--- a/server/services/creativeDirector/completionHook.js
+++ b/server/services/creativeDirector/completionHook.js
@@ -44,6 +44,7 @@ import {
exhaustedDeliverableStreak,
missedDeliverableReason,
} from './deliverableGate.js';
+import { logFailureWithStack } from '../../lib/failureLogging.js';
export async function handleCreativeDirectorCompletion(task, agentId, success) {
const videoAttempt = task?.metadata?.videoProduction;
@@ -146,7 +147,7 @@ export async function handleCreativeDirectorCompletion(task, agentId, success) {
// the user has no idea what happened.
const reason = `${meta.kind} agent task failed (taskId=${task.id || '?'}, agent=${agentId || '?'})`;
await updateProject(project.id, { status: 'failed', failureReason: reason })
- .catch((e) => console.log(`⚠️ CD updateProject(failed) for ${project.id} failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD updateProject(failed) for ${project.id} failed`, e));
console.error(`❌ CD project ${project.id} marked failed (task ${meta.kind} failed)`);
return;
}
@@ -304,7 +305,7 @@ export async function advanceAfterSceneSettled(projectId, opts = {}) {
if (emptyStreak) {
await closeDeliverableStreak(project.id, project.runs, 'treatment');
await updateProject(project.id, { status: 'paused', failureReason: blockedStageReason('treatment', emptyStreak) })
- .catch((e) => console.log(`⚠️ CD updateProject(paused) for ${project.id} failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD updateProject(paused) for ${project.id} failed`, e));
console.log(`⏸️ CD project ${project.id}: treatment agent came back empty ${emptyStreak}× — paused for a model change`);
return;
}
@@ -530,7 +531,7 @@ export async function advanceAfterSceneSettled(projectId, opts = {}) {
// text-to-video, exactly as the fire-and-forget contract allowed.
// Runs outside the request lifecycle — never throw.
waitForSeedFrameThenAdvance(project.id, sceneId)
- .catch((e) => console.log(`⚠️ CD deferred advance for ${project.id}/${sceneId} failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD deferred advance for ${project.id}/${sceneId} failed`, e));
};
// Match by scene TAG, not the single job id we happened to sample: if
// a duplicate/re-queued seed job for the same scene completes first and
@@ -605,7 +606,7 @@ export async function advanceAfterSceneSettled(projectId, opts = {}) {
const accepted = scenes.filter((s) => s.status === 'accepted');
if (!accepted.length) {
await updateProject(project.id, { status: 'failed' })
- .catch((e) => console.log(`⚠️ CD updateProject(failed) for ${projectId} failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD updateProject(failed) for ${projectId} failed`, e));
console.error(`❌ CD project ${projectId}: every scene failed — marking project failed`);
return;
}
diff --git a/server/services/creativeDirector/planAdvance.js b/server/services/creativeDirector/planAdvance.js
index 93b2487e7e..fcfc2aa92e 100644
--- a/server/services/creativeDirector/planAdvance.js
+++ b/server/services/creativeDirector/planAdvance.js
@@ -36,6 +36,7 @@ import { isAutopilotActive } from '../pipeline/seriesAutopilot/session.js';
import { getSeries } from '../pipeline/series.js';
import { MAX_REPLAN_ROUNDS, PLAN_STEP_TERMINAL_SUCCESS } from '../../lib/creativeDirectorPresets.js';
import { blockedStageReason, closeDeliverableStreak, exhaustedDeliverableStreak } from './deliverableGate.js';
+import { logFailureWithStack } from '../../lib/failureLogging.js';
// The registry tool that runs Series Autopilot as a plan step. A long-running
// step whose dispatch returns a run handle (a `runId`, not a media `jobId`)
@@ -546,7 +547,7 @@ function armPlanJobListener(projectId, stepId, jobId, runId, expectedProductionR
await updatePlanStep(projectId, stepId, { ...(expectedProductionRevision === undefined ? {} : { expectedProductionRevision }), status: 'failed', result: { jobId, jobStatus: job.status } });
await handlePlanStepFailure(projectId, { stepId, toolName: '(long-running job)', retryCount: 0 });
}
- }).catch((e) => console.log(`⚠️ CD plan ${projectId} job settle for ${stepId} failed: ${e.message}`));
+ }).catch((e) => logFailureWithStack(`❌ CD plan ${projectId} job settle for ${stepId} failed`, e));
}
mediaJobEvents.on('completed', settle);
mediaJobEvents.on('failed', settle);
@@ -667,7 +668,7 @@ function armAutopilotListener(projectId, stepId, seriesId, runId, apResult, expe
await finishRun(projectId, runId, 'failed', `autopilot run stalled — no activity for ${Math.round(AUTOPILOT_LISTENER_IDLE_MS / 60000)}m`);
await updatePlanStep(projectId, stepId, { ...(expectedProductionRevision === undefined ? {} : { expectedProductionRevision }), status: 'failed', result: { error: 'autopilot run stalled (idle backstop)' } });
await handlePlanStepFailure(projectId, { stepId, toolName: '(series autopilot)', retryCount: 0 });
- })().catch((e) => console.log(`⚠️ CD plan ${projectId} autopilot idle-backstop settle for ${stepId} failed: ${e.message}`));
+ })().catch((e) => logFailureWithStack(`❌ CD plan ${projectId} autopilot idle-backstop settle for ${stepId} failed`, e));
}, AUTOPILOT_LISTENER_IDLE_MS);
idleTimer.unref?.();
};
@@ -682,7 +683,7 @@ function armAutopilotListener(projectId, stepId, seriesId, runId, apResult, expe
fired = true;
teardown();
settleAutopilotStep(projectId, stepId, runId, payload, expectedProductionRevision)
- .catch((e) => console.log(`⚠️ CD plan ${projectId} autopilot settle for ${stepId} failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD plan ${projectId} autopilot settle for ${stepId} failed`, e));
}
autopilotEvents.on(seriesId, handler);
planJobCleanups.set(key, teardown);
@@ -699,7 +700,7 @@ function armAutopilotListener(projectId, stepId, seriesId, runId, apResult, expe
teardown();
await settleAutopilotStep(projectId, stepId, runId, marker, expectedProductionRevision);
}
- })().catch((e) => console.log(`⚠️ CD plan ${projectId} autopilot marker settle for ${stepId} failed: ${e.message}`));
+ })().catch((e) => logFailureWithStack(`❌ CD plan ${projectId} autopilot marker settle for ${stepId} failed`, e));
}
}
diff --git a/server/services/creativeDirector/recovery.js b/server/services/creativeDirector/recovery.js
index 7ce0289ce4..5d8feb632e 100644
--- a/server/services/creativeDirector/recovery.js
+++ b/server/services/creativeDirector/recovery.js
@@ -28,6 +28,7 @@
import { listProjects, updateScene, updatePlanStep, updateProject } from './local.js';
import { listJobs, cancelJob } from '../mediaJobQueue/index.js';
import { inflightRuns, ownedLiveJobs, retireRuns } from './stopProject.js';
+import { logFailureWithStack } from '../../lib/failureLogging.js';
// Boot-time coordination: cos.start() (entered from cos.init() when
// alwaysOn/autoStart is configured) calls resetOrphanedTasks(), which
@@ -186,7 +187,7 @@ export async function recoverInFlightProjects() {
// step from the reset plan). Legacy video projects stay on the scene loop.
if (project.directive) {
advanceAfterPlanStepSettled(project.id)
- .catch((e) => console.log(`⚠️ CD recovery: plan advance for ${project.id} failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD recovery: plan advance for ${project.id} failed`, e));
resumed += 1;
continue;
}
@@ -202,7 +203,7 @@ export async function recoverInFlightProjects() {
.catch((e) => console.log(`⚠️ CD recovery: reset stitching→rendering for ${project.id} failed: ${e.message}`));
}
advanceAfterSceneSettled(project.id)
- .catch((e) => console.log(`⚠️ CD recovery: advance for ${project.id} failed: ${e.message}`));
+ .catch((e) => logFailureWithStack(`❌ CD recovery: advance for ${project.id} failed`, e));
resumed += 1;
}
}
diff --git a/server/services/creativeDirector/sceneEvaluator.js b/server/services/creativeDirector/sceneEvaluator.js
index ba6308d8b8..78edc52b0d 100644
--- a/server/services/creativeDirector/sceneEvaluator.js
+++ b/server/services/creativeDirector/sceneEvaluator.js
@@ -38,6 +38,7 @@ import { addItem } from '../mediaCollections.js';
import { updateScene, recordRun, updateRun } from './local.js';
import { resolveStagePin } from './projectsLogic.js';
import { enqueueEvaluateTask } from './agentBridge.js';
+import { logFailureWithStack } from '../../lib/failureLogging.js';
// Cap frames per call — the runner base64-inlines every frame into one request
// body, so a large batch balloons the prompt and a local VLM's context window.
@@ -299,7 +300,7 @@ export async function applySceneVerdict(project, scene, verdict, llm = null, run
const advance = async () => {
const advanceAfterSceneSettled = await loadAdvance();
return advanceAfterSceneSettled(project.id).catch((err) =>
- console.log(`⚠️ CD advance after scene ${scene.sceneId} settled failed: ${err.message}`));
+ logFailureWithStack(`❌ CD advance after scene ${scene.sceneId} of ${project.id} settled failed`, err));
};
if (verdict.accepted) {
diff --git a/server/services/creativeDirector/sceneRunner.js b/server/services/creativeDirector/sceneRunner.js
index 08a8865563..061d7d86eb 100644
--- a/server/services/creativeDirector/sceneRunner.js
+++ b/server/services/creativeDirector/sceneRunner.js
@@ -44,6 +44,7 @@ import { getSettings } from '../settings.js';
import { updateScene, updateProject, getProject } from './local.js';
import { dispatchSceneEvaluation } from './sceneEvaluator.js';
import { videoAudioIsDisabled } from './videoAudio.js';
+import { logFailureWithStack } from '../../lib/failureLogging.js';
// Max render+eval attempts per scene (shared with the evaluator so render-retry
// and eval-retry caps can't silently diverge — both bump the same scene.retryCount).
@@ -379,7 +380,7 @@ async function handleRenderCompleted(projectId, sceneId, jobId, opts = {}) {
await updateProject(projectId, {
status: 'failed',
failureReason: `i2v continuation regression detected: ${reason}`,
- }).catch((e) => console.log(`⚠️ CD updateProject(failed) for ${projectId} failed: ${e.message}`));
+ }).catch((e) => logFailureWithStack(`❌ CD updateProject(failed) for ${projectId} failed`, e));
return;
}
const videoPath = join(PATHS.videos, `${jobId}.mp4`);
@@ -398,7 +399,7 @@ async function handleRenderCompleted(projectId, sceneId, jobId, opts = {}) {
await updateProject(projectId, {
status: 'failed',
failureReason: `unplayable render detected: ${reason}`,
- }).catch((e) => console.log(`⚠️ CD updateProject(failed) for ${projectId} failed: ${e.message}`));
+ }).catch((e) => logFailureWithStack(`❌ CD updateProject(failed) for ${projectId} failed`, e));
return;
}
await updateScene(projectId, sceneId, { ...(opts.workRevision === undefined ? {} : { expectedWorkRevision: opts.workRevision }),