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: preserve running media cancellation state across refreshes (#8273)

[._.]/ Adam Eivy651c018db1e1
diff --git a/client/src/components/media/MediaJobsQueue.jsx b/client/src/components/media/MediaJobsQueue.jsx
index 55cbca7247..75676a743e 100644
--- a/client/src/components/media/MediaJobsQueue.jsx
+++ b/client/src/components/media/MediaJobsQueue.jsx
@@ -166,8 +166,8 @@ export default function MediaJobsQueue({ kind, recentLimit = 10, className = ''
.then(() => {
// Optimistic update: queued jobs flip to 'canceled' immediately (the
// worker won't pick them up). For running jobs leave the server status
- // alone and track a UI-only `cancelRequested` flag — the next poll
- // resolves to 'canceled' once the worker observes it.
+ // alone; the next queue refresh replaces this optimistic flag with the
+ // server-projected `cancelRequested` state until the job is terminal.
setJobs((prev) => prev.map((j) => {
if (j.id !== id) return j;
if (j.status === 'queued') return { ...j, status: 'canceled', cancelRequested: false };
diff --git a/client/src/components/media/MediaJobsQueue.test.jsx b/client/src/components/media/MediaJobsQueue.test.jsx
index b83795b175..b7e01394cc 100644
--- a/client/src/components/media/MediaJobsQueue.test.jsx
+++ b/client/src/components/media/MediaJobsQueue.test.jsx
@@ -7,12 +7,13 @@ import { findEnabledByRole } from '../../test/enabledBarrier.js';
// Mock the media-jobs API so the queue renders a controlled job list without
// the network. useAutoRefetch calls the fetcher on mount.
const listQueueMediaJobs = vi.fn();
+const cancelMediaJob = vi.fn();
const retryMediaJob = vi.fn();
const resumeMediaVideoHold = vi.fn();
const listMediaVideoHolds = vi.fn();
vi.mock('../../services/apiMediaJobs.js', () => ({
listQueueMediaJobs: (...a) => listQueueMediaJobs(...a),
- cancelMediaJob: vi.fn(),
+ cancelMediaJob: (...a) => cancelMediaJob(...a),
cancelQueuedMediaJobs: vi.fn(),
deleteMediaJob: vi.fn(),
retryMediaJob: (...a) => retryMediaJob(...a),
@@ -56,6 +57,7 @@ const trainingJob = {
beforeEach(() => {
listQueueMediaJobs.mockReset();
+ cancelMediaJob.mockReset().mockResolvedValue({ ok: true, status: 'canceling' });
listMediaVideoHolds.mockReset().mockResolvedValue([]);
resumeMediaVideoHold.mockReset();
listLoraTrainingCheckpoints.mockReset();
@@ -113,6 +115,44 @@ describe('MediaJobsQueue — unavailable state', () => {
});
});
+describe('MediaJobsQueue — cancellation state', () => {
+ it('keeps a running cancellation through refresh and clears it on terminal status', async () => {
+ const user = userEvent.setup();
+ const runningJob = {
+ id: 'canceljob12345678',
+ kind: 'image',
+ status: 'running',
+ queuedAt: '2026-06-19T10:00:00Z',
+ params: { prompt: 'an invented cancellation prompt', modelId: 'example-model' },
+ };
+ let queueSnapshot = [runningJob];
+ listQueueMediaJobs.mockImplementation(() => Promise.resolve(queueSnapshot));
+
+ render(<MediaJobsQueue kind="image" />);
+
+ await screen.findByText(/an invented cancellation prompt/);
+ await user.click(screen.getByRole('button', { name: 'Cancel' }));
+ expect(cancelMediaJob).toHaveBeenCalledWith('canceljob12345678', { silent: true });
+ expect(await screen.findByText('cancelling…')).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Cancel' })).not.toBeInTheDocument();
+
+ queueSnapshot = [{ ...runningJob, cancelRequested: true }];
+ await user.click(screen.getByRole('button', { name: 'Refresh' }));
+ await waitFor(() => {
+ expect(screen.getByText('cancelling…')).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Cancel' })).not.toBeInTheDocument();
+ });
+
+ queueSnapshot = [{ ...runningJob, status: 'canceled', cancelRequested: false, error: 'Canceled' }];
+ await user.click(screen.getByRole('button', { name: 'Refresh' }));
+ await user.click(await screen.findByText(/Show failed \/ canceled/));
+
+ expect(await screen.findByText('canceled')).toBeInTheDocument();
+ expect(screen.queryByText('cancelling…')).not.toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Cancel' })).not.toBeInTheDocument();
+ });
+});
+
describe('MediaJobsQueue — Creative Director renders', () => {
it('surfaces a Creative Director-owned video job in the live queue', async () => {
listQueueMediaJobs.mockResolvedValue([{
diff --git a/server/services/mediaJobQueue/sanitizeJob.js b/server/services/mediaJobQueue/sanitizeJob.js
index 60f497b8d9..1c555dce10 100644
--- a/server/services/mediaJobQueue/sanitizeJob.js
+++ b/server/services/mediaJobQueue/sanitizeJob.js
@@ -101,6 +101,9 @@ export function sanitizeJob(job) {
executionLane: mediaJobExecutionLane({ kind: job.kind, mode: job.params?.mode, remote: routed }),
owner: job.owner,
status: job.status,
+ // This flag describes an in-flight request. Archived terminal jobs can
+ // retain the internal marker, and remote recovery may resume as queued.
+ cancelRequested: (job.status === 'queued' || job.status === 'running') && job.cancelRequested === true,
...(hold?.success ? { hold: { ...hold.data, heldJobCount: job.hold.heldJobCount,
...(job.hold.scope === 'local-video' ? { scope: 'local-video' } : {}) } } : {}),
queuedAt: job.queuedAt,
diff --git a/server/services/mediaJobQueue/sanitizeJob.test.js b/server/services/mediaJobQueue/sanitizeJob.test.js
index a5ef4b452b..8bf645364e 100644
--- a/server/services/mediaJobQueue/sanitizeJob.test.js
+++ b/server/services/mediaJobQueue/sanitizeJob.test.js
@@ -2,6 +2,22 @@ import { describe, expect, it } from 'vitest';
import { sanitizeJob } from './sanitizeJob.js';
describe('sanitizeJob', () => {
+ it('projects cancellation only while the job is still active', () => {
+ const projectCancellation = (status) => sanitizeJob({
+ id: 'job-cancel-example',
+ kind: 'image',
+ status,
+ cancelRequested: true,
+ }).cancelRequested;
+
+ expect(projectCancellation('running')).toBe(true);
+ // Remote cancellation recovery can restore an active job in the queue.
+ expect(projectCancellation('queued')).toBe(true);
+ expect(projectCancellation('completed')).toBe(false);
+ expect(projectCancellation('canceled')).toBe(false);
+ expect(projectCancellation('failed')).toBe(false);
+ });
+
it('projects only validated image execution provenance from a completed result', () => {
const sanitized = sanitizeJob({
id: 'image-job',