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
fix resume review findings: unlink before canceling, re-pin a running production run, refuse lowered limits
[._.]/ Adam Eivy01157ffd7fcc
diff --git a/docs/features/music-video-autonomous.md b/docs/features/music-video-autonomous.mdindex 55fdc00594..8f735fe0d5 100644--- a/docs/features/music-video-autonomous.md+++ b/docs/features/music-video-autonomous.md@@ -144,7 +144,7 @@ and does not press Create or spend credits on a second generation.- Any other stage failure parks **`failed`** with the error; Retry re-runs that stage only. Songs already submitted to Suno are stored the moment Suno accepts the request, so a failed download retries the same songs and never spends credits on a second generation.- Resume after Stop waits for the prior stage attempt to settle before restarting. A Cancel while Resume waits remains canceled.- A parked or failed delegated production run parks this run `needs-human`; Resume resumes the production run. A production run canceled on its own (not by canceling this run) also parks it `needs-human` (`PRODUCTION_CANCELED`).-- **Resume after manual edits.** At the produce stage, Resume follows the newest production run started since the run began, so a run the director started by hand (for example with a different video model) is adopted: a live one is followed, a parked one is resumed, and a completed one goes straight to the final render. With no production run left to follow, Resume starts a new one from the brief. A run canceled while it waited on production can be resumed the same way. Resume may also carry `limits` (raised or lowered, applied to the brief and to the resumed production run) and `models` (per-tool swaps, `null` clears a pin); a changed model cancels the current production run and starts a new one with the new pool.+- **Resume after manual edits.** At the produce stage, Resume follows the newest production run started since the run began, so a run the director started by hand (for example with a different video model) is adopted: a live one is followed, a parked one is resumed, and a completed one goes straight to the final render. With no production run left to follow, Resume starts a new one from the brief. A run canceled while it waited on production can be resumed the same way. Resume may also carry `limits` (raised only once production has started, applied to the brief and to the resumed production run) and `models` (per-tool swaps, `null` clears a pin); a changed model cancels the current production run and starts a new one with the new pool.The Suno adapter fills the form through `placeholder` / role selectors and reads the new `/song/<id>` links. It opens the first take in the same signed-in PortOS Browser, selects only M4A, and presses Download (or Unlock & Download) once. It waits for the browser download to finish saving, checks the container and decodes the complete audio to reject damaged files, and imports the original M4A without conversion. The export has a ten-minute deadline; timeout, cancellation, or invalid audio removes staging files and never imports a partial/error response. Failures identify the export stage using bounded reason metadata. A retry reopens the existing song rather than pressing Create again.diff --git a/server/services/musicVideo/autonomousService.js b/server/services/musicVideo/autonomousService.jsindex d644dce135..56b48ebc83 100644--- a/server/services/musicVideo/autonomousService.js+++ b/server/services/musicVideo/autonomousService.js@@ -1072,6 +1072,10 @@ export async function resumeAutonomousVideo(projectId, edits = {}, { autoApproveif (retake) assertAtSongCheckpoint(run);const modelsChanged = modelsPatch !== null && JSON.stringify(modelsPatch) !== JSON.stringify(run.brief.models || {});const limitsPatch = edits.limits ? { ...run.brief.limits, ...edits.limits } : null;+ // A production run only takes raised limits; refuse a lower one before anything changes.+ if (edits.limits && run.stage === 'produce' && Object.entries(edits.limits).some(([key, value]) => value != null && value < (run.brief.limits?.[key] ?? 0))) {+ throw runError(400, 'VALIDATION_ERROR', 'Resuming production can only raise a limit');+ }// Stop changes the record immediately, but its stage may still be settling.// Let that attempt release ownership before marking a new attempt running.await inflight.get(projectId);@@ -1155,8 +1159,9 @@ async function resumeDelegatedProduction(projectId, run, { restart = false, limi.filter((r) => ADOPTABLE_PRODUCTION.has(r.status) && String(r.createdAt || '') >= String(run.createdAt || '')).sort((a, b) => String(b.createdAt || '').localeCompare(String(a.createdAt || '')))[0] || null;if (!adopt) {- if (current && PRODUCTION_LIVE.has(current.status)) await deps.cancelProduction(projectId, current.id).catch(() => {});+ // Unlink first: the old run's own "canceled" event must no longer match this run.const out = await patchRun(projectId, (r) => ({ output: { productionRunId: null }, ...stagePatch(r, 'produce', { status: 'pending', error: null, step: null }) }));+ if (current && PRODUCTION_LIVE.has(current.status)) await deps.cancelProduction(projectId, current.id).catch(() => {});console.log(`🎬 Autonomous music video ${short(run.id)} starting a new production run${restart ? ' with the new models' : ''}`);advanceInBackground(projectId);return { project: out.project, run: presentAutonomousRun(out.run) };@@ -1168,7 +1173,8 @@ async function resumeDelegatedProduction(projectId, run, { restart = false, limiif (adopt.status === 'completed') {await patchRun(projectId, () => ({ output: { productionDone: true } }));await reconcileFinalRender(projectId, { restart: true });- } else if (adopt.status !== 'running') {+ } else {+ // Resuming a "running" run is safe and re-pins one left by a previous server process.const productionLimits = limits ? Object.fromEntries(Object.entries(limits).filter(([, v]) => v != null)) : undefined;const failure = await deps.resumeProduction(projectId, adopt.id, { acceptBasis: true, ...(productionLimits ? { limits: productionLimits } : {}) }).then(() => null, (err) => err);diff --git a/server/services/musicVideo/autonomousService.test.js b/server/services/musicVideo/autonomousService.test.jsindex f1d8418582..bf602a7b6b 100644--- a/server/services/musicVideo/autonomousService.test.js+++ b/server/services/musicVideo/autonomousService.test.js@@ -290,7 +290,8 @@ describe('startAutonomousVideo', () => {store.get('mv-auto').productionRuns.push({ id: 'mvpr-manual', status: 'running', createdAt: later() });await service.resumeAutonomousVideo('mv-auto');expect(runOf()).toMatchObject({ status: 'running', stage: 'produce', output: expect.objectContaining({ productionRunId: 'mvpr-manual' }) });- expect(doubles.resumeProduction).not.toHaveBeenCalled();+ // Resuming the adopted live run re-pins it to this process (a no-op when it already is).+ expect(doubles.resumeProduction).toHaveBeenCalledWith('mv-auto', 'mvpr-manual', { acceptBasis: true });expect(doubles.startProduction).toHaveBeenCalledOnce();// The adopted run's completion is now ours: it starts the final render.await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-manual', run: { status: 'completed' } });@@ -311,6 +312,8 @@ describe('startAutonomousVideo', () => {await delegated();store.get('mv-auto').productionRuns[0].status = 'limit-reached';await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'limit-reached', stopReason: 'generation limit' } });+ await expect(service.resumeAutonomousVideo('mv-auto', { limits: { maxGenerations: 10 } })).rejects.toMatchObject({ code: 'VALIDATION_ERROR' });+ expect(runOf().brief.limits.maxGenerations).toBe(40);await service.resumeAutonomousVideo('mv-auto', { limits: { maxGenerations: 120 } });expect(doubles.resumeProduction).toHaveBeenCalledWith('mv-auto', 'mvpr-1', { acceptBasis: true, limits: { maxGenerations: 120 } });expect(runOf().brief.limits.maxGenerations).toBe(120);@@ -318,11 +321,26 @@ describe('startAutonomousVideo', () => {store.get('mv-auto').productionRuns[0].status = 'blocked';await service.__testing.onProductionEvent({ projectId: 'mv-auto', runId: 'mvpr-1', run: { status: 'blocked', stopReason: 'no image-to-video' } });doubles.startProduction.mockResolvedValueOnce({ run: { id: 'mvpr-2' } });+ // Like the real service, canceling the old run publishes its own "canceled" event.+ doubles.cancelProduction.mockImplementationOnce(async (projectId, runId) => {+ store.get(projectId).productionRuns[0].status = 'canceled';+ await service.__testing.onProductionEvent({ projectId, runId, run: { status: 'canceled' } });+ });await service.resumeAutonomousVideo('mv-auto', { models: { 'video:local': 'image-capable' } });expect(doubles.cancelProduction).toHaveBeenCalledWith('mv-auto', 'mvpr-1');await vi.waitFor(() => expect(runOf().output.productionRunId).toBe('mvpr-2'));expect(doubles.startProduction.mock.calls[1][1].pool).toEqual([{ kind: 'image', mode: 'local' }, { kind: 'video', mode: 'local', model: 'image-capable' }]);await expect(service.resumeAutonomousVideo('mv-auto', { models: { 'image:fal': 'x' } })).rejects.toMatchObject({ code: 'VALIDATION_ERROR' });+ expect(runOf()).toMatchObject({ status: 'running', output: expect.objectContaining({ productionRunId: 'mvpr-2' }) });+ });++ it('re-pins a production run left running by a previous server process', async () => {+ await delegated();+ store.get('mv-auto').autonomousRun.processId = 'proc-previous';+ store.get('mv-auto').productionRuns[0].processId = 'proc-previous';+ await service.resumeAutonomousVideo('mv-auto');+ expect(doubles.resumeProduction).toHaveBeenCalledWith('mv-auto', 'mvpr-1', { acceptBasis: true });+ expect(runOf()).toMatchObject({ status: 'running', output: expect.objectContaining({ productionRunId: 'mvpr-1' }) });});it('starts a new production run when there is none left to follow', async () => {