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([issue-1346]): partial custom-check edit no longer resets omitted fields; review fixes

Adam Eivy3da685e1fbd9
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 49665b3e41..b958f30514 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -1018,35 +1018,44 @@ export const editorialChecksRunSchema = z.object({
model: z.string().trim().max(200).optional(),
}).strict();
-// User-defined editorial check (#1346) — the authored input shape for
-// POST .../editorial/custom-checks. The user only describes WHAT to look for;
-// the JSON output contract is enforced server-side (buildCustomCheckPrompt), so
-// no schema field captures it. `scope`/`severityDefault` reuse the registry's
-// own enums so the wire gate can't drift from what `buildCustomCheck` accepts.
-export const editorialCustomCheckCreateSchema = z.object({
+// User-defined editorial check (#1346). The base authored-field shapes carry NO
+// `.default()` so the UPDATE schema (a `.partial()` of them) leaves an omitted
+// field unchanged — a defaulted optional would silently RESET the stored value
+// on a field-specific PATCH (Zod's `.partial()` keeps the inner `.default()`,
+// which still fires when the key is absent). `scope`/`severityDefault` reuse the
+// registry's own enums so the wire gate can't drift from `buildCustomCheck`.
+const editorialCustomCheckShape = {
label: z.string().trim().min(1).max(120),
- description: z.string().trim().max(500).optional().default(''),
+ description: z.string().trim().max(500),
prompt: z.string().trim().min(1).max(8_000),
- scope: z.enum([...CHECK_SCOPES]).optional().default('issue'),
- category: z.string().trim().max(60).optional().default('custom'),
- severityDefault: z.enum([...CHECK_SEVERITIES]).optional().default('medium'),
+ scope: z.enum([...CHECK_SCOPES]),
+ category: z.string().trim().max(60),
+ severityDefault: z.enum([...CHECK_SEVERITIES]),
+};
+
+// Create: label + prompt required; the rest optional with sensible defaults (so
+// a new check is fully-formed). The JSON output contract is enforced server-side
+// (buildCustomCheckPrompt), so no schema field captures it.
+export const editorialCustomCheckCreateSchema = z.object({
+ ...editorialCustomCheckShape,
+ description: editorialCustomCheckShape.description.optional().default(''),
+ scope: editorialCustomCheckShape.scope.optional().default('issue'),
+ category: editorialCustomCheckShape.category.optional().default('custom'),
+ severityDefault: editorialCustomCheckShape.severityDefault.optional().default('medium'),
}).strict();
-// Edit is the same shape, all-optional (the id is in the URL). `.partial()`
-// drops the `.default()`s so an unspecified field is simply left unchanged.
-export const editorialCustomCheckUpdateSchema = editorialCustomCheckCreateSchema.partial();
+// Edit (the id is in the URL): every field optional, NO defaults, so an omitted
+// field is left unchanged rather than reset.
+export const editorialCustomCheckUpdateSchema = z.object(editorialCustomCheckShape).partial().strict();
// The STORED definition shape (settings.pipelineEditorialChecks.customChecks[]):
// the authored fields + the generated id and timestamps. Validated as part of
// the settings slice below so a hand-edited / synced file is bounded.
export const editorialCustomCheckDefSchema = z.object({
id: z.string().trim().min(1).max(120),
- label: z.string().trim().min(1).max(120),
- description: z.string().trim().max(500).optional().default(''),
- prompt: z.string().trim().min(1).max(8_000),
- scope: z.enum([...CHECK_SCOPES]),
- category: z.string().trim().max(60).optional().default('custom'),
- severityDefault: z.enum([...CHECK_SEVERITIES]),
+ ...editorialCustomCheckShape,
+ description: editorialCustomCheckShape.description.optional().default(''),
+ category: editorialCustomCheckShape.category.optional().default('custom'),
createdAt: z.string().optional(),
updatedAt: z.string().optional(),
}).strict();
diff --git a/server/routes/pipeline/editorial.js b/server/routes/pipeline/editorial.js
index d1362cb6a9..dea84ba1f8 100644
--- a/server/routes/pipeline/editorial.js
+++ b/server/routes/pipeline/editorial.js
@@ -165,6 +165,8 @@ router.patch('/editorial/custom-checks/:id', asyncHandler(async (req, res) => {
const slice = editorialChecksSlice(current);
const defs = Array.isArray(slice.customChecks) ? slice.customChecks : [];
// Preserve id + createdAt; apply only the supplied fields; stamp updatedAt.
+ // `body` carries only the fields the caller actually supplied (the update
+ // schema has no defaults), so an omitted field is left unchanged.
const next = defs.map((d) => (d?.id === id
? { ...d, ...body, id: d.id, createdAt: d.createdAt, updatedAt: new Date().toISOString() }
: d));
diff --git a/server/routes/pipeline/editorial.test.js b/server/routes/pipeline/editorial.test.js
index c22f007de6..882ea8a4d7 100644
--- a/server/routes/pipeline/editorial.test.js
+++ b/server/routes/pipeline/editorial.test.js
@@ -171,6 +171,22 @@ describe('custom checks CRUD (#1346)', () => {
expect(def.prompt).toBe('old prompt'); // untouched fields preserved
});
+ it('a field-specific edit leaves omitted fields unchanged (no default reset)', async () => {
+ const { body } = await create({ label: 'Original', prompt: 'p', scope: 'series', category: 'continuity', description: 'keep me' });
+ const res = await request(app)
+ .patch(`/api/pipeline/editorial/custom-checks/${encodeURIComponent(body.id)}`)
+ .send({ label: 'Renamed' }); // only label
+ expect(res.status).toBe(200);
+ expect(res.body.label).toBe('Renamed');
+ // Omitted fields must NOT revert to schema defaults (issue/custom/'').
+ expect(res.body.scope).toBe('series');
+ expect(res.body.category).toBe('continuity');
+ const def = settingsStore.pipelineEditorialChecks.customChecks[0];
+ expect(def.scope).toBe('series');
+ expect(def.category).toBe('continuity');
+ expect(def.description).toBe('keep me');
+ });
+
it('404s editing an unknown custom id and 400s a non-custom id', async () => {
expect((await request(app).patch('/api/pipeline/editorial/custom-checks/custom.nope').send({ label: 'x' })).status).toBe(404);
expect((await request(app).patch('/api/pipeline/editorial/custom-checks/prose.info-dumping').send({ label: 'x' })).status).toBe(400);
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.js
index 0b4ddb3de9..0455227ff5 100644
--- a/server/services/pipeline/editorial/checkRunner.js
+++ b/server/services/pipeline/editorial/checkRunner.js
@@ -19,7 +19,7 @@ import { randomUUID, createHash } from 'crypto';
import { createSseRunner } from '../../../lib/sseUtils.js';
import { runStagedLLM, runInlineLLM, resolveStageContext } from '../../../lib/stageRunner.js';
import { planManuscriptPass } from '../../../lib/contextBudget.js';
-import { getEnabledChecks, getEnabledCheckRows, getCheckById } from '../../../lib/editorial/index.js';
+import { getEnabledChecks, getEnabledCheckRows, getAllChecks } from '../../../lib/editorial/index.js';
import { getSettings } from '../../settings.js';
import { getSeries } from '../series.js';
import { listIssues } from '../issues.js';
@@ -233,9 +233,11 @@ export async function buildEditorialCheckPlan(seriesId, { checkIds = null, setti
export async function getReviewWithStaleness(seriesId) {
const review = await getReview(seriesId);
// Resolve checks against built-ins + the user's custom checks (#1346) so a
- // custom-check finding still gets staleness annotation. Read settings once.
+ // custom-check finding still gets staleness annotation. Build the id→check map
+ // once (custom-check synthesis is not free) and look up per comment.
const settings = await getSettings();
- const checkFor = (id) => getCheckById(settings, id);
+ const byId = new Map(getAllChecks(settings).map((c) => [c.id, c]));
+ const checkFor = (id) => byId.get(id) || null;
// Only recompute hashes when there's at least one hash-stamped finding from a
// still-registered check — a pure completeness review pays no extra I/O.
const evaluable = review.comments.filter((c) => c.checkId && c.sourceContentHash && checkFor(c.checkId));