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 r2): additive-field sync preservation, create schema, failed-save reset

Adam Eivy54e625ed0cae
diff --git a/client/src/components/pipeline/editorial/EditorialCheckCard.jsx b/client/src/components/pipeline/editorial/EditorialCheckCard.jsx
index 3e764fee0e..c2b0601c08 100644
--- a/client/src/components/pipeline/editorial/EditorialCheckCard.jsx
+++ b/client/src/components/pipeline/editorial/EditorialCheckCard.jsx
@@ -26,11 +26,14 @@ const SEVERITY_BADGE = {
low: 'bg-gray-500/15 text-gray-300',
};
-function ConfigField({ checkId, field, value, disabled, onCommit }) {
+function ConfigField({ checkId, field, value, disabled, onCommit, resetNonce = 0 }) {
const inputId = `cfg-${checkId}-${field.key}`;
const [draft, setDraft] = useState(value);
- // Re-seed when the committed value changes underneath us (e.g. save resolved).
- useEffect(() => { setDraft(value); }, [value]);
+ // Re-seed when the committed value changes underneath us (e.g. save resolved),
+ // OR when `resetNonce` bumps — used to revert the draft to the persisted value
+ // after a failed save, so the input never lingers on an unsaved threshold the
+ // runner won't use.
+ useEffect(() => { setDraft(value); }, [value, resetNonce]);
if (field.type === 'boolean') {
return (
@@ -82,7 +85,7 @@ function ConfigField({ checkId, field, value, disabled, onCommit }) {
function EditorialCheckCard({
check, saving = false, onToggle, onConfigSave, onEdit, onDelete,
- seriesId = '', seriesConfig = null, seriesSaving = false, onSeriesConfigSave,
+ seriesId = '', seriesConfig = null, seriesSaving = false, seriesResetNonce = 0, onSeriesConfigSave,
}) {
const [expanded, setExpanded] = useState(false);
const [seriesExpanded, setSeriesExpanded] = useState(false);
@@ -183,6 +186,7 @@ function EditorialCheckCard({
field={field}
value={seriesConfig?.[field.key] ?? check.config?.[field.key]}
disabled={seriesSaving}
+ resetNonce={seriesResetNonce}
onCommit={(key, val) => onSeriesConfigSave(check.id, { ...(seriesConfig || {}), [key]: val })}
/>
))}
diff --git a/client/src/components/pipeline/editorial/EditorialCheckCard.test.jsx b/client/src/components/pipeline/editorial/EditorialCheckCard.test.jsx
index 0fce58d7cd..f30de5c4c5 100644
--- a/client/src/components/pipeline/editorial/EditorialCheckCard.test.jsx
+++ b/client/src/components/pipeline/editorial/EditorialCheckCard.test.jsx
@@ -69,6 +69,37 @@ describe('EditorialCheckCard', () => {
expect(onSeriesConfigSave).toHaveBeenCalledWith('naming.dissimilar-names', { minSharedSignals: 4 });
});
+ it('reverts the draft to the persisted value when seriesResetNonce bumps (failed save)', () => {
+ const { rerender } = render(
+ <EditorialCheckCard
+ check={check}
+ seriesId="ser-1"
+ seriesConfig={null}
+ seriesResetNonce={0}
+ onToggle={vi.fn()}
+ onConfigSave={vi.fn()}
+ onSeriesConfigSave={vi.fn()}
+ />,
+ );
+ fireEvent.click(screen.getByRole('button', { name: /override for this series/i }));
+ const input = screen.getByLabelText('Minimum shared signals to flag');
+ fireEvent.change(input, { target: { value: '4' } }); // typed, not yet persisted
+ expect(input.value).toBe('4');
+ // A failed save bumps the nonce; the draft must revert to the persisted (global) value.
+ rerender(
+ <EditorialCheckCard
+ check={check}
+ seriesId="ser-1"
+ seriesConfig={null}
+ seriesResetNonce={1}
+ onToggle={vi.fn()}
+ onConfigSave={vi.fn()}
+ onSeriesConfigSave={vi.fn()}
+ />,
+ );
+ expect(screen.getByLabelText('Minimum shared signals to flag').value).toBe('2');
+ });
+
it('shows an active badge and clears the override via Reset to global', () => {
const onSeriesConfigSave = vi.fn();
render(
diff --git a/client/src/pages/PipelineEditorialChecks.jsx b/client/src/pages/PipelineEditorialChecks.jsx
index 5abbe28163..7a11939d3b 100644
--- a/client/src/pages/PipelineEditorialChecks.jsx
+++ b/client/src/pages/PipelineEditorialChecks.jsx
@@ -50,6 +50,9 @@ export default function PipelineEditorialChecks() {
// series PATCH; track in-flight saves per checkId so the run buttons gate on the
// override landing (the runner reads the persisted series record).
const [savingSeriesIds, setSavingSeriesIds] = useState(() => new Set());
+ // 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(() => ({}));
const seriesId = searchParams.get('series') || '';
const [comments, setComments] = useState([]);
const [loadingFindings, setLoadingFindings] = useState(false);
@@ -236,7 +239,13 @@ export default function PipelineEditorialChecks() {
if (!nextOverride || Object.keys(nextOverride).length === 0) delete map[checkId];
else map[checkId] = nextOverride;
const saved = await updatePipelineSeries(sid, { editorialCheckConfig: map }, { silent: true })
- .catch((err) => { toast.error(err.message || 'Failed to save series override'); return null; });
+ .catch((err) => {
+ toast.error(err.message || 'Failed to save series override');
+ // Revert the card's draft inputs to the persisted value (the override
+ // wasn't saved, so the field must not keep showing the typed threshold).
+ setSeriesResetNonces((m) => ({ ...m, [checkId]: (m[checkId] || 0) + 1 }));
+ return null;
+ });
// On failure `overrideMapRef` is untouched, so the UI keeps showing the
// last persisted overrides (no phantom). On success, sync the ref + state
// from the sanitized record — but only if the user hasn't switched series
@@ -491,6 +500,7 @@ export default function PipelineEditorialChecks() {
seriesId={seriesId}
seriesConfig={seriesOverrides?.[check.id] || null}
seriesSaving={savingSeriesIds.has(check.id)}
+ seriesResetNonce={seriesResetNonces[check.id] || 0}
onSeriesConfigSave={handleSeriesConfigSave}
onEdit={check.isCustom ? openCustomForm : undefined}
onDelete={check.isCustom ? handleDeleteCustom : undefined}
diff --git a/server/routes/pipeline/series.js b/server/routes/pipeline/series.js
index 2420e21404..ce24807817 100644
--- a/server/routes/pipeline/series.js
+++ b/server/routes/pipeline/series.js
@@ -181,6 +181,10 @@ const seriesCreateSchema = z.object({
characterArcs: characterArcsSchema.optional(),
locked: seriesLockedSchema.optional(),
styleNotes: z.string().trim().max(seriesSvc.STYLE_NOTES_MAX).optional().default(''),
+ // Per-series editorial-check config overrides (#1591). Free-form blob (re-validated
+ // per check at run time, bounded by sanitizeEditorialCheckConfig); forwarded so an
+ // importer / share-bucket create that seeds tuned thresholds keeps them.
+ editorialCheckConfig: z.record(z.record(z.unknown())).nullable().optional(),
// Fact-checking opt-in + author fact reference (#1588).
factCritical: z.boolean().optional().default(false),
factReference: z.string().trim().max(seriesSvc.FACT_REFERENCE_MAX).optional().default(''),
diff --git a/server/services/pipeline/series.js b/server/services/pipeline/series.js
index 4999e5a9d8..3fee4242d5 100644
--- a/server/services/pipeline/series.js
+++ b/server/services/pipeline/series.js
@@ -179,10 +179,12 @@ const toCount = (v) => (Number.isInteger(v) && v >= 0 ? v : 0);
// re-validates the merged blob through the check's own Zod `configSchema`, so a
// malformed/out-of-range value is dropped at run time and can't corrupt a pass.
// This sanitizer therefore only bounds the WIRE shape: a plain object-of-objects
-// with primitive leaves, size-capped against a hand-edited/older-peer file. Empty
-// → `undefined` (omitted) so a series that sets no override keeps its byte-stable
-// on-disk + wire shape against pre-feature peers (the v8 `pipelineSeries` gate
-// protects only series that DO carry the field from strip-then-LWW loss).
+// with primitive leaves, size-capped against a hand-edited/older-peer file. Always
+// present (empty `{}` when a series tunes nothing) — mirroring factReference/
+// styleGuide — so an explicit clear (`{}`) propagates between v8 peers via LWW
+// while a behind-sender that OMITS the key is preserved by
+// `preserveAbsentAdditiveFields` (see ADDITIVE_SERIES_FIELDS). The v8
+// `pipelineSeries` gate stops a ≤v7 peer from strip-then-LWW-ing the field.
const ECC_MAX_CHECKS = 200;
const ECC_MAX_KEYS_PER_CHECK = 40;
const ECC_CHECK_ID_MAX = 120;
@@ -203,7 +205,7 @@ const sanitizeCheckConfigOverride = (raw) => {
};
const sanitizeEditorialCheckConfig = (raw) => {
- if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return undefined;
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return {};
const out = {};
for (const [checkId, override] of Object.entries(raw)) {
if (Object.keys(out).length >= ECC_MAX_CHECKS) break;
@@ -211,7 +213,7 @@ const sanitizeEditorialCheckConfig = (raw) => {
const clean = sanitizeCheckConfigOverride(override);
if (clean) out[checkId] = clean;
}
- return Object.keys(out).length ? out : undefined;
+ return out;
};
const sanitizeSeriesLocked = (raw = {}) => {
@@ -335,13 +337,12 @@ const sanitizeSeries = (raw) => {
// Older peers' sanitizeSeries simply drops the unknown field (forward/
// back-compatible).
...(autopilot ? { autopilot } : {}),
- // Per-series editorial-check config overrides (#1591). Persisted only when a
- // series actually carries an override so series that never tune a check keep
- // their byte-stable on-disk + wire shape (the v8 `pipelineSeries` gate guards
- // the loss for series that DO carry it). A ≤v7 peer that re-sanitizes a series
- // through its editorialCheckConfig-unaware sanitizeSeries would otherwise drop
- // the overrides and last-writer-wins the loss back onto the newer peer.
- ...(editorialCheckConfig ? { editorialCheckConfig } : {}),
+ // Per-series editorial-check config overrides (#1591). Always present (empty
+ // `{}` when nothing is tuned), like factReference/styleGuide, so a clear
+ // propagates between v8 peers and a behind-sender's omission is preserved (see
+ // ADDITIVE_SERIES_FIELDS). Wire-gated at pipelineSeries v8 so a ≤v7 peer can't
+ // strip-then-LWW the overrides back onto a newer peer.
+ editorialCheckConfig,
};
};
@@ -392,7 +393,7 @@ export async function createSeries(input = {}) {
importDraft: input.importDraft === true,
// Per-series editorial-check config overrides (#1591) — forwarded so an
// importer / promote flow that seeds a series with tuned thresholds keeps
- // them; sanitizeSeries normalizes an empty/malformed map back to absent.
+ // them; sanitizeSeries normalizes an empty/malformed map to `{}`.
editorialCheckConfig: input.editorialCheckConfig,
});
await store().saveOne(created.id, created);
@@ -571,7 +572,7 @@ export async function updateSeries(id, patch = {}) {
...('autopilot' in patch ? { autopilot: patch.autopilot } : {}),
// Per-series editorial-check config overrides (#1591). Wholesale replace —
// `{}`/`null` clears every override; omission preserves. The sanitizer drops
- // empty/malformed entries and normalizes an empty map back to absent.
+ // empty/malformed entries and normalizes to `{}` (always present).
...('editorialCheckConfig' in patch ? { editorialCheckConfig: patch.editorialCheckConfig } : {}),
llm: mergedLlm,
updatedAt: new Date().toISOString(),
@@ -781,7 +782,7 @@ async function cascadeDeleteSideEffects(id) {
// consult the RAW remote payload to tell the two apart: key absent → preserve
// local; key present (even null/empty) → honor the intentional clear. Mirrors
// the `universeId` hierarchy guard. See issue #1361.
-const ADDITIVE_SERIES_FIELDS = ['arc', 'seasons', 'styleGuide', 'styleNotes', 'characterArcs', 'factReference', 'factCritical'];
+const ADDITIVE_SERIES_FIELDS = ['arc', 'seasons', 'styleGuide', 'styleNotes', 'characterArcs', 'factReference', 'factCritical', 'editorialCheckConfig'];
// Additive sub-fields nested inside `arc`. A peer that predates these (readerMap
// shipped at schema v2, tickingClock at #1289/v3) still sends an `arc` object —
// just without these keys — so the erasure for them happens one level down.
diff --git a/server/services/pipeline/series.test.js b/server/services/pipeline/series.test.js
index b3b854333e..67d83795db 100644
--- a/server/services/pipeline/series.test.js
+++ b/server/services/pipeline/series.test.js
@@ -125,10 +125,11 @@ describe('pipeline series service', () => {
expect(cleared.factReference).toBe('');
});
- it('defaults editorialCheckConfig absent and round-trips per-series overrides (#1591)', async () => {
+ it('defaults editorialCheckConfig to {} and round-trips per-series overrides (#1591)', async () => {
const plain = await svc.createSeries({ name: 'Plain' });
- // Absent until a series actually tunes a check (byte-stable shape for old peers).
- expect(plain.editorialCheckConfig).toBeUndefined();
+ // Always present (empty) — like factReference/styleGuide — so a clear can
+ // propagate between v8 peers and is protected as an additive field on sync.
+ expect(plain.editorialCheckConfig).toEqual({});
const tuned = await svc.createSeries({
name: 'YA Graphic Novel',
@@ -160,9 +161,9 @@ describe('pipeline series service', () => {
// Wholesale replace.
const replaced = await svc.updateSeries(s.id, { editorialCheckConfig: { 'comic.panel-rhythm': { maxConsecutiveSplash: 1 } } });
expect(replaced.editorialCheckConfig).toEqual({ 'comic.panel-rhythm': { maxConsecutiveSplash: 1 } });
- // {} clears (sanitizer normalizes the empty map back to absent).
+ // {} clears all overrides (sanitizer keeps the always-present empty map).
const cleared = await svc.updateSeries(s.id, { editorialCheckConfig: {} });
- expect(cleared.editorialCheckConfig).toBeUndefined();
+ expect(cleared.editorialCheckConfig).toEqual({});
});
it('updateSeries throws ERR_NOT_FOUND for unknown id', async () => {
@@ -648,6 +649,25 @@ describe('pipeline series service', () => {
expect(after.seasons[0].title).toBe('Season One');
});
+ it('preserves editorialCheckConfig when a behind-sender omits the key, applies an explicit clear (#1591)', async () => {
+ const s = await svc.createSeries({
+ name: 'TunedSeries',
+ editorialCheckConfig: { 'comic.lettering-density': { maxWordsPerBalloon: 18 } },
+ });
+ expect(s.editorialCheckConfig).toEqual({ 'comic.lettering-density': { maxWordsPerBalloon: 18 } });
+ // Behind-sender (older peer) omits the key → local overrides preserved.
+ const behind = { id: s.id, name: 'TunedSeries (peer edit)', updatedAt: NEWER };
+ await svc.mergeSeriesFromSync([behind]);
+ const kept = await svc.getSeries(s.id);
+ expect(kept.name).toBe('TunedSeries (peer edit)');
+ expect(kept.editorialCheckConfig).toEqual({ 'comic.lettering-density': { maxWordsPerBalloon: 18 } });
+ // Up-to-date peer present-but-empty map → the clear applies (present key wins).
+ const clear = { id: s.id, name: 'TunedSeries', editorialCheckConfig: {}, updatedAt: '2999-06-01T00:00:00.000Z' };
+ await svc.mergeSeriesFromSync([clear]);
+ const cleared = await svc.getSeries(s.id);
+ expect(cleared.editorialCheckConfig).toEqual({});
+ });
+
it('preserves arc (incl. readerMap + tickingClock) when the remote omits arc', async () => {
const s = await svc.createSeries({
name: 'ArcKeep',