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

address review (codex): compose severity saves from freshest state, refresh + revert health UI

[._.]/ Adam Eivy97b94f768e15
diff --git a/client/src/components/pipeline/editorial/SeriesSeverityConfig.jsx b/client/src/components/pipeline/editorial/SeriesSeverityConfig.jsx
index 82da257e30..29124477a0 100644
--- a/client/src/components/pipeline/editorial/SeriesSeverityConfig.jsx
+++ b/client/src/components/pipeline/editorial/SeriesSeverityConfig.jsx
@@ -2,7 +2,10 @@
* Per-series severity config panel (#1616) for the Editorial Checks page.
*
* Two per-series overrides, both saved through the parent's serialized silent
- * save tail (`onSaveField(field, value)`):
+ * save tail. The handler is `onSaveField(field, updater)` where `updater` is a
+ * pure `(currentStored) => nextStored` composed AT SAVE TIME against this series'
+ * freshest server-confirmed override — so two quick edits (or a toggle on the
+ * same gate) can't wholesale-clobber each other.
*
* - SEVERITY WEIGHTS — the health-score penalty weights (high/medium/low). The
* defaults are high:12 / medium:5 / low:1; an unset series shows the defaults.
@@ -53,7 +56,7 @@ function effectiveBlocking(override, gate) {
return DEFAULT_BLOCKING_SEVERITIES[gate];
}
-export default function SeriesSeverityConfig({ series, onSaveField, saving = false }) {
+export default function SeriesSeverityConfig({ series, onSaveField, saving = false, resetNonce = 0 }) {
const weightsOverride = series && typeof series.severityWeights === 'object' && series.severityWeights
? series.severityWeights : {};
const blockingOverride = series && typeof series.blockingSeverities === 'object' && series.blockingSeverities
@@ -61,9 +64,10 @@ export default function SeriesSeverityConfig({ series, onSaveField, saving = fal
// Draft state for the number inputs so typing doesn't fight the controlled
// value. Re-seeded from the persisted effective values whenever the series id
- // or its stored weights change (covers a failed-save revert too — the parent
- // leaves the series record untouched on failure, so the effective values are
- // still the persisted ones).
+ // or its stored weights change — AND whenever `resetNonce` bumps, which the
+ // parent does on a FAILED save (the series record is untouched on failure, so
+ // the props don't change and only the nonce can force the drafts back to the
+ // persisted values).
const seriesId = series?.id || '';
const [draft, setDraft] = useState({});
useEffect(() => {
@@ -72,44 +76,55 @@ export default function SeriesSeverityConfig({ series, onSaveField, saving = fal
medium: String(effectiveWeight(weightsOverride, 'medium')),
low: String(effectiveWeight(weightsOverride, 'low')),
});
- }, [seriesId, JSON.stringify(weightsOverride)]);
+ }, [seriesId, JSON.stringify(weightsOverride), resetNonce]);
if (!series) return null;
// Persist a single weight key. An empty/invalid input CLEARS the key (absent →
- // default); a valid number sets it. Built onto the STORED override so untouched
- // keys stay absent.
+ // default); a valid number sets it. The save composes onto the STORED override
+ // at execution time (untouched keys stay absent), so a second edit can't drop
+ // the first.
const commitWeight = (sev, rawText) => {
- const next = { ...weightsOverride };
const trimmed = (rawText ?? '').trim();
+ let clear = false;
+ let num = null;
if (trimmed === '') {
- delete next[sev];
+ clear = true;
} else {
- const num = Number(trimmed);
+ num = Number(trimmed);
if (!Number.isFinite(num) || num < 0) {
// Invalid → revert the draft to the persisted effective value, no save.
setDraft((d) => ({ ...d, [sev]: String(effectiveWeight(weightsOverride, sev)) }));
return;
}
- next[sev] = num;
}
- // No-op guard: if nothing actually changed vs the stored override, skip.
- if (JSON.stringify(next) === JSON.stringify(weightsOverride)) return;
- onSaveField('severityWeights', next);
+ // No-op guard vs the currently-displayed stored override (avoids a redundant
+ // PATCH when the committed value matches what's already persisted).
+ if (clear && !(sev in weightsOverride)) return;
+ if (!clear && weightsOverride[sev] === num) return;
+ onSaveField('severityWeights', (stored) => {
+ const next = { ...stored };
+ if (clear) delete next[sev];
+ else next[sev] = num;
+ return next;
+ });
};
- // Toggle one severity for one gate. Built onto the STORED override so an
- // untouched gate stays absent (tracks the default). An explicit empty array is
- // preserved (= nothing blocks this gate).
+ // Toggle one severity for one gate. The save FLIPS `sev` against the gate's
+ // freshest stored set (or its default when absent) at execution time — so an
+ // untouched gate stays absent (tracks the default) and rapid toggles compose
+ // instead of clobbering. An explicit empty array is preserved (= nothing
+ // blocks this gate).
const toggleBlocking = (gate, sev) => {
- const current = effectiveBlocking(blockingOverride, gate);
- const nextSet = current.includes(sev)
- ? current.filter((s) => s !== sev)
- : [...current, sev];
- // Order canonically (high → low) for a stable persisted shape.
- const ordered = SEVERITIES.filter((s) => nextSet.includes(s));
- const next = { ...blockingOverride, [gate]: ordered };
- onSaveField('blockingSeverities', next);
+ onSaveField('blockingSeverities', (stored) => {
+ const cur = Array.isArray(stored[gate])
+ ? stored[gate].filter((s) => SEVERITIES.includes(s))
+ : DEFAULT_BLOCKING_SEVERITIES[gate];
+ const nextSet = cur.includes(sev) ? cur.filter((s) => s !== sev) : [...cur, sev];
+ // Order canonically (high → low) for a stable persisted shape.
+ const ordered = SEVERITIES.filter((s) => nextSet.includes(s));
+ return { ...stored, [gate]: ordered };
+ });
};
return (
diff --git a/client/src/components/pipeline/editorial/SeriesSeverityConfig.test.jsx b/client/src/components/pipeline/editorial/SeriesSeverityConfig.test.jsx
index fbd01ff685..11277b8130 100644
--- a/client/src/components/pipeline/editorial/SeriesSeverityConfig.test.jsx
+++ b/client/src/components/pipeline/editorial/SeriesSeverityConfig.test.jsx
@@ -38,13 +38,21 @@ describe('SeriesSeverityConfig (#1616)', () => {
expect(document.getElementById('block-editorial-high').checked).toBe(false);
});
- it('saves a single weight key onto the stored override on blur', () => {
+ // onSaveField is called with (field, updater); the updater composes the next
+ // STORED override against the freshest stored value at save time. Pull it out
+ // and apply it to the stored override the parent would hold.
+ const lastUpdater = (field) => {
+ const call = [...onSaveField.mock.calls].reverse().find(([f]) => f === field);
+ return call ? call[1] : null;
+ };
+
+ it('saves a single weight key by composing onto the stored override on blur', () => {
render(<SeriesSeverityConfig series={series({ severityWeights: { low: 2 } })} onSaveField={onSaveField} />);
const high = weightInput('high');
fireEvent.change(high, { target: { value: '20' } });
fireEvent.blur(high);
- // merges onto the stored override (keeps low:2), doesn't send the merged defaults.
- expect(onSaveField).toHaveBeenCalledWith('severityWeights', { low: 2, high: 20 });
+ // Composes onto the stored override (keeps low:2) rather than sending merged defaults.
+ expect(lastUpdater('severityWeights')({ low: 2 })).toEqual({ low: 2, high: 20 });
});
it('clears a weight key when the input is emptied', () => {
@@ -52,20 +60,47 @@ describe('SeriesSeverityConfig (#1616)', () => {
const high = weightInput('high');
fireEvent.change(high, { target: { value: '' } });
fireEvent.blur(high);
- expect(onSaveField).toHaveBeenCalledWith('severityWeights', { low: 2 });
+ expect(lastUpdater('severityWeights')({ high: 20, low: 2 })).toEqual({ low: 2 });
+ });
+
+ it('does not save when the committed weight matches the stored value (no-op guard)', () => {
+ render(<SeriesSeverityConfig series={series({ severityWeights: { high: 20 } })} onSaveField={onSaveField} />);
+ const high = weightInput('high');
+ fireEvent.change(high, { target: { value: '20' } });
+ fireEvent.blur(high);
+ expect(onSaveField).not.toHaveBeenCalled();
});
- it('toggles a blocking severity, persisting an ordered array onto the stored override', () => {
+ it('toggles a blocking severity, composing an ordered array onto the freshest stored set', () => {
render(<SeriesSeverityConfig series={series()} onSaveField={onSaveField} />);
- // uncheck arc medium → arc becomes [high].
+ // uncheck arc medium → flip medium against the gate's default [high,medium] → [high].
fireEvent.click(document.getElementById('block-arc-medium'));
- expect(onSaveField).toHaveBeenCalledWith('blockingSeverities', { arc: ['high'] });
+ expect(lastUpdater('blockingSeverities')({})).toEqual({ arc: ['high'] });
+ });
+
+ it('composes a toggle against the freshest stored set, not the rendered props', () => {
+ render(<SeriesSeverityConfig series={series()} onSaveField={onSaveField} />);
+ // The user checks arc low; by save time another save has landed making arc [high].
+ fireEvent.click(document.getElementById('block-arc-low'));
+ // Flipping low onto the freshest stored arc:[high] yields [high, low] (ordered).
+ expect(lastUpdater('blockingSeverities')({ arc: ['high'] })).toEqual({ arc: ['high', 'low'] });
});
it('unchecking the last box persists an explicit empty array (nothing blocks)', () => {
render(<SeriesSeverityConfig series={series({ blockingSeverities: { editorial: ['high'] } })} onSaveField={onSaveField} />);
fireEvent.click(document.getElementById('block-editorial-high'));
- expect(onSaveField).toHaveBeenCalledWith('blockingSeverities', { editorial: [] });
+ expect(lastUpdater('blockingSeverities')({ editorial: ['high'] })).toEqual({ editorial: [] });
+ });
+
+ it('re-seeds the weight drafts when resetNonce bumps (failed-save revert)', () => {
+ const s = series({ severityWeights: { high: 20 } });
+ const { rerender } = render(<SeriesSeverityConfig series={s} onSaveField={onSaveField} resetNonce={0} />);
+ const high = weightInput('high');
+ fireEvent.change(high, { target: { value: '99' } });
+ expect(high).toHaveValue(99);
+ // Parent leaves the series untouched on failure and bumps the nonce.
+ rerender(<SeriesSeverityConfig series={s} onSaveField={onSaveField} resetNonce={1} />);
+ expect(high).toHaveValue(20);
});
it('renders nothing without a series', () => {
diff --git a/client/src/pages/PipelineEditorialChecks.jsx b/client/src/pages/PipelineEditorialChecks.jsx
index f4e8c462af..d342934d88 100644
--- a/client/src/pages/PipelineEditorialChecks.jsx
+++ b/client/src/pages/PipelineEditorialChecks.jsx
@@ -69,6 +69,9 @@ export default function PipelineEditorialChecks() {
// Per-check nonce bumped on a FAILED series-override save so the check card can
// revert its draft inputs to the persisted value (#1591).
const [seriesResetNonces, setSeriesResetNonces] = useState(() => ({}));
+ // Bumped on a FAILED severity-config save (#1616) so the severity-tuning panel
+ // re-seeds its number-input drafts from the persisted (untouched) values.
+ const [severityResetNonce, setSeverityResetNonce] = useState(0);
const seriesId = searchParams.get('series') || '';
const [comments, setComments] = useState([]);
// Canon entities (#1631) for the selected series' linked universe, flattened to
@@ -391,7 +394,19 @@ export default function PipelineEditorialChecks() {
? selectedSeries.editorialCheckConfig
: null;
+ // Per-series severity-config overrides (#1616) — the STORED (not effective)
+ // severityWeights/blockingSeverities, keyed by seriesId, so a queued save
+ // composes its edit onto THIS series' freshest server-confirmed values at
+ // execution time (mirrors overrideMapsRef). Without this, two quick edits each
+ // build a full wholesale-replacement from props captured at event time and the
+ // second clobbers the first.
+ const seriesSeverityWeights = selectedSeries?.severityWeights && typeof selectedSeries.severityWeights === 'object'
+ ? selectedSeries.severityWeights : null;
+ const seriesBlockingSeverities = selectedSeries?.blockingSeverities && typeof selectedSeries.blockingSeverities === 'object'
+ ? selectedSeries.blockingSeverities : null;
+
const overrideMapsRef = useRef({});
+ const severityFieldsRef = useRef({});
const seriesSaveTailRef = useRef(Promise.resolve());
// Seed/refresh ONLY the selected series' entry from its loaded record (covers
// the async series-list load AND a server-confirmed save echo). Keying by id
@@ -399,6 +414,12 @@ export default function PipelineEditorialChecks() {
useEffect(() => {
if (seriesId) overrideMapsRef.current[seriesId] = seriesOverrides ? { ...seriesOverrides } : {};
}, [seriesId, seriesOverrides]);
+ useEffect(() => {
+ if (seriesId) severityFieldsRef.current[seriesId] = {
+ severityWeights: seriesSeverityWeights ? { ...seriesSeverityWeights } : {},
+ blockingSeverities: seriesBlockingSeverities ? { ...seriesBlockingSeverities } : {},
+ };
+ }, [seriesId, seriesSeverityWeights, seriesBlockingSeverities]);
// `patch` is a PARTIAL per-check override ({ [key]: value }) to merge, or `null`
// to clear the whole check. Merging (rather than replacing the per-check entry)
@@ -441,18 +462,40 @@ export default function PipelineEditorialChecks() {
// (the panel reverts to the persisted value on failure since the series record
// is left untouched). Keyed in savingSeriesIds so the run buttons gate on the
// save landing (the autopilot reads the persisted series record).
- const handleSeriesFieldSave = useCallback((field, value) => {
+ // `updater(currentStored)` composes the next STORED override from this series'
+ // freshest server-confirmed value at execution time (not from props captured
+ // when the user clicked), so two quick edits can't wholesale-clobber each other.
+ const handleSeriesFieldSave = useCallback((field, updater) => {
const sid = activeSeriesRef.current;
if (!sid) return;
setSavingSeriesIds((s) => new Set(s).add(field));
seriesSaveTailRef.current = seriesSaveTailRef.current
.then(async () => {
- const saved = await updatePipelineSeries(sid, { [field]: value }, { silent: true })
- .catch((err) => { toast.error(err.message || 'Failed to save severity config'); return null; });
- // On success sync THIS series' record by id (keyed, never clobbers
- // another series); on failure leave it untouched so the panel keeps
- // showing — and reverts to — the persisted values.
- if (saved) setSeries((rows) => rows.map((r) => (r.id === saved.id ? saved : r)));
+ const store = severityFieldsRef.current[sid] || {};
+ const current = (store[field] && typeof store[field] === 'object') ? store[field] : {};
+ const nextValue = updater({ ...current });
+ const saved = await updatePipelineSeries(sid, { [field]: nextValue }, { silent: true })
+ .catch((err) => {
+ toast.error(err.message || 'Failed to save severity config');
+ // Failure: the series record is untouched, but the panel's number
+ // inputs may hold typed-but-unsaved drafts — bump the reset nonce so
+ // it re-seeds from the persisted values.
+ setSeverityResetNonce((n) => n + 1);
+ return null;
+ });
+ // On success sync THIS series' record + stored-override ref by id (keyed,
+ // never clobbers another series); on failure leave both untouched.
+ if (saved) {
+ severityFieldsRef.current[saved.id] = {
+ severityWeights: (saved.severityWeights && typeof saved.severityWeights === 'object') ? { ...saved.severityWeights } : {},
+ blockingSeverities: (saved.blockingSeverities && typeof saved.blockingSeverities === 'object') ? { ...saved.blockingSeverities } : {},
+ };
+ setSeries((rows) => rows.map((r) => (r.id === saved.id ? saved : r)));
+ // Weights change the health SCORE, so re-pull the panel's score/trend in
+ // lockstep (it only refetches on seriesId/refreshKey change). Blocking
+ // sets only gate the autopilot, not the score — no refresh needed.
+ if (field === 'severityWeights') setHealthRefresh((n) => n + 1);
+ }
})
.finally(() => setSavingSeriesIds((s) => { const n = new Set(s); n.delete(field); return n; }));
}, []);
@@ -663,6 +706,7 @@ export default function PipelineEditorialChecks() {
series={selectedSeries}
onSaveField={handleSeriesFieldSave}
saving={severitySaving}
+ resetNonce={severityResetNonce}
/>
) : null}