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 quota read on an already-loaded Quota Burn page (#3979)
[._.]/ Adam Eivy7f2250dc27aa
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 3a0ccc079c..72aa37d640 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -82,3 +82,4 @@- Applying an inbound catalog sync envelope no longer writes each legacy-tagged ingredient twice. The friendlify-on-sync repair — which rewrites an older peer's raw `from-universe` / `universe:<id>` tags to the friendly universe name — ran as a follow-up `updateIngredient` after `upsertIngredientFromPeer` had already written the row, so an envelope carrying N such ingredients cost 2N queries and left a redundant `catalog_ingredient_revisions` entry for every one of them. The rewrite now happens on the row before it is upserted, so it lands cleaned in a single write with no extra revision history. Behavior is otherwise unchanged: the universe name map is still built lazily and only once per apply, a row whose universe is not resolvable locally still lands with its machine tags intact for a later pass, an LWW skip still touches nothing, and a failure to build the map is isolated per row (reported as `ingredient-prepare`) with the raw row still applied. The friendly universe name — minted locally rather than carried by the peer — is still registered in the canonical tag taxonomy so autocomplete can suggest it, but now only for the label the rewrite adds, once per apply, instead of re-normalizing every row's whole tag array.- Unsaved job-skill edits in the Prompt Manager are no longer thrown away when you click another skill. Selecting a skill replaced the Markdown editor's contents outright, so a half-written template vanished with no warning and no undo the moment the user reached for a neighbouring skill in the sidebar list. The editor now tracks the last server-confirmed text (a full copy, not a flag, so typing an edit and undoing it back to the original stops counting as dirty) and marks itself with an "Unsaved changes" note in the header and an "Unsaved" badge on the list row. Clicking a different skill while dirty parks that click and takes over its list slot with an inline confirm row — "Discard unsaved changes to …?" with Discard / Keep editing — so cancelling leaves the selection, the URL, and the typed text untouched, and the next skill is only fetched once the discard is confirmed. Saving snapshots exactly what was sent — and which skill it was sent for — as the new clean baseline, so a save that lands after the user has already moved on cannot mark the freshly loaded skill dirty; a preview that resolves late is dropped for the same reason rather than rendered under the wrong skill's heading.- Saving an ingredient no longer issues one or two database queries per tag. `normalizeTags` mapped each raw label to its canonical `catalog_tags` row inside a `for` loop — an `INSERT … ON CONFLICT DO NOTHING RETURNING label` per label, plus a follow-up `SELECT` whenever the row already existed, which is the common case — so an ingredient carrying M tags cost between M and 2M round-trips on every create, every tag-touching update, and every committed scrap. The whole list is now resolved in at most two statements: one `SELECT id, label … WHERE id = ANY($1)` to read every pre-existing row, then a single multi-row insert for whatever is missing, skipped entirely when nothing is. The canonical rules are unchanged — blank tags dropped, casing/whitespace variants collapsed to one row, order of first appearance preserved, and a stored label still beating the incoming casing (`Noir` wins over a later `NOIR`) — and passing `{ client }` still runs both statements on the caller's transaction.+- A failed quota read on an already-loaded Quota Burn page now says so. Once a plan was on screen, a "Refresh quota" that never landed — or a background poll for a still-pending provider scrape — left the numbers exactly as they were, so a read that failed was indistinguishable from one that came back unchanged. Any failed read now raises a warning banner above the page header naming the cause, with its own Retry button, and clears itself on the next successful read (including the poll's). The banner is the page's single error surface: the manual refresh no longer toasts the same failure on top of it, and the stale plan stays rendered throughout rather than being blanked.diff --git a/client/src/pages/QuotaBurn.jsx b/client/src/pages/QuotaBurn.jsxindex 836687c82f..b9c1f0b5c4 100644--- a/client/src/pages/QuotaBurn.jsx+++ b/client/src/pages/QuotaBurn.jsx@@ -132,32 +132,28 @@ export default function QuotaBurn() {const saveRef = useRef(null);const hasConfigRef = 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.+ // Every failure — first load, manual refresh, or a background poll — is+ // reported by `loadError` and rendered as this page's ONE banner, so the+ // caller doesn't need the cause back.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- // or its refresh toast rather than the request helper's — see- // client/src/CLAUDE.md's silent-vs-toasting rule.+ // rather than the request helper's toast — see client/src/CLAUDE.md's+ // silent-vs-toasting rule.const data = await api.getQuotaBurn(refresh, { silent: true }).catch((err) => {- failure = err?.message || 'The request failed.';- setLoadError(failure);+ setLoadError(err?.message || 'The request failed.');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 failure;+ if (data === READ_FAILED) return;// 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 null;+ if (!data) return;// `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);@@ -173,7 +169,6 @@ 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;}, []);// The catalog is the page's second read and fails independently of the plan:@@ -361,12 +356,11 @@ export default function QuotaBurn() {// spinner and the page keeps rendering what it has.const refreshQuota = async (hard = false) => {setRefreshing(true);- const failure = await load(hard);+ await load(hard);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}`);+ // No toast: `loadError` is rendered as a banner in BOTH branches below, so+ // a toast on top of it would report the same failure twice — and a toast+ // fades while a poll that keeps failing deserves a standing indicator.};if (loading) return <div className="p-6 text-gray-400"><BrailleSpinner /> Loading burn plan…</div>;@@ -401,6 +395,32 @@ export default function QuotaBurn() {return (<div className="space-y-4">+ {/* A refresh or a poll that failed with a plan already on screen used to+ change nothing at all — the numbers stayed put and a read that never+ landed looked exactly like one that landed unchanged. `warning`, not+ `error`: the plan below is still rendered and still usable, and this+ clears itself on the next successful read (including a poll), so a+ transient blip should not read as a page-blocking failure. */}+ {loadError && (+ <Banner+ tone="warning"+ icon={AlertTriangle}+ role="status"+ aria-live="polite"+ actions={(+ <button+ type="button"+ className="text-xs px-3 py-1.5 rounded border border-port-warning/40 hover:bg-port-warning/10 disabled:opacity-40"+ disabled={refreshing}+ onClick={() => refreshQuota()}+ >+ {refreshing ? 'Retrying…' : 'Retry'}+ </button>+ )}+ >+ <p className="break-words">Quota stats could not be refreshed — showing the last values read. {loadError}</p>+ </Banner>+ )}<header className="flex flex-wrap items-center gap-3"><h1 className="text-xl font-semibold text-white flex items-center gap-2"><Flame size={20} className="text-orange-400" /> Quota Burn</h1>{/* There is no Save button on this page, and nothing else said so — thediff --git a/client/src/pages/QuotaBurn.test.jsx b/client/src/pages/QuotaBurn.test.jsxindex 2044f5243a..19ca6a6548 100644--- a/client/src/pages/QuotaBurn.test.jsx+++ b/client/src/pages/QuotaBurn.test.jsx@@ -637,12 +637,56 @@ describe('QuotaBurn save races', () => {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 banner names the cause — and it is the ONLY surface that reports it,+ // so the same failure is never announced twice.+ expect(await screen.findByText(/Quota scrape timed out/)).toBeInTheDocument();+ expect(toastError).not.toHaveBeenCalled();// 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('clears the failed-refresh banner on the next successful read', async () => {+ const user = userEvent.setup();+ api.getQuotaBurn.mockResolvedValueOnce({ config, status });+ api.getQuotaBurn.mockRejectedValueOnce(new Error('Quota scrape timed out'));+ renderPage();++ expect(await screen.findByText(/62% left/)).toBeInTheDocument();+ await user.click(screen.getByRole('button', { name: /Refresh quota/ }));+ expect(await screen.findByText(/Quota scrape timed out/)).toBeInTheDocument();++ // The banner's own Retry re-reads; the success takes the banner away and+ // leaves the plan exactly where it was.+ await user.click(screen.getByRole('button', { name: 'Retry' }));+ await waitFor(() => expect(screen.queryByText(/Quota scrape timed out/)).not.toBeInTheDocument());+ expect(screen.getByText(/62% left/)).toBeInTheDocument();+ });++ it('surfaces a background poll that failed, and clears it on the next poll that lands', async () => {+ // A poll failure is the one read nobody asked for — with nothing on screen+ // changing, a stalled scrape looked identical to one that kept answering+ // with the same numbers.+ const pendingStatus = {+ ...status,+ families: [{ ...status.families[0], pending: true }, status.families[1]],+ };+ api.getQuotaBurn.mockResolvedValueOnce({ config, status: pendingStatus });+ api.getQuotaBurn.mockRejectedValueOnce(new Error('Provider CLI is not responding'));+ renderPage();++ expect(await screen.findByText(/reading quota…/)).toBeInTheDocument();+ expect(await screen.findByText(/Provider CLI is not responding/, undefined, { timeout: 8000 })).toBeInTheDocument();+ // The plan stays on screen: a failed poll must not blank it.+ expect(screen.getByLabelText(/Run the quota-burn loop automatically/)).toBeInTheDocument();++ // The default mock resolves, so the following poll clears the banner and+ // fills the reading in.+ expect(await screen.findByText(/62% left/, undefined, { timeout: 8000 })).toBeInTheDocument();+ expect(screen.queryByText(/Provider CLI is not responding/)).not.toBeInTheDocument();+ // Two 4s poll intervals have to elapse, so the default 5s cap is too tight.+ }, 20000);+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.