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: surface a failed SongBook URL import inline with retry context (#3903)
[._.]/ Adam Eivy06b5ca416486
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 82c0df52ad..b4874cb05e 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -65,3 +65,4 @@- An AI generate or refine started in the Story Builder now survives clicking another step on the left rail. The step panel is keyed by the active step, so navigating away unmounted it — which tore down the SSE progress stream and threw away the completion handlers, leaving the run to finish on the server with no phase updates, no success or failure toast, and a stale view until a manual refresh. Each run's stream, phase and handlers now live in a provider mounted above the rail (`client/src/hooks/useStoryStepRuns.jsx`), one slot per step id, so runs on different steps can be in flight at once and the panel picks its own run back up — including which character a refine targets — when the user navigates back to it.- `docs/SELF_UPDATE.md` now documents that `update.sh` / `update.ps1` check out `main` before pulling, stashing a dirty working tree first so the checkout can proceed. The doc described only the `git pull --rebase --autostash`, so anyone running an in-app or CLI update from a feature branch or a detached HEAD was surprised to find their checkout moved to `main` with their work parked in `git stash` — the scripts print the restore commands on completion, but nothing said so up front.- The Vite dev server example in `docs/PM2.md` no longer tells you to point PM2 at `node_modules/.bin/vite`. PM2 resolves a relative `script` against its own working directory rather than the app's `cwd`, and the `.bin` entry itself varies by platform and package manager (symlink, `.cmd`/`.ps1` wrapper, generated shell script), none of which the Node interpreter launches uniformly — so a config copy-pasted from the doc crashed on startup. Both the standalone snippet and the complete monorepo example now use the absolute `path.join(__dirname, 'client', 'node_modules', 'vite', 'bin', 'vite.js')` form that PortOS's own `portos-ui` app has always used, with a note explaining why.+- A failed URL import in the SongBook importer no longer leaves the form looking untouched. The error had only a transient toast behind it, so once it faded the URL still sat in the input with no preview, no explanation, and a Save button that answered with the unrelated "Nothing to save — paste or fetch a tab first". The From URL tab now keeps an inline alert under the input naming the failure with a Retry button next to it, clears that alert as soon as the URL is edited, and drops any previously fetched draft (and the title/artist it auto-filled) so a failed fetch can't leave the earlier song previewed under a URL that never loaded. The disabled Save button now says why it's disabled instead of waiting for the click.diff --git a/client/src/pages/SongBookImport.jsx b/client/src/pages/SongBookImport.jsxindex 936843d13d..063d206a87 100644--- a/client/src/pages/SongBookImport.jsx+++ b/client/src/pages/SongBookImport.jsx@@ -17,7 +17,7 @@import { useEffect, useMemo, useRef, useState, useCallback } from 'react';import { toVoicingInstrument } from '../lib/chordShapes.js';import { useNavigate, Link } from 'react-router';-import { ListMusic, ArrowLeft, ClipboardPaste, Eraser, Wand2, Globe, FileText, Save } from 'lucide-react';+import { ListMusic, ArrowLeft, ClipboardPaste, Eraser, Wand2, Globe, FileText, Save, AlertTriangle, RotateCw } from 'lucide-react';import toast from '../components/ui/Toast';import PageHeader from '../components/PageHeader';import TabPills from '../components/ui/TabPills';@@ -59,6 +59,8 @@ const IMPORT_ERROR_MESSAGES = {SONG_IMPORT_EMPTY: 'No tab or chord content found on that page — try copy/pasting the tab instead.',};+const importErrorMessage = (err) => IMPORT_ERROR_MESSAGES[err?.code] || err?.message || 'Import failed';+const TABS = [{ id: 'paste', label: 'Paste', icon: FileText },{ id: 'url', label: 'From URL', icon: Globe },@@ -77,6 +79,9 @@ export default function SongBookImport() {// URL tab stateconst [url, setUrl] = useState('');const [fetched, setFetched] = useState(null); // server draft: { title, artist, content, sourceUrl }+ // null = no failure. A failed fetch keeps its message on screen (the toast is+ // transient) so the URL still sitting in the input has visible context.+ const [fetchError, setFetchError] = useState(null);// Shared draft formconst [title, setTitle] = useState('');@@ -117,11 +122,18 @@ export default function SongBookImport() {const normalizedUrl = normalizeUrl(url);if (!normalizedUrl || !isUrl(normalizedUrl)) { toast.error('Enter a valid URL'); return null; }const data = await importSongFromUrl(normalizedUrl, { silent: true }).catch((err) => {- toast.error(IMPORT_ERROR_MESSAGES[err?.code] || err?.message || 'Import failed');+ const message = importErrorMessage(err);+ toast.error(message);+ // Drop any earlier draft: leaving the previous song previewed under a+ // failed URL is exactly the stale-form confusion this guards against.+ setFetched(null);+ applyMetaDefaults({});+ setFetchError(message);return null;});const draft = data?.draft;if (!draft) return null;+ setFetchError(null);setFetched(draft);applyMetaDefaults(draft);return draft;@@ -162,6 +174,14 @@ export default function SongBookImport() {}, [tab, fetchedFormat, contentText, instrument]);const previewIsDrum = contentFormat === DRUM_FORMAT;+ // Why Save is disabled — otherwise a failed URL import surfaces only as the+ // unrelated "Nothing to save" toast once the user clicks.+ const saveHint = contentText.trim()+ ? null+ : (tab === 'url' && fetchError+ ? 'That URL import failed — retry it above, or switch to Paste and paste the tab.'+ : 'Paste or fetch a tab first — there\'s nothing to save yet.');+const [save, saving] = useAsyncAction(async () => {const name = title.trim();if (!name) { toast.error('Give the song a title'); return null; }@@ -251,7 +271,7 @@ export default function SongBookImport() {id="import-url"type="text"value={url}- onChange={(e) => setUrl(e.target.value)}+ onChange={(e) => { setUrl(e.target.value); setFetchError(null); }}placeholder="https://example.com/tabs/example-song"className={inputClass}/>@@ -265,6 +285,26 @@ export default function SongBookImport() {{fetching ? 'Fetching…' : 'Fetch'}</button></form>+ {fetchError && (+ <div+ role="alert"+ className="mt-2 flex flex-col sm:flex-row sm:items-center gap-2 rounded-lg border border-red-500/40 bg-red-500/10 px-3 py-2 text-xs text-red-300"+ >+ <AlertTriangle size={14} className="shrink-0" />+ <span className="flex-1">+ Import failed — {fetchError} Nothing was fetched, so there's nothing to save yet.+ </span>+ <button+ type="button"+ onClick={() => fetchUrl()}+ disabled={fetching || !isUrl(normalizeUrl(url) || '')}+ className={`${btnClass} shrink-0`}+ >+ <RotateCw size={13} />+ Retry+ </button>+ </div>+ )}{fetched && (<p className="text-xs text-gray-500 mt-2">Fetched <span className="text-gray-300">{fetched.title || 'untitled'}</span>@@ -325,7 +365,7 @@ export default function SongBookImport() {<label htmlFor="import-tags" className={labelClass}>Tags (comma-separated)</label><input id="import-tags" type="text" value={tags} onChange={(e) => setTags(e.target.value)} placeholder="e.g. campfire" className={inputClass} /></div>- <div className="sm:col-span-2 lg:col-span-5">+ <div className="sm:col-span-2 lg:col-span-5 flex flex-col sm:flex-row sm:items-center gap-2"><buttontype="submit"disabled={saving || !contentText.trim()}@@ -334,6 +374,7 @@ export default function SongBookImport() {<Save size={15} />{saving ? 'Saving…' : 'Save song'}</button>+ {saveHint && <span className="text-xs text-gray-400">{saveHint}</span>}</div></form></div>diff --git a/client/src/pages/SongBookImport.test.jsx b/client/src/pages/SongBookImport.test.jsxindex 3508520263..3d8729997a 100644--- a/client/src/pages/SongBookImport.test.jsx+++ b/client/src/pages/SongBookImport.test.jsx@@ -176,6 +176,63 @@ describe('SongBookImport', () => {});});+ describe('failed URL import (#3903)', () => {+ const fetchFailure = Object.assign(new Error('Bad gateway'), { code: 'SONG_IMPORT_FETCH_FAILED' });++ const failFetch = async (url = 'https://example.com/missing') => {+ renderPage();+ fireEvent.click(screen.getByRole('tab', { name: 'From URL' }));+ fireEvent.change(screen.getByLabelText('Tab / chord-sheet URL'), { target: { value: url } });+ fireEvent.click(screen.getByRole('button', { name: 'Fetch' }));+ return screen.findByRole('alert');+ };++ it('shows an inline alert with retry context and clears it when the URL changes', async () => {+ api.importSongFromUrl.mockRejectedValue(fetchFailure);+ const alert = await failFetch();+ expect(alert.textContent).toContain('Couldn\'t fetch that page');+ // The URL stays put so Retry is meaningful.+ expect(screen.getByLabelText('Tab / chord-sheet URL').value).toBe('https://example.com/missing');+ expect(screen.getByRole('button', { name: 'Retry' })).toBeTruthy();+ // Save explains ITSELF rather than waiting for the unrelated click-time toast.+ expect(screen.getByRole('button', { name: 'Save song' }).disabled).toBe(true);+ expect(screen.getByText(/That URL import failed/)).toBeTruthy();++ fireEvent.change(screen.getByLabelText('Tab / chord-sheet URL'), { target: { value: 'https://example.com/other' } });+ await waitFor(() => expect(screen.queryByRole('alert')).toBeNull());+ });++ it('Retry re-runs the import and a success clears the alert', async () => {+ api.importSongFromUrl.mockRejectedValueOnce(fetchFailure).mockResolvedValueOnce({+ draft: { title: 'Recovered Song', artist: '', content: { format: 'tab', text: 'C G' }, sourceUrl: 'https://example.com/missing' },+ });+ await failFetch();+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }));+ await waitFor(() => expect(screen.queryByRole('alert')).toBeNull());+ expect(api.importSongFromUrl).toHaveBeenCalledTimes(2);+ await waitFor(() => expect(screen.getByLabelText('Title').value).toBe('Recovered Song'));+ });++ it('drops the previous draft so a failed fetch never leaves a stale preview or auto-fill', async () => {+ api.importSongFromUrl.mockResolvedValueOnce({+ draft: { title: 'First Fetch', artist: '', content: { format: 'tab', text: 'C G Am' }, sourceUrl: 'https://example.com/a' },+ }).mockRejectedValueOnce(fetchFailure);+ renderPage();+ fireEvent.click(screen.getByRole('tab', { name: 'From URL' }));+ const input = screen.getByLabelText('Tab / chord-sheet URL');+ fireEvent.change(input, { target: { value: 'https://example.com/a' } });+ fireEvent.click(screen.getByRole('button', { name: 'Fetch' }));+ await waitFor(() => expect(screen.getByLabelText('Title').value).toBe('First Fetch'));++ fireEvent.change(input, { target: { value: 'https://example.com/b' } });+ fireEvent.click(screen.getByRole('button', { name: 'Fetch' }));+ await screen.findByRole('alert');+ expect(screen.queryByText('Preview')).toBeNull();+ // The stale auto-fill goes with the draft — it must not save onto a later import.+ expect(screen.getByLabelText('Title').value).toBe('');+ });+ });+it('sends an in-range pasted capo through unchanged', async () => {renderPage();fireEvent.change(screen.getByLabelText('Pasted tab content'), {