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: keep Creative Director actions tied to the current project (#8270)

[._.]/ Adam Eivy8919095946d3
diff --git a/client/src/pages/CreativeDirectorDetail.jsx b/client/src/pages/CreativeDirectorDetail.jsx
index 715142a985..22a01d7957 100644
--- a/client/src/pages/CreativeDirectorDetail.jsx
+++ b/client/src/pages/CreativeDirectorDetail.jsx
@@ -45,6 +45,17 @@ const TABS = [
export default function CreativeDirectorDetail({ basePath = '/creative-director' } = {}) {
const { id } = useParams();
+ // Give each route identity its own state and callbacks, including confirmations
+ // and child saves. A late callback from a prior visit cannot update this visit.
+ return <CreativeDirectorProject key={id} id={id} basePath={basePath} />;
+}
+
+function CreativeDirectorProject({ id, basePath }) {
+ const active = useRef(false);
+ useEffect(() => {
+ active.current = true;
+ return () => { active.current = false; };
+ }, []);
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const editingDraft = searchParams.get('draft') === '1';
@@ -119,7 +130,8 @@ export default function CreativeDirectorDetail({ basePath = '/creative-director'
const fetchProject = useCallback(async () => {
const p = await getCreativeDirectorProject(id).catch(() => null);
- setProject(p);
+ if (!active.current) return null;
+ setProject(p?.id === id ? p : null);
setLoading(false);
return null;
}, [id]);
@@ -129,6 +141,7 @@ export default function CreativeDirectorDetail({ basePath = '/creative-director'
// Filter by `taskId` prefix `cd-<projectId>-` (agentBridge's id scheme).
const fetchAgents = useCallback(async () => {
const data = await getCosAgents().catch(() => []);
+ if (!active.current) return null;
const prefix = `cd-${id}-`;
const mine = (data || []).filter((a) => a.status === 'running' && (a.taskId || '').startsWith(prefix));
setActiveAgents(mine);
@@ -185,6 +198,7 @@ export default function CreativeDirectorDetail({ basePath = '/creative-director'
const [deleting, setDeleting] = useState(false);
const handleAction = async (kind) => {
+ if (!active.current || project?.id !== id) return;
// Map action → past-tense label and optimistic status up-front.
const successMessages = {
start: 'Started', pause: 'Paused', resume: 'Resumed',
@@ -202,20 +216,24 @@ export default function CreativeDirectorDetail({ basePath = '/creative-director'
else if (kind === 'pause') await pauseCreativeDirectorProject(id, { silent: true });
else if (kind === 'resume') await resumeCreativeDirectorProject(id, { silent: true });
else if (kind === 'stop') await stopCreativeDirectorProject(id, { silent: true });
+ if (!active.current) return;
toast.success(successMessages[kind] || kind);
if (optimisticStatus) setProject((p) => p ? { ...p, status: optimisticStatus } : p);
} catch (err) {
- toast.error(err.message || `Failed to ${kind}`);
+ if (active.current) toast.error(err.message || `Failed to ${kind}`);
}
};
const handleDelete = async () => {
+ if (!active.current || project?.id !== id) return;
setDeleting(true);
try {
await deleteCreativeDirectorProject(id, { silent: true });
+ if (!active.current) return;
toast.success('Creative Director project deleted');
navigate(basePath);
} catch (err) {
+ if (!active.current) return;
toast.error(err.message || 'Failed to delete project');
setDeleting(false);
}
@@ -240,7 +258,7 @@ export default function CreativeDirectorDetail({ basePath = '/creative-director'
/>
);
}
- if (!project) return <div className="p-6 text-port-error">Project not found.</div>;
+ if (!project || project.id !== id) return <div className="p-6 text-port-error">Project not found.</div>;
const goTo = (tabId) => navigate(`${basePath}/${id}/${tabId}`);
diff --git a/client/src/pages/CreativeDirectorDetail.test.jsx b/client/src/pages/CreativeDirectorDetail.test.jsx
index 140c70856d..5352ce6c5c 100644
--- a/client/src/pages/CreativeDirectorDetail.test.jsx
+++ b/client/src/pages/CreativeDirectorDetail.test.jsx
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { act, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
-import { MemoryRouter, Route, Routes, useLocation } from 'react-router';
+import { MemoryRouter, Route, Routes, Link, useLocation } from 'react-router';
vi.mock('../services/apiCreativeDirector.js', () => ({
getCreativeDirectorProject: vi.fn(),
@@ -21,13 +21,14 @@ vi.mock('../components/creative-director/TreatmentTab.jsx', () => ({ default: ()
vi.mock('../components/creative-director/SegmentsTab.jsx', () => ({ default: () => null }));
vi.mock('../components/creative-director/PlanTab.jsx', () => ({ default: () => null }));
vi.mock('../components/creative-director/RunsTab.jsx', () => ({ default: () => null }));
-vi.mock('../components/creative-director/ActiveAgentsBanner.jsx', () => ({ default: () => null }));
+vi.mock('../components/creative-director/ActiveAgentsBanner.jsx', () => ({ default: ({ agents }) => <div data-testid="agents">{agents.map(a => a.id).join(',')}</div> }));
vi.mock('../components/creative-director/CreativeDirectorModelsDrawer.jsx', () => ({ default: () => null }));
vi.mock('../components/ui/Toast', () => ({
default: { success: vi.fn(), error: vi.fn(), info: vi.fn(), warning: vi.fn() },
}));
import * as cdApi from '../services/apiCreativeDirector.js';
+import { getCosAgents } from '../services/apiAgents.js';
import CreativeDirectorDetail from './CreativeDirectorDetail';
const PROJECT = {
@@ -85,6 +86,57 @@ describe('CreativeDirectorDetail project deletion', () => {
});
});
+describe('CreativeDirectorDetail route isolation', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ getCosAgents.mockResolvedValue([]);
+ });
+
+ it('keeps B and its agents when A requests finish last, and deletes only confirmed B', async () => {
+ const user = userEvent.setup();
+ let resolveA;
+ let resolveAgentsA;
+ const pendingA = new Promise(resolve => { resolveA = resolve; });
+ const pendingAgentsA = new Promise(resolve => { resolveAgentsA = resolve; });
+ const projectB = { ...PROJECT, id: 'cd-other', name: 'Other project' };
+ cdApi.getCreativeDirectorProject.mockImplementation(id => id === PROJECT.id ? pendingA : Promise.resolve(projectB));
+ getCosAgents.mockReturnValue(pendingAgentsA);
+ render(
+ <MemoryRouter initialEntries={['/creative-director/cd-example/overview']}>
+ <LocationProbe />
+ <Link to="/creative-director/cd-other/overview">Open B</Link>
+ <Routes><Route path="/creative-director/:id/:tab" element={<CreativeDirectorDetail />} /></Routes>
+ </MemoryRouter>,
+ );
+ await waitFor(() => expect(getCosAgents).toHaveBeenCalled());
+ getCosAgents.mockResolvedValue([{ id: 'agent-b', status: 'running', taskId: 'cd-cd-other-task' }]);
+ await user.click(screen.getByRole('link', { name: 'Open B' }));
+ await screen.findByRole('heading', { name: projectB.name });
+ await user.click(screen.getByRole('button', { name: 'Delete project Other project' }));
+ await act(async () => {
+ resolveA(PROJECT);
+ resolveAgentsA([{ id: 'agent-a', status: 'running', taskId: 'cd-cd-example-task' }]);
+ });
+ expect(screen.queryByRole('heading', { name: PROJECT.name })).not.toBeInTheDocument();
+ expect(screen.getByTestId('agents')).toHaveTextContent('agent-b');
+ expect(screen.getByTestId('agents')).not.toHaveTextContent('agent-a');
+ await user.click(screen.getByRole('button', { name: 'Delete', exact: true }));
+ expect(cdApi.deleteCreativeDirectorProject).toHaveBeenCalledWith(projectB.id, { silent: true });
+ });
+
+ it('hides project actions when the response ID differs from the route', async () => {
+ cdApi.getCreativeDirectorProject.mockResolvedValue({ ...PROJECT, id: 'wrong-project' });
+ render(
+ <MemoryRouter initialEntries={['/creative-director/cd-example/overview']}>
+ <Routes><Route path="/creative-director/:id/:tab" element={<CreativeDirectorDetail />} /></Routes>
+ </MemoryRouter>,
+ );
+ await screen.findByText('Project not found.');
+ expect(screen.queryByRole('button', { name: /Delete|Start|Stop|Pause|Resume/ })).not.toBeInTheDocument();
+ expect(screen.queryByRole('heading', { name: PROJECT.name })).not.toBeInTheDocument();
+ });
+});
+
describe('Video saved artifacts', () => {
const videoProject = {
...PROJECT, workspace: 'video', targetDurationSeconds: 120,