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: show a retryable error banner when the SongBook list fails to load (#3899)

[._.]/ Adam Eivyeb91063dc5d3
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index c4f07cd8d7..84f4f1a87a 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -35,6 +35,7 @@
- An Antigravity (agy) run that hits the account's subscription quota is now recognized as a spent quota instead of being recorded as a success. When the quota is gone agy paints `⚠ Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 3h51m14s.` where the answer would have been, and then goes silent — so the run's output-idle fallback finished it as a *successful* run whose "response" was the repainted prompt screen. Downstream that is worse than a failure: a Series Autopilot foundation-judge call read the JSON example out of its own echoed instructions, and the run died reporting "foundation judge response parsed but its rubric is incomplete or contains placeholders" — a manuscript problem, for what was purely an exhausted provider quota. Both attempts burned on the same dead provider, because nothing had marked it unavailable. PortOS now fails such a run the moment the banner appears, benches agy until its quota frees up, and lets the call retry on a fallback provider. CoS agent runs classify the same banner as a usage limit rather than an unknown error, so they stop re-picking the spent provider too.
- Two CoS agents running without a worktree can no longer steal each other's completion. Agents whose task needs no code change (the issue-filing and reasoning types) all run in the primary checkout, and every one of them wrote its done-signal to the same `.agent-done` file — so with two running at once the second overwrote the first's summary, and each run's 2-second poll finalized on whichever sentinel happened to be there, attributing one agent's result to the other and killing a session that was still working. The sentinel is now named per agent instance (`.agent-done-<agentId>`), resolved from one helper by every side that touches it — the path written into the agent's prompt, the 2-second poll, the durable runner's watch, the CLI exit check, the structured-payload read, and the worktree-cleanup ignore — so a run reads, cleans up, and reports only its own. A Layered Intelligence reasoning run, where that file *is* the deliverable, was also being handed two different filenames in one prompt; its instructions now defer to the sentinel path the briefing gives it. The one behaviour to know about on upgrade: an agent still mid-run when the server restarts was told the old shared name, so it finalizes through its normal idle/exit path rather than the sentinel poll.
+- The SongBook index no longer shows "No songs yet" when the song list fails to load. A network blip or server error left the page in the same state as an empty repertoire, so the page read as "your songs are gone" with no hint that a fetch had failed. The list is now `null` until it is actually fetched, and a failed load renders a retryable error banner naming the failure instead of the teaching empty state.
## Changed
diff --git a/client/src/pages/SongBook.jsx b/client/src/pages/SongBook.jsx
index cc842e8c78..ea39c9c274 100644
--- a/client/src/pages/SongBook.jsx
+++ b/client/src/pages/SongBook.jsx
@@ -13,10 +13,11 @@
import { useEffect, useMemo, useState, useCallback } from 'react';
import { useNavigate, useSearchParams, Link } from 'react-router';
-import { ListMusic, Plus, Trash2, Download, Search, X } from 'lucide-react';
+import { ListMusic, Plus, Trash2, Download, Search, X, AlertTriangle } from 'lucide-react';
import toast from '../components/ui/Toast';
import PageHeader from '../components/PageHeader';
import EmptyState from '../components/EmptyState';
+import Banner from '../components/ui/Banner';
import ConfirmButtonPair from '../components/ui/ConfirmButtonPair';
import { timeAgo } from '../utils/formatters';
import { useAsyncAction } from '../hooks/useAsyncAction';
@@ -43,17 +44,36 @@ export default function SongBook() {
}, { replace: true });
}, [setSearchParams]);
- const [songs, setSongs] = useState([]);
+ // null = not fetched (or the fetch failed), [] = fetched-and-empty. A failed
+ // load must NOT collapse into the same state as an empty repertoire, or the
+ // page tells the user their songs are gone (issue #3899).
+ const [songs, setSongs] = useState(null);
const [loading, setLoading] = useState(true);
+ const [loadError, setLoadError] = useState(null);
+ // Bump to re-run the load effect (the Retry button on the error banner).
+ const [retryKey, setRetryKey] = useState(0);
const [title, setTitle] = useState('');
const { isConfirming, requestDelete, cancelDelete, confirmDelete } = useConfirmDelete();
useEffect(() => {
+ let cancelled = false;
+ setLoading(true);
+ setLoadError(null);
+ // The banner below owns the error UI, so the request stays silent — one
+ // error layer only (client/src/CLAUDE.md "custom catch ⇒ silent: true").
listSongs({ silent: true })
- .then((data) => setSongs(Array.isArray(data?.songs) ? data.songs : []))
- .catch((err) => toast.error(err?.message || 'Failed to load songs'))
- .finally(() => setLoading(false));
- }, []);
+ .then((data) => {
+ if (cancelled) return;
+ setSongs(Array.isArray(data?.songs) ? data.songs : []);
+ })
+ .catch((err) => {
+ if (cancelled) return;
+ setSongs(null);
+ setLoadError(err?.message || 'Failed to load songs');
+ })
+ .finally(() => { if (!cancelled) setLoading(false); });
+ return () => { cancelled = true; };
+ }, [retryKey]);
const [create, creating] = useAsyncAction(async () => {
const name = title.trim();
@@ -66,7 +86,7 @@ export default function SongBook() {
const onDelete = useCallback((song) => confirmDelete(() =>
deleteSong(song.id, { silent: true })
- .then(() => setSongs((prev) => prev.filter((s) => s.id !== song.id)))
+ .then(() => setSongs((prev) => (prev || []).filter((s) => s.id !== song.id)))
.catch((err) => toast.error(err?.message || 'Failed to delete song')),
), [confirmDelete]);
@@ -75,13 +95,13 @@ export default function SongBook() {
// helper owns the error toast (single layer).
const onStageChange = useCallback((id, stage) => {
updateSong(id, { stage })
- .then((updated) => setSongs((prev) => prev.map((s) => (s.id === id ? { ...s, ...updated } : s))))
+ .then((updated) => setSongs((prev) => (prev || []).map((s) => (s.id === id ? { ...s, ...updated } : s))))
.catch(() => {});
}, []);
const filtered = useMemo(() => {
const needle = q.trim().toLowerCase();
- return songs.filter((s) => {
+ return (songs || []).filter((s) => {
if (stageFilter && s.stage !== stageFilter) return false;
if (instrumentFilter && s.instrument !== instrumentFilter) return false;
if (tagFilter && !(Array.isArray(s.tags) && s.tags.includes(tagFilter))) return false;
@@ -183,8 +203,26 @@ export default function SongBook() {
{/* Grid */}
{loading ? (
<p className="text-sm text-gray-500">Loading songs…</p>
+ ) : loadError ? (
+ <Banner
+ tone="error"
+ size="md"
+ icon={AlertTriangle}
+ title="Couldn't load your songs"
+ actions={(
+ <button
+ type="button"
+ onClick={() => setRetryKey((k) => k + 1)}
+ className="px-3 py-1.5 rounded-lg text-xs bg-port-error/20 hover:bg-port-error/30 text-port-error"
+ >
+ Retry
+ </button>
+ )}
+ >
+ {loadError} — your repertoire is still there; this is a fetch failure, not an empty SongBook.
+ </Banner>
) : filtered.length === 0 ? (
- songs.length === 0 ? (
+ songs?.length === 0 ? (
<EmptyState
icon={ListMusic}
title="No songs yet"
diff --git a/client/src/pages/SongBook.test.jsx b/client/src/pages/SongBook.test.jsx
index 5d1d26b030..ff52bb2395 100644
--- a/client/src/pages/SongBook.test.jsx
+++ b/client/src/pages/SongBook.test.jsx
@@ -10,7 +10,8 @@ const api = vi.hoisted(() => ({
updateSong: vi.fn(),
}));
vi.mock('../services/api', () => api);
-vi.mock('../components/ui/Toast', () => ({ default: { error: vi.fn(), success: vi.fn() } }));
+const toast = vi.hoisted(() => ({ error: vi.fn(), success: vi.fn() }));
+vi.mock('../components/ui/Toast', () => ({ default: toast }));
import SongBook from './SongBook.jsx';
@@ -46,6 +47,8 @@ describe('SongBook index', () => {
api.updateSong.mockReset();
api.deleteSong.mockReset();
api.createSong.mockReset();
+ toast.error.mockReset();
+ toast.success.mockReset();
});
it('renders the loaded songs', async () => {
@@ -91,4 +94,31 @@ describe('SongBook index', () => {
expect(await screen.findByText('No songs yet')).toBeTruthy();
expect(screen.getByText('Import a song')).toBeTruthy();
});
+
+ // A failed fetch must not collapse into the fetched-and-empty state (#3899).
+ it('renders a retryable error banner instead of the empty state when the load fails', async () => {
+ api.listSongs.mockRejectedValue(new Error('Network down'));
+ renderPage();
+ expect(await screen.findByText("Couldn't load your songs")).toBeTruthy();
+ expect(screen.queryByText('No songs yet')).toBeNull();
+ expect(screen.getByRole('button', { name: 'Retry' })).toBeTruthy();
+ });
+
+ it('re-fetches and clears the error banner when Retry is clicked', async () => {
+ api.listSongs.mockRejectedValueOnce(new Error('Network down'))
+ .mockResolvedValueOnce({ songs: [song('s1', 'Example Song')] });
+ renderPage();
+ fireEvent.click(await screen.findByRole('button', { name: 'Retry' }));
+ expect(await screen.findByText('Example Song')).toBeTruthy();
+ await waitFor(() => expect(screen.queryByText("Couldn't load your songs")).toBeNull());
+ expect(api.listSongs).toHaveBeenCalledTimes(2);
+ });
+
+ it('does not double-toast on a failed load — the banner owns the error UI', async () => {
+ api.listSongs.mockRejectedValue(new Error('Network down'));
+ renderPage();
+ await screen.findByText("Couldn't load your songs");
+ expect(api.listSongs).toHaveBeenCalledWith({ silent: true });
+ expect(toast.error).not.toHaveBeenCalled();
+ });
});