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
Cover art: never lock out "Make with Codex", and crop rotated photos upright
Claude97ad6e6d09fc
diff --git a/client/src/components/musicVideo/CoverArtPanel.jsx b/client/src/components/musicVideo/CoverArtPanel.jsxindex 3173e13c2b..e8973959bf 100644--- a/client/src/components/musicVideo/CoverArtPanel.jsx+++ b/client/src/components/musicVideo/CoverArtPanel.jsx@@ -119,9 +119,10 @@ export default function CoverArtPanel({ project, publishKit }) {Keep the likeness of the current cover image</label>)}- <button type="button" onClick={generate} disabled={!!art.pending}- className="flex items-center gap-1 bg-port-accent/20 text-port-accent disabled:opacity-50 rounded px-2 py-1.5 min-h-[44px] sm:min-h-0">- <Sparkles size={13} /> {art.pending ? 'Making…' : 'Make with Codex'}+ {/* Never disabled by `pending`: the server tells a live render from one a restart lost. */}+ <button type="button" onClick={generate}+ className="flex items-center gap-1 bg-port-accent/20 text-port-accent rounded px-2 py-1.5 min-h-[44px] sm:min-h-0">+ <Sparkles size={13} /> Make with Codex</button></div></div>diff --git a/client/src/components/musicVideo/PublishKitPanel.test.jsx b/client/src/components/musicVideo/PublishKitPanel.test.jsxindex dbc96f09e9..bf110440d4 100644--- a/client/src/components/musicVideo/PublishKitPanel.test.jsx+++ b/client/src/components/musicVideo/PublishKitPanel.test.jsx@@ -78,6 +78,5 @@ describe('PublishKitPanel (#9281)', () => {rerender(<PublishKitPanel project={{ ...project, publishKit: { ...built, coverArt: art } }} publishKit={k} />);expect(screen.getByAltText('Cover art for Example Song')).toBeTruthy();expect(screen.getByText(/Making a cover image on codex/)).toBeTruthy();- expect(screen.getByRole('button', { name: /Making/ })).toBeDisabled();});});diff --git a/server/services/musicVideo/coverArt.js b/server/services/musicVideo/coverArt.jsindex 2df8e3db83..68e83b21c2 100644--- a/server/services/musicVideo/coverArt.js+++ b/server/services/musicVideo/coverArt.js@@ -29,6 +29,9 @@ import { getProject, mutateProjectRecord } from './projects.js';import { projectPublishKit, releaseKitFiles } from './publishKit.js';const MAX_GENERATED = 12;+const LIVE_JOB = new Set(['queued', 'running', 'canceling']);+// A reservation that never got its job id (the process died mid-enqueue) stops blocking after this.+const RESERVATION_TTL_MS = 2 * 60 * 1000;// Codex renders square at 1024; the compose scales it to the store size.const SOURCE_PX = 1024;@@ -40,6 +43,7 @@ const defaults = {chooseRoute: async (project, opts) => (await import('./castAndSetsService.js')).chooseCastAndSetsRoute(project, opts),imageParams: async (settings, route, common) => (await import('./castAndSetsService.js')).imageJobParams(settings, route, common),withStyle: async (...args) => (await import('./styleReferences.js')).withMusicVideoStyle(...args),+ jobStatus: async (jobId) => (await import('../mediaJobQueue/index.js')).getJob(jobId)?.status || null,};let deps = { ...defaults };export function __setCoverArtDepsForTests(overrides) { deps = { ...defaults, ...overrides }; }@@ -133,6 +137,17 @@ function buildCoverArtPrompt(project, { notes = '' } = {}) {].filter(Boolean).join(' ');}+/**+ * Whether a recorded request still has a render on the way. One whose job left+ * the queue without its terminal event reaching the hook (a restart mid-render)+ * is not, so it never locks the director out of asking again.+ */+async function pendingIsLive(pending) {+ if (!pending) return false;+ if (pending.jobId) return LIVE_JOB.has(await deps.jobStatus(pending.jobId).catch(() => null));+ return Date.now() - Date.parse(pending.requestedAt || 0) < RESERVATION_TTL_MS;+}+/*** Ask an image backend (Codex when enabled) for a new cover source. The* completion hook composes the cover from it with the current title and tag.@@ -141,7 +156,8 @@ function buildCoverArtPrompt(project, { notes = '' } = {}) {*/export async function generateCoverArtSource(projectId, { notes = '', reference = null } = {}) {const project = await requireProject(projectId);- if (projectCoverArt(project).pending) throw coverError(409, 'COVER_ART_IN_PROGRESS', 'A cover image is already being made');+ const previous = projectCoverArt(project).pending;+ if (await pendingIsLive(previous)) throw coverError(409, 'COVER_ART_IN_PROGRESS', 'A cover image is already being made');const settings = await deps.getSettings();const route = await deps.chooseRoute(project, { preferred: { mode: 'codex' }, settings })|| await deps.chooseRoute(project, { settings });@@ -150,6 +166,13 @@ export async function generateCoverArtSource(projectId, { notes = '', referenceconst refPath = refName ? resolveGalleryImage(refName) : null;if (reference?.filename && !refPath) throw coverError(422, 'PUBLISH_ASSET_MISSING', `The reference image is missing (${basename(reference.filename)})`);const requestId = randomUUID();+ // Reserve before queueing, so a job that settles at once finds its request+ // current. The check runs again inside the write: a second click that raced+ // past the one above loses here.+ await writeCoverArt(projectId, (art) => {+ if ((art.pending?.requestId || null) !== (previous?.requestId || null)) throw coverError(409, 'COVER_ART_IN_PROGRESS', 'A cover image is already being made');+ return { pending: { requestId, jobId: null, mode: route.mode, requestedAt: new Date().toISOString() }, lastError: null };+ });const common = {prompt: buildCoverArtPrompt(project, { notes }),width: SOURCE_PX,@@ -159,12 +182,18 @@ export async function generateCoverArtSource(projectId, { notes = '', reference// `castAndSets`, so the scene and Cast & Sets hooks ignore the job.musicVideo: { projectId: project.id, coverArt: { requestId } },};- const params = await deps.withStyle(project, await deps.imageParams(settings, route, common), route.mode, route.model, settings);- const sent = await deps.enqueue({ kind: 'image', params, owner: `music-video-cover-art:${project.id}` });- const out = await writeCoverArt(projectId, () => ({- pending: { requestId, jobId: typeof sent?.jobId === 'string' ? sent.jobId : null, mode: route.mode, requestedAt: new Date().toISOString() },- lastError: null,- }));+ const sent = await deps.imageParams(settings, route, common)+ .then((params) => deps.withStyle(project, params, route.mode, route.model, settings))+ .then((params) => deps.enqueue({ kind: 'image', params, owner: `music-video-cover-art:${project.id}` }))+ .catch(async (err) => {+ const failed = await writeCoverArt(projectId, (art) => (art.pending?.requestId === requestId+ ? { pending: null, lastError: trimTo(`The cover image could not be queued: ${err.message}`, 300) } : {}));+ publish(projectId, failed.project);+ throw err;+ });+ const jobId = typeof sent?.jobId === 'string' ? sent.jobId : null;+ // The job may already have settled and cleared the reservation; only a still-current one gets its id.+ const out = await writeCoverArt(projectId, (art) => (art.pending?.requestId === requestId && jobId ? { pending: { ...art.pending, jobId } } : {}));console.log(`🖼️ Music Video cover art ${String(projectId).slice(3, 11)}: source image queued on ${route.mode}`);publish(projectId, out.project);return { project: out.project };diff --git a/server/services/musicVideo/coverArt.test.js b/server/services/musicVideo/coverArt.test.jsindex 1459d355f5..6ef9d9d328 100644--- a/server/services/musicVideo/coverArt.test.js+++ b/server/services/musicVideo/coverArt.test.js@@ -25,12 +25,14 @@ afterAll(() => cleanupTempDataRoots());const compose = vi.fn(async ({ out }) => { await writeFile(out, 'jpeg'); return { width: 3000, height: 3000 }; });const enqueue = vi.fn(async () => ({ jobId: 'job-example' }));+const jobStatus = vi.fn(async () => 'queued');const chooseRoute = vi.fn(async (_project, { preferred } = {}) => (preferred?.mode === 'codex' ? { mode: 'codex', model: null } : null));beforeEach(() => {- compose.mockClear(); enqueue.mockClear(); chooseRoute.mockClear();+ compose.mockClear(); enqueue.mockReset(); enqueue.mockResolvedValue({ jobId: 'job-example' }); chooseRoute.mockClear();+ jobStatus.mockReset(); jobStatus.mockResolvedValue('queued');cover.__setCoverArtDepsForTests({- compose, enqueue, chooseRoute,+ compose, enqueue, chooseRoute, jobStatus,getSettings: async () => ({}),getPlatforms: async () => ({ distrokid: { enabled: true, account: 'Example Artist' } }),imageParams: async (_settings, route, common) => ({ ...common, provider: route.mode }),@@ -113,6 +115,36 @@ describe('release cover art', () => {expect(art).toMatchObject({ pending: null, lastError: 'Codex refused the prompt' });});+ it('files a render that settles before the queue call returns, and frees a failed enqueue', async () => {+ const { id } = await projectWithThumbnail();+ await mkdir(PATHS.images, { recursive: true });+ await writeFile(join(PATHS.images, 'fast-example.png'), 'png');+ // The hook fires while enqueue is still in flight: the reservation is already current.+ enqueue.mockImplementationOnce(async (job) => {+ await cover.onCoverArtImageSettled({ projectId: id, requestId: job.params.musicVideo.coverArt.requestId, filename: 'fast-example.png' });+ return { jobId: 'job-fast' };+ });+ const { project } = await cover.generateCoverArtSource(id);+ expect(project.publishKit.coverArt).toMatchObject({ pending: null, source: { kind: 'image', filename: 'fast-example.png' } });++ enqueue.mockRejectedValueOnce(new Error('Codex is signed out'));+ await expect(cover.generateCoverArtSource(id)).rejects.toThrow('Codex is signed out');+ const art = (await projects.getProject(id)).publishKit.coverArt;+ expect(art.pending).toBeNull();+ expect(art.lastError).toMatch(/Codex is signed out/);+ });++ it('lets the director ask again once a pending render is no longer in the queue', async () => {+ const { id } = await projectWithThumbnail();+ const first = (await cover.generateCoverArtSource(id)).project.publishKit.coverArt.pending;+ await expect(cover.generateCoverArtSource(id)).rejects.toMatchObject({ status: 409 });+ // A restart lost the job's terminal event: the queue no longer holds it live.+ jobStatus.mockResolvedValue('failed');+ const next = (await cover.generateCoverArtSource(id)).project.publishKit.coverArt.pending;+ expect(next.requestId).not.toBe(first.requestId);+ expect(enqueue).toHaveBeenCalledTimes(2);+ });+it('says so when no image backend is enabled', async () => {const { id } = await projectWithThumbnail();chooseRoute.mockResolvedValue(null);@@ -132,5 +164,11 @@ describe('cover lettering', () => {await composeCoverArt({ source, out, title: 'Example Song', tag: 'Example Artist', size: 1000 });const meta = await sharp(out).metadata();expect(meta).toMatchObject({ format: 'jpeg', width: 1000, height: 1000 });++ // A portrait phone photo stored landscape with an EXIF rotation crops on the upright image.+ const rotated = join(dir, 'rotated.jpg');+ await sharp({ create: { width: 640, height: 360, channels: 3, background: '#775533' } }).jpeg().withMetadata({ orientation: 6 }).toFile(rotated);+ await composeCoverArt({ source: rotated, out, title: 'Example Song', focusX: 1, size: 1000 });+ expect(await sharp(out).metadata()).toMatchObject({ width: 1000, height: 1000 });});});diff --git a/server/services/musicVideo/coverArtCompose.js b/server/services/musicVideo/coverArtCompose.jsindex f321063db8..27e2a5346b 100644--- a/server/services/musicVideo/coverArtCompose.js+++ b/server/services/musicVideo/coverArtCompose.js@@ -75,14 +75,14 @@ function coverOverlaySvg({ title, tag = '', accent = COVER_ART_ACCENT, size = CO*/export async function composeCoverArt({ source, out, title, tag = '', accent = COVER_ART_ACCENT, focusX = 0.5, size = COVER_ART_SIZE }, deps = {}) {const sharp = deps.sharp || (await import('sharp')).default;- const meta = await sharp(source).metadata();- const side = Math.min(meta.width, meta.height);+ // Apply the EXIF orientation first, so the crop is measured on the upright image.+ const { data, info } = await sharp(source).rotate().toBuffer({ resolveWithObject: true });+ const side = Math.min(info.width, info.height);const fx = Math.min(1, Math.max(0, Number.isFinite(focusX) ? focusX : 0.5));- const left = Math.round((meta.width - side) * fx);- const top = Math.round((meta.height - side) / 2);+ const left = Math.round((info.width - side) * fx);+ const top = Math.round((info.height - side) / 2);const overlay = Buffer.from(coverOverlaySvg({ title, tag, accent, size }));- await sharp(source)- .rotate()+ await sharp(data).extract({ left, top, width: side, height: side }).resize(size, size, { kernel: 'lanczos3' }).composite([{ input: overlay, top: 0, left: 0 }])