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 an inline error instead of silently reverting a cleared Quota Burn number field (#3934)

[._.]/ Adam Eivy97b4bbebe3cf
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 55c0453c70..7c566d46e7 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -78,3 +78,4 @@
- A failed job-skill save in the Prompt Manager no longer looks like a successful one. `saveJobSkill` sent the PUT with `{ silent: true }` and an empty `.catch(() => {})`, so a network blip, an auth failure, or a 500 dropped the edit on the floor while the Save button simply re-enabled — the exact shape of a save that worked. The failure now raises a toast naming the cause, a successful save confirms itself ("Job skill saved"), and the Preview button on the same panel likewise reports a failed render instead of leaving the preview panel blank with no explanation.
- Saving a universe no longer issues one database read per canon entry. `projectToCatalog` — which runs synchronously inside `updateUniverse` to keep each catalog row in step with its embedded character/place/object entry — called `getIngredient` once per entry just to compare timestamps, so a universe with 50 canon items cost 50 single-row `SELECT`s before the first write, on the request the user is waiting on. The freshness lookup is now a single batched query (`getIngredientTimestamps`, `WHERE id = ANY($1)`, two columns rather than the whole jsonb row), with the loop-break guard applied before the batch so a guarded ingredient is never fetched at all. The LWW rule is unchanged (an entry at least as fresh as its row wins; an older one is skipped), missing rows still count as skipped instead of being confused with stale ones, and a per-entry write failure is still logged and skipped without aborting the rest of the pass.
- Unsaved Quota Burn edits are no longer lost silently when you navigate away. The page has no Save button — edits persist on a 500ms trailing edge — and the dismount flush that catches everything typed inside that window swallowed its own failure with `.catch(() => {})`, so leaving the page while the header still read "Saving changes…" dropped a pasted work prompt or a changed interval for good, with no toast and nothing on screen having said so. A failed flush now raises an error toast naming what happened and keeps the patch in tab-scoped `sessionStorage`; the next visit that successfully reads a plan replays it through the normal save path, so the edits come back on screen AND get re-sent to the server instead of waiting for the user to retype the field. A visit whose own read failed leaves the stash alone for the visit after it, and a stash that is not a patch object is ignored rather than replayed into a 400.
+- Clearing a Quota Burn number box no longer discards the edit without saying so. `NumberField` held an uncommitted draft so an empty box could not commit `Number('') === 0` into a 400, but on blur it simply dropped the draft and snapped the input back to the stored value — a user who cleared "Check every (minutes)" or "Reserve (%)" and clicked away saw the old number reappear with nothing on screen explaining why. An empty, non-numeric or out-of-range draft now stays on screen next to an inline error naming what the field accepts ("Must be between 5 and 720"), wired up with `aria-invalid`/`aria-describedby`; the error clears the moment the draft is committable again, and only a committable draft is released back to the stored value. Out-of-range numbers are also no longer committed mid-typing, so a 721-minute interval is caught in the field rather than by the server.
diff --git a/client/src/components/quotaBurn/fields.jsx b/client/src/components/quotaBurn/fields.jsx
index af29a9f7ae..abd9ef0572 100644
--- a/client/src/components/quotaBurn/fields.jsx
+++ b/client/src/components/quotaBurn/fields.jsx
@@ -12,6 +12,26 @@ import { useState } from 'react';
export const inputClass = 'w-full mt-1 bg-port-bg border border-port-border rounded p-2 text-white text-xs';
+/**
+ * Why a draft is invalid, or `null` when it is a committable number.
+ *
+ * Empty, non-numeric and out-of-range all get the SAME range sentence: the
+ * useful thing to tell someone who just cleared the box is what the field will
+ * accept, not that "" is not a number.
+ */
+export function numberFieldError(raw, { min, max } = {}) {
+ const text = typeof raw === 'string' ? raw.trim() : raw;
+ const parsed = text === '' || text === null || text === undefined ? NaN : Number(text);
+ const hasMin = Number.isFinite(min);
+ const hasMax = Number.isFinite(max);
+ const inRange = Number.isFinite(parsed) && (!hasMin || parsed >= min) && (!hasMax || parsed <= max);
+ if (inRange) return null;
+ if (hasMin && hasMax) return `Must be between ${min} and ${max}`;
+ if (hasMin) return `Must be ${min} or more`;
+ if (hasMax) return `Must be ${max} or less`;
+ return 'Must be a number';
+}
+
/**
* A labeled number input with an optional hint line beneath it.
*
@@ -21,11 +41,17 @@ export const inputClass = 'w-full mt-1 bg-port-bg border border-port-border roun
* -1 "unlimited" sentinel) — so a user who clears the box to retype it, and
* pauses past the save debounce, would 400 the request and take every other
* edit coalesced into that body down with it.
- * Committing only on a parseable number avoids the whole class. The draft is
- * released on blur so the field snaps back to whatever the server stored.
+ * Committing only on an in-range number avoids the whole class.
+ *
+ * The draft is released on blur ONLY when it committed. An empty or
+ * out-of-range draft is kept on screen next to an inline error instead —
+ * snapping silently back to the stored value reads as "my edit was eaten"
+ * with nothing on screen explaining why.
*/
export function NumberField({ id, label, value, onChange, min, max, hint }) {
const [draft, setDraft] = useState(null);
+ const [error, setError] = useState(null);
+ const errorId = `${id}-error`;
return (
<label htmlFor={id} className="block text-xs text-gray-400">
{label}
@@ -36,13 +62,25 @@ export function NumberField({ id, label, value, onChange, min, max, hint }) {
max={max}
className={inputClass}
value={draft ?? value}
+ aria-invalid={error ? 'true' : undefined}
+ aria-describedby={error ? errorId : undefined}
onChange={(event) => {
const raw = event.target.value;
setDraft(raw);
- if (raw !== '' && Number.isFinite(Number(raw))) onChange(Number(raw));
+ if (numberFieldError(raw, { min, max })) return;
+ // Clear a prior error as soon as the draft is committable again —
+ // waiting for blur would leave a stale complaint under a good value.
+ setError(null);
+ onChange(Number(raw));
+ }}
+ onBlur={() => {
+ if (draft === null) return;
+ const message = numberFieldError(draft, { min, max });
+ setError(message);
+ if (!message) setDraft(null);
}}
- onBlur={() => setDraft(null)}
/>
+ {error && <span id={errorId} role="alert" className="block mt-1 text-[11px] text-red-400">{error}</span>}
{hint && <span className="block mt-1 text-[11px] text-gray-500">{hint}</span>}
</label>
);
diff --git a/client/src/components/quotaBurn/fields.test.jsx b/client/src/components/quotaBurn/fields.test.jsx
new file mode 100644
index 0000000000..e27c2aa9f7
--- /dev/null
+++ b/client/src/components/quotaBurn/fields.test.jsx
@@ -0,0 +1,127 @@
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+
+// Coverage for the Quota Burn number field (#3934). The load-bearing behavior:
+// an empty or out-of-range draft must not commit (it would 400 the coalesced
+// save), and must not silently snap back to the stored value on blur either —
+// it stays on screen with an inline reason.
+
+import { NumberField, numberFieldError } from './fields';
+
+const setup = (props = {}) => {
+ const onChange = vi.fn();
+ render(
+ <NumberField
+ id="burn-interval"
+ label="Check every (minutes)"
+ value={15}
+ min={5}
+ max={720}
+ onChange={onChange}
+ {...props}
+ />
+ );
+ return { onChange, input: screen.getByLabelText(props.label ?? /Check every/) };
+};
+
+describe('numberFieldError', () => {
+ it('accepts an in-range number and both bounds', () => {
+ expect(numberFieldError('7', { min: 5, max: 720 })).toBeNull();
+ expect(numberFieldError('5', { min: 5, max: 720 })).toBeNull();
+ expect(numberFieldError('720', { min: 5, max: 720 })).toBeNull();
+ expect(numberFieldError('-1', { min: -1, max: 50 })).toBeNull();
+ });
+
+ it('rejects empty, blank and non-numeric drafts with the range sentence', () => {
+ expect(numberFieldError('', { min: 5, max: 720 })).toBe('Must be between 5 and 720');
+ expect(numberFieldError(' ', { min: 5, max: 720 })).toBe('Must be between 5 and 720');
+ expect(numberFieldError('abc', { min: 5, max: 720 })).toBe('Must be between 5 and 720');
+ expect(numberFieldError('-', { min: -1, max: 50 })).toBe('Must be between -1 and 50');
+ });
+
+ it('rejects out-of-range numbers', () => {
+ expect(numberFieldError('4', { min: 5, max: 720 })).toBe('Must be between 5 and 720');
+ expect(numberFieldError('721', { min: 5, max: 720 })).toBe('Must be between 5 and 720');
+ });
+
+ it('phrases a one-sided or absent bound', () => {
+ expect(numberFieldError('', { min: 5 })).toBe('Must be 5 or more');
+ expect(numberFieldError('', { max: 50 })).toBe('Must be 50 or less');
+ expect(numberFieldError('', {})).toBe('Must be a number');
+ expect(numberFieldError('9999', {})).toBeNull();
+ });
+});
+
+describe('NumberField', () => {
+ it('commits an in-range edit and keeps the box in sync with it', async () => {
+ const user = userEvent.setup();
+ const { onChange, input } = setup();
+ await user.clear(input);
+ await user.type(input, '30');
+ expect(onChange).toHaveBeenLastCalledWith(30);
+ expect(input).toHaveValue(30);
+ await user.tab();
+ expect(screen.queryByRole('alert')).toBeNull();
+ });
+
+ it('shows an inline error on blur of a cleared box instead of reverting', async () => {
+ const user = userEvent.setup();
+ const { onChange, input } = setup();
+ await user.clear(input);
+ await user.tab();
+ expect(screen.getByRole('alert')).toHaveTextContent('Must be between 5 and 720');
+ expect(input).toHaveValue(null);
+ expect(input).toHaveAttribute('aria-invalid', 'true');
+ expect(input).toHaveAttribute('aria-describedby', 'burn-interval-error');
+ expect(onChange).not.toHaveBeenCalled();
+ });
+
+ it('never commits an out-of-range number and flags it on blur', async () => {
+ const user = userEvent.setup();
+ const { onChange, input } = setup();
+ await user.clear(input);
+ await user.type(input, '3');
+ expect(onChange).not.toHaveBeenCalled();
+ await user.tab();
+ expect(screen.getByRole('alert')).toHaveTextContent('Must be between 5 and 720');
+ expect(input).toHaveValue(3);
+ });
+
+ it('clears the error as soon as the draft becomes committable again', async () => {
+ const user = userEvent.setup();
+ const { onChange, input } = setup();
+ await user.clear(input);
+ await user.tab();
+ expect(screen.getByRole('alert')).toBeInTheDocument();
+ await user.type(input, '45');
+ expect(screen.queryByRole('alert')).toBeNull();
+ expect(onChange).toHaveBeenLastCalledWith(45);
+ });
+
+ it('follows the stored value again once a good draft is released', async () => {
+ const user = userEvent.setup();
+ const onChange = vi.fn();
+ const { rerender } = render(
+ <NumberField id="burn-interval" label="Check every (minutes)" value={15} min={5} max={720} onChange={onChange} />
+ );
+ const input = screen.getByLabelText(/Check every/);
+ await user.clear(input);
+ await user.type(input, '60');
+ await user.tab();
+ rerender(
+ <NumberField id="burn-interval" label="Check every (minutes)" value={90} min={5} max={720} onChange={onChange} />
+ );
+ expect(input).toHaveValue(90);
+ });
+
+ it('accepts the -1 unlimited dispatch-cap sentinel', async () => {
+ const user = userEvent.setup();
+ const { onChange, input } = setup({ id: 'burn-cap', label: 'Dispatch cap per window', value: 5, min: -1, max: 50 });
+ await user.clear(input);
+ await user.type(input, '-1');
+ await user.tab();
+ expect(onChange).toHaveBeenLastCalledWith(-1);
+ expect(screen.queryByRole('alert')).toBeNull();
+ });
+});