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([story-builder-import-commit-ok-session-fail]): skip re-commit when only createStorySession failed
[._.]/ Adam Eivye86315027460
diff --git a/client/src/pages/StoryBuilder.jsx b/client/src/pages/StoryBuilder.jsxindex 1918a88350..839bb1dd4e 100644--- a/client/src/pages/StoryBuilder.jsx+++ b/client/src/pages/StoryBuilder.jsx@@ -195,9 +195,14 @@ function ImportPanel({ onCreated }) {// re-creates the issues — re-sending the full payload would clobber the// persisted state and risk duplicate issues. Mirrors Importer.jsx.const [arcAlreadyPersisted, setArcAlreadyPersisted] = useState(false);+ // Set once commitImport fully succeeds (issues created) but createStorySession+ // then failed — a re-click must skip commitImport entirely and resume at+ // session creation, otherwise it re-creates the already-created issues and+ // overwrites the arc.+ const [committed, setCommitted] = useState(false);// Any path that clears the preview (analyze, Re-analyze) is a fresh attempt,- // so the partial-retry state can't survive it — centralize the reset here.- useEffect(() => { if (!preview) setArcAlreadyPersisted(false); }, [preview]);+ // so the retry/committed state can't survive it — centralize the reset here.+ useEffect(() => { if (!preview) { setArcAlreadyPersisted(false); setCommitted(false); } }, [preview]);const types = IMPORTER_CONTENT_TYPES || ['short-story', 'novel', 'screenplay', 'comic-script'];@@ -235,33 +240,39 @@ function ImportPanel({ onCreated }) {const issues = preview.issueProposals || [];if (issues.length === 0) { toast.error('No issues were extracted — retry the issue split or adjust the source'); return; }setCommitting(true);- // On an arcAlreadyPersisted retry the server kept arc/seasons/canon from- // the failed commit, so resend issues only — re-sending the full payload- // would clobber the persisted state and risk duplicate issues.- const base = { universeId: preview.universe.id, seriesId: preview.series.id, issues, contentType };- const payload = arcAlreadyPersisted- ? { ...base, canonSelections: { characters: [], places: [], objects: [] }, arc: null, seasons: [] }- : {- ...base,- canonSelections: {- characters: preview.canonPreview?.characters || [],- places: preview.canonPreview?.places || [],- objects: preview.canonPreview?.objects || [],- },- arc: pickArcFields(preview.arcPreview),- seasons: preview.seasonsPreview || [],- };- const committed = await commitImport(payload, { silent: true }).catch((err) => {- if (err?.code === 'IMPORTER_PARTIAL_COMMIT_ISSUES' && err?.context?.arcAlreadyPersisted) {- setArcAlreadyPersisted(true);- toast.warning('Arc + seasons saved; issues failed and were rolled back. Click again to re-create the issues only — the arc won\'t be re-sent.');+ // Skip commitImport when a prior click already committed (only the later+ // createStorySession failed) — re-running it would duplicate the+ // already-created issues and overwrite the arc. Resume at session creation.+ if (!committed) {+ // On an arcAlreadyPersisted retry the server kept arc/seasons/canon from+ // the failed commit, so resend issues only — re-sending the full payload+ // would clobber the persisted state and risk duplicate issues.+ const base = { universeId: preview.universe.id, seriesId: preview.series.id, issues, contentType };+ const payload = arcAlreadyPersisted+ ? { ...base, canonSelections: { characters: [], places: [], objects: [] }, arc: null, seasons: [] }+ : {+ ...base,+ canonSelections: {+ characters: preview.canonPreview?.characters || [],+ places: preview.canonPreview?.places || [],+ objects: preview.canonPreview?.objects || [],+ },+ arc: pickArcFields(preview.arcPreview),+ seasons: preview.seasonsPreview || [],+ };+ const result = await commitImport(payload, { silent: true }).catch((err) => {+ if (err?.code === 'IMPORTER_PARTIAL_COMMIT_ISSUES' && err?.context?.arcAlreadyPersisted) {+ setArcAlreadyPersisted(true);+ toast.warning('Arc + seasons saved; issues failed and were rolled back. Click again to re-create the issues only — the arc won\'t be re-sent.');+ return null;+ }+ toast.error(err?.message || 'Import failed');return null;- }- toast.error(err?.message || 'Import failed');- return null;- });- if (!committed) { setCommitting(false); return; }- setArcAlreadyPersisted(false);+ });+ if (!result) { setCommitting(false); return; }+ setArcAlreadyPersisted(false);+ setCommitted(true);+ }const session = await createStorySession({intakeMode: 'import',title: seriesName.trim() || universeName.trim(),@@ -351,7 +362,7 @@ function ImportPanel({ onCreated }) {<button onClick={importAndBuild} disabled={committing || issueCount === 0}className="inline-flex items-center gap-2 bg-port-success hover:bg-green-600 disabled:opacity-50 text-white px-4 py-2 rounded text-sm">{committing ? <Loader2 className="w-4 h-4 animate-spin" /> : <Check className="w-4 h-4" />}- {arcAlreadyPersisted ? 'Retry issues & start building' : 'Import & start building'}+ {committed ? 'Retry starting the builder' : arcAlreadyPersisted ? 'Retry issues & start building' : 'Import & start building'}</button><button onClick={() => setPreview(null)} disabled={committing}className="text-sm text-gray-400 hover:text-white px-2">Re-analyze</button>diff --git a/client/src/pages/StoryBuilder.test.jsx b/client/src/pages/StoryBuilder.test.jsxindex af6a388a2a..600225b140 100644--- a/client/src/pages/StoryBuilder.test.jsx+++ b/client/src/pages/StoryBuilder.test.jsx@@ -221,6 +221,42 @@ describe('StoryBuilder — index', () => {);});+ it('import tab: a committed import whose session-create fails retries the session only, never re-committing', async () => {+ const { fireEvent } = await import('@testing-library/react');+ api.analyzeImport.mockResolvedValue({+ universe: { id: 'u9', name: 'Giant' }, series: { id: 's9' },+ canonPreview: { characters: [{ name: 'Kessa' }], places: [], objects: [] },+ arcPreview: { logline: 'A giant wakes.', summary: 'spine' },+ seasonsPreview: [{ number: 1, title: 'Vol 1' }],+ issueProposals: [{ title: 'Issue 1' }], issueSplitFailed: false,+ });+ // Commit succeeds on the first click; createStorySession then fails, leaving+ // the import committed but no session created.+ api.commitImport.mockResolvedValue({ universe: { id: 'u9' }, series: { id: 's9' }, createdIssueIds: ['iss-1'] });+ api.createStorySession.mockRejectedValueOnce(new Error('session create failed'));+ api.createStorySession.mockResolvedValueOnce({ id: 'stb-import', currentStep: 'idea' });++ renderAt('/story-builder');+ fireEvent.click(await screen.findByText('Import a finished work'));+ fireEvent.change(await screen.findByLabelText('Universe name'), { target: { value: 'Giant' } });+ fireEvent.change(screen.getByLabelText('Series name'), { target: { value: 'Giant' } });+ fireEvent.change(screen.getByLabelText(/Source text/), { target: { value: 'PAGE ONE...' } });+ fireEvent.click(screen.getByRole('button', { name: /^Analyze$/ }));+ await waitFor(() => expect(screen.getByText(/Extracted/)).toBeTruthy());++ // First click → commit succeeds, session fails, button flips to the+ // session-only retry label.+ fireEvent.click(screen.getByRole('button', { name: /Import & start building/ }));+ await waitFor(() => expect(api.createStorySession).toHaveBeenCalledTimes(1));+ await waitFor(() => expect(screen.getByRole('button', { name: /Retry starting the builder/ })).toBeTruthy());+ expect(api.commitImport).toHaveBeenCalledTimes(1);++ // Second click → commitImport is NOT re-run; only createStorySession retries.+ fireEvent.click(screen.getByRole('button', { name: /Retry starting the builder/ }));+ await waitFor(() => expect(api.createStorySession).toHaveBeenCalledTimes(2));+ expect(api.commitImport).toHaveBeenCalledTimes(1);+ });+it('import tab: blocks "Import & build" when no issues were extracted, offers retry', async () => {const { fireEvent } = await import('@testing-library/react');api.analyzeImport.mockResolvedValue({