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 the Quota Burn page mounted during a refresh and report a failed re-scrape (#3931)

[._.]/ Adam Eivy1a7f114f05f1
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index a994640d20..46937604d7 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -71,3 +71,4 @@
- A failed first read on the Quota Burn page no longer strands you on a dead end. `load()` swallowed the error and left `config` null, and the unavailable branch returns before the header — so the only control that could re-read, "Refresh quota", was never rendered, and the one line on screen named neither the cause nor a way out short of reloading the browser tab. The read's failure is now kept in its own state (`null` = never failed, distinct from "the server answered and has no plan"), and the unavailable branch renders an error banner carrying that message with a Retry button that re-reads and clears it on success.
- Deleting a prompt variable now asks first. The 14px trash icon on each row in the Prompt Manager's Variables list fired `DELETE /api/prompts/variables/:key` on the first click, so a mis-click — easy on a touch screen or with tight cursor tracking — destroyed the variable and its template content with no warning and no undo. The trash button now arms an inline confirm row in place of that row ("Delete "Tone Guide"?" with Delete / Cancel), using the shared `useConfirmDelete` + `InlineConfirmRow` pattern, so only one row is armed at a time and cancelling leaves the variable untouched. The trash button's accessible name now also names the variable it deletes instead of the generic "Delete variable".
- Media-library sweeps from two or more full-sync peers no longer race on the same asset file. The in-flight pull guard is keyed by `(peer, kind, filename)` on purpose — a re-render pushed by one peer should still be able to overwrite an older copy another peer served — but that also meant two peers advertising the same filename, which is exactly what a mirrored library looks like, both passed the guard and downloaded and wrote `data/{images,videos,audio,music}/<name>` at the same time. Pulls now serialize on a queue keyed by the destination alone, so the later peer waits its turn rather than writing alongside the first, and the local file is re-checked against the advertised hash once the turn arrives: for every asset kind, not just images, matching bytes mean a hash instead of a second download. The all-peers sweep also picked up a global re-entrancy guard, since a sweep that outran the 60-second tick let the next tick start peer B while peer A was still mid-pull, and the derived `media_assets` reconcile now runs on a single tail with concurrent requests collapsed into one pass instead of stacking overlapping full-table rebuilds.
+- "Refresh quota" on the Quota Burn page no longer blanks the page or hides a failed re-scrape. The handler flipped the same `loading` flag as the first read, so every family card, control, and status number was replaced by a full-page "Loading burn plan…" spinner for the length of a 10–20s PTY quota scrape — and because the read's error was swallowed, a scrape that timed out simply put the stale numbers back with nothing saying they were stale. The refresh now reports itself on the button that asked for it (spinning icon, "Refreshing…", disabled) while the plan stays on screen, and a failure raises a toast naming the cause. The unavailable-state Retry button shares the same path; it stays banner-only there, since the banner already names the error.
diff --git a/client/src/pages/QuotaBurn.jsx b/client/src/pages/QuotaBurn.jsx
index 2d072d9b55..64eb717541 100644
--- a/client/src/pages/QuotaBurn.jsx
+++ b/client/src/pages/QuotaBurn.jsx
@@ -52,6 +52,9 @@ export default function QuotaBurn() {
const [status, setStatus] = useState(null);
const [catalog, setCatalog] = useState(EMPTY_CATALOG);
const [loading, setLoading] = useState(true);
+ // Distinct from `loading`: a manual re-read is reported ON the button that
+ // asked for it, never by replacing the page with a spinner.
+ const [refreshing, setRefreshing] = useState(false);
// `null` = the read has never failed; a string = the message from the read
// that did. Collapsing the two into a boolean (or into `!config`) is what
// left a failed first load indistinguishable from "the server answered, and
@@ -83,21 +86,32 @@ export default function QuotaBurn() {
const persistRef = useRef(null);
const savingRef = useRef(false);
+ // Resolves to `null` when the read landed, or to the failure message when it
+ // didn't. The banner state alone can't tell a caller whether THIS read failed
+ // (a poll may have set it earlier), and the manual refresh — which renders no
+ // banner, because the page still has its plan on screen — needs the cause to
+ // put in its toast.
const load = useCallback(async (refresh = false) => {
const seq = editSeqRef.current;
+ let failure = null;
// `silent: true` because the failure is rendered by this page's own banner
- // rather than a toast — see client/src/CLAUDE.md's silent-vs-toasting rule.
+ // or its refresh toast rather than the request helper's — see
+ // client/src/CLAUDE.md's silent-vs-toasting rule.
const data = await api.getQuotaBurn(refresh, { silent: true })
- .catch((err) => { setLoadError(err?.message || 'The request failed.'); return READ_FAILED; });
+ .catch((err) => {
+ failure = err?.message || 'The request failed.';
+ setLoadError(failure);
+ return READ_FAILED;
+ });
// The sentinel — not a falsy check — is what separates the two: a read that
// FAILED must keep its message, while a read that merely answered with
// nothing has to clear the previous failure, or the banner goes on blaming
// a network error for what is now the server returning no plan.
- if (data === READ_FAILED) return;
+ if (data === READ_FAILED) return failure;
// Cleared on ANY successful read, including the polls: the last error no
// longer describes the page once the server has answered.
setLoadError(null);
- if (!data) return;
+ if (!data) return null;
// `status` is derived server-side and never edited here, so it is always
// safe to adopt; `config` is the form's own state and must not be rewound.
setStatus(data.status);
@@ -109,6 +123,7 @@ export default function QuotaBurn() {
// it. Anything unsaved or in flight means the server's copy is stale by
// definition; don't adopt it.
if (editSeqRef.current === seq && !pendingRef.current && !savingRef.current) setConfig(data.config);
+ return null;
}, []);
useEffect(() => {
@@ -228,9 +243,19 @@ export default function QuotaBurn() {
setRunning(false);
};
- const reload = (refresh = false) => {
- setLoading(true);
- load(refresh).finally(() => setLoading(false));
+ // A re-read must NOT go back through `loading`: that unmounts every family
+ // card, control, and status number behind a full-page spinner for the length
+ // of a 10-20s PTY quota scrape, and then — if the scrape fails — puts the
+ // stale numbers back with nothing having said so. The button carries its own
+ // spinner and the page keeps rendering what it has.
+ const reload = async (refresh = false) => {
+ setRefreshing(true);
+ const failure = await load(refresh);
+ setRefreshing(false);
+ // With a plan on screen there is no banner, so the toast is the only thing
+ // that can report the failure; when there ISN'T one the banner already
+ // names it, and toasting too would say it twice.
+ if (failure && config) toast.error(`Failed to refresh quota stats: ${failure}`);
};
if (loading) return <div className="p-6 text-gray-400"><BrailleSpinner /> Loading burn plan…</div>;
@@ -247,10 +272,11 @@ export default function QuotaBurn() {
actions={(
<button
type="button"
- className="text-xs px-3 py-1.5 rounded border border-port-error/40 hover:bg-port-error/10"
+ className="text-xs px-3 py-1.5 rounded border border-port-error/40 hover:bg-port-error/10 disabled:opacity-40"
+ disabled={refreshing}
onClick={() => reload()}
>
- Retry
+ {refreshing ? 'Retrying…' : 'Retry'}
</button>
)}
>
@@ -279,10 +305,12 @@ export default function QuotaBurn() {
</span>
<button
type="button"
- className="inline-flex items-center gap-1 text-xs text-gray-300 hover:text-white"
+ className="inline-flex items-center gap-1 text-xs text-gray-300 hover:text-white disabled:opacity-40"
+ disabled={refreshing}
onClick={() => reload(true)}
>
- <RefreshCw size={13} /> Refresh quota
+ <RefreshCw size={13} className={refreshing ? 'animate-spin' : undefined} aria-hidden="true" />
+ {refreshing ? 'Refreshing…' : 'Refresh quota'}
</button>
<button
type="button"
diff --git a/client/src/pages/QuotaBurn.test.jsx b/client/src/pages/QuotaBurn.test.jsx
index e326be2c2a..11db0d19aa 100644
--- a/client/src/pages/QuotaBurn.test.jsx
+++ b/client/src/pages/QuotaBurn.test.jsx
@@ -13,6 +13,17 @@ vi.mock('../services/api', () => ({
rearmQuotaBurn: vi.fn(),
}));
+const toastError = vi.fn();
+vi.mock('../components/ui/Toast', () => {
+ // The page calls the default export BOTH as a function (neutral messages) and
+ // through `.success` / `.error`, so the mock has to be callable too.
+ const toast = (...a) => toast.message(...a);
+ toast.message = vi.fn();
+ toast.success = vi.fn();
+ toast.error = (...a) => toastError(...a);
+ return { default: toast };
+});
+
import * as api from '../services/api';
const config = {
@@ -471,6 +482,45 @@ describe('QuotaBurn save races', () => {
expect(screen.queryByText('Network request failed')).not.toBeInTheDocument();
});
+ it('keeps the plan on screen while Refresh quota re-reads, and names a refresh that failed', async () => {
+ // The refresh used to run through the same `loading` flag as the first read,
+ // so a 10-20s PTY quota scrape replaced every card and control with a
+ // full-page spinner — and a scrape that then FAILED put the stale numbers
+ // back with nothing saying they were stale.
+ const user = userEvent.setup();
+ let rejectRefresh;
+ api.getQuotaBurn.mockImplementationOnce(() => Promise.resolve({ config, status }));
+ api.getQuotaBurn.mockImplementationOnce(() => new Promise((_, reject) => { rejectRefresh = reject; }));
+ renderPage();
+
+ expect(await screen.findByText(/62% left/)).toBeInTheDocument();
+ await user.click(screen.getByRole('button', { name: /Refresh quota/ }));
+
+ // Mid-refresh: the button reports it, the page still shows the plan.
+ expect(await screen.findByRole('button', { name: /Refreshing…/ })).toBeDisabled();
+ expect(screen.getByText(/62% left/)).toBeInTheDocument();
+ expect(screen.queryByText(/Loading burn plan/)).not.toBeInTheDocument();
+
+ rejectRefresh(new Error('Quota scrape timed out'));
+ await waitFor(() => expect(toastError).toHaveBeenCalledWith('Failed to refresh quota stats: Quota scrape timed out'));
+ // The failure does not tear the page down, and the button is usable again.
+ expect(screen.getByText(/62% left/)).toBeInTheDocument();
+ expect(await screen.findByRole('button', { name: /Refresh quota/ })).toBeEnabled();
+ });
+
+ it('does not also toast when the failure is already named by the banner', async () => {
+ // With no plan on screen the banner owns the error surface — a toast on top
+ // of it would report the same failure twice.
+ const user = userEvent.setup();
+ api.getQuotaBurn.mockRejectedValueOnce(new Error('Network request failed'));
+ api.getQuotaBurn.mockRejectedValueOnce(new Error('Network request failed'));
+ renderPage();
+
+ await user.click(await screen.findByRole('button', { name: 'Retry' }));
+ await waitFor(() => expect(api.getQuotaBurn).toHaveBeenCalledTimes(2));
+ expect(toastError).not.toHaveBeenCalled();
+ });
+
it('still offers a retry when the server answers without a plan', async () => {
// No error to name — but the page is just as stuck, so the way out has to
// be the same one.