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-partial-commit]): retry issues-only after a partial import commit
[._.]/ Adam Eivyadf7e2c1908e
diff --git a/client/src/pages/StoryBuilder.jsx b/client/src/pages/StoryBuilder.jsxindex 20bfcb5701..0620fa91ea 100644--- a/client/src/pages/StoryBuilder.jsx+++ b/client/src/pages/StoryBuilder.jsx@@ -190,6 +190,11 @@ function ImportPanel({ onCreated }) {const [preview, setPreview] = useState(null);const [retrying, setRetrying] = useState(false);const [committing, setCommitting] = useState(false);+ // Set after a partial commit (universe/series/arc/canon persisted, issues+ // rolled back). The retry then drops arc + seasons + canon so it only+ // 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);const types = IMPORTER_CONTENT_TYPES || ['short-story', 'novel', 'screenplay', 'comic-script'];@@ -206,7 +211,7 @@ function ImportPanel({ onCreated }) {{ silent: true },).catch((err) => { toast.error(err?.message || 'Analyze failed'); return null; });setAnalyzing(false);- if (res) setPreview(res);+ if (res) { setPreview(res); setArcAlreadyPersisted(false); }};const retryIssues = async () => {@@ -227,20 +232,33 @@ 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);- const committed = await commitImport({- universeId: preview.universe.id,- seriesId: preview.series.id,- issues,- contentType,- canonSelections: {- characters: preview.canonPreview?.characters || [],- places: preview.canonPreview?.places || [],- objects: preview.canonPreview?.objects || [],- },- arc: pickArcFields(preview.arcPreview),- seasons: preview.seasonsPreview || [],- }, { silent: true }).catch((err) => { toast.error(err?.message || 'Import failed'); return null; });+ // 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.');+ return null;+ }+ toast.error(err?.message || 'Import failed');+ return null;+ });if (!committed) { setCommitting(false); return; }+ setArcAlreadyPersisted(false);const session = await createStorySession({intakeMode: 'import',title: seriesName.trim() || universeName.trim(),@@ -330,9 +348,9 @@ 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" />}- Import & start building+ {arcAlreadyPersisted ? 'Retry issues & start building' : 'Import & start building'}</button>- <button onClick={() => setPreview(null)} disabled={committing}+ <button onClick={() => { setPreview(null); setArcAlreadyPersisted(false); }} disabled={committing}className="text-sm text-gray-400 hover:text-white px-2">Re-analyze</button></div></div>diff --git a/client/src/pages/StoryBuilder.test.jsx b/client/src/pages/StoryBuilder.test.jsxindex c03ade01d6..af6a388a2a 100644--- a/client/src/pages/StoryBuilder.test.jsx+++ b/client/src/pages/StoryBuilder.test.jsx@@ -175,6 +175,52 @@ describe('StoryBuilder — index', () => {));});+ it('import tab: a partial commit (issues rolled back) retries issues-only without re-sending arc/canon', 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,+ });+ // First commit fails after persisting universe/series/arc/canon; the server+ // rolled the issues back and signals arcAlreadyPersisted.+ const partial = Object.assign(new Error('issues rolled back'), {+ code: 'IMPORTER_PARTIAL_COMMIT_ISSUES', context: { arcAlreadyPersisted: true },+ });+ api.commitImport.mockRejectedValueOnce(partial);+ api.commitImport.mockResolvedValueOnce({ universe: { id: 'u9' }, series: { id: 's9' }, createdIssueIds: ['iss-1'] });+ api.createStorySession.mockResolvedValue({ 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 → partial-commit warning, button flips to the issues-only retry label.+ fireEvent.click(screen.getByRole('button', { name: /Import & start building/ }));+ await waitFor(() => expect(toastMock.warning).toHaveBeenCalled());+ await waitFor(() => expect(screen.getByRole('button', { name: /Retry issues & start building/ })).toBeTruthy());+ // No session created from the failed commit.+ expect(api.createStorySession).not.toHaveBeenCalled();++ // Second click → retry drops arc + seasons + canon, re-sends issues only.+ fireEvent.click(screen.getByRole('button', { name: /Retry issues & start building/ }));+ await waitFor(() => expect(api.createStorySession).toHaveBeenCalled());+ expect(api.commitImport).toHaveBeenCalledTimes(2);+ expect(api.commitImport).toHaveBeenLastCalledWith(+ expect.objectContaining({+ universeId: 'u9', seriesId: 's9', issues: [{ title: 'Issue 1' }],+ arc: null, seasons: [], canonSelections: { characters: [], places: [], objects: [] },+ }),+ expect.objectContaining({ silent: true }),+ );+ });+it('import tab: blocks "Import & build" when no issues were extracted, offers retry', async () => {const { fireEvent } = await import('@testing-library/react');api.analyzeImport.mockResolvedValue({