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

editorial: deterministic checks self-heal via fresh+scoped seeding

[._.]/ Adam Eivy8c2c9ca49f8f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 6d532e0098..c80eaebcd5 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -53,3 +53,4 @@
- Editing an app's ports now persists. Port fields are derived from `ecosystem.config.cjs`, so saving only updated PortOS's registry while PM2 kept the old ports and the next config refresh reverted the change. Saving a changed port now rewrites the matching value in the app's `ecosystem.config.cjs` (the source of truth). Restart the app for the new port to take effect.
- Editing a **shared or derived** port now persists too. When two port fields resolve to the same literal (e.g. the prod UI is served by the API, so `uiPort === apiPort`), the value-keyed rewrite couldn't tell them apart and the edit returned a 422. The PUT route now falls back to a **per-process-label-targeted** rewrite: it locates the specific process block in `ecosystem.config.cjs` and rewrites only the touched label's port (`api`/`ui`/`devUi`), leaving the sibling field — and any same-valued unrelated number — untouched. Edits to ports that live only under a process's `env`/`args` (no top-level field) persist as well, and an explicit `ports: { ui: N, devUi: N }` map with matching values is split correctly (only the edited key changes). A save that mixes a distinct port and a shared port is written **atomically** — both rewrites are computed in memory and the config file is written once, only when every edit is persistable — so a request that's rejected (422) never leaves the config half-changed. The 422 is reserved for the genuinely unpersistable case (the literal isn't in the touched process block — e.g. it lives in a shared `const PORTS = {…}` referenced via `ports: PORTS.server`, or is computed entirely at runtime), so a shared-value edit never falsely reports success while the displayed port silently reverts. For an app whose prod UI is **served by the API** (no separate UI port), the UI port can't be set on its own — it always follows the API port: the stored UI port is normalized to track the API port on every save (so it never freezes at a stale value), and you change it by changing the API port.
- **The character-name dissimilarity check no longer floods an epithet cast with thousands of false "confusable name" findings.** Two bugs compounded on a cast that uses article-led epithet names ("THE CABARET SINGER", "THE CHAPTER SEVENTEEN READER", …): (1) the check compared on the raw name, so 60+ "THE …" names all read as starting with the same letter and sharing the same 3-character opening; and (2) "same first letter" and "same opening" were counted as two independent similarity signals even though a shared 3-char opening always implies a shared first letter — so any two names sharing a prefix auto-reached the default 2-signal flag threshold. On one 24-issue series this produced ~2,100 spurious naming findings (and a "44 of 69 names start with T" crowding finding that was really just the article "THE"), driving the editorial health score to 0 and hard-pausing Series Autopilot at the health gate. The check now strips a leading article (the/a/an) before comparing names and counts the first-letter/opening overlap once, so it flags names readers would genuinely confuse and an epithet cast is judged on its real distinguishing words. (`server/lib/editorial/nameSimilarity.js`, `server/lib/editorial/checkRegistry.js`)
+- **Deterministic editorial checks now self-heal — corrected or resolved findings clear instead of lingering forever.** The editorial-checks pass seeded every finding in `merge` mode, which only ever *adds* findings: an open finding a deterministic check no longer produces (because the check was fixed, or the underlying canon/manuscript changed) stayed open permanently. That let stale findings accumulate and could keep Series Autopilot's editorial-health gate blocked on problems that no longer exist. Deterministic checks (pure functions of their inputs) are now seeded in `fresh` mode scoped to each check's own id, so a finding the check no longer surfaces is auto-dismissed (a sync-safe status flip, never a deletion) — including when a check finds nothing at all that pass. LLM checks stay `merge`-only, since an absent LLM finding can be sampling variance rather than a real resolution; one check's reconciliation never touches another check's or the completeness pass's open comments. (`server/services/pipeline/editorial/checkRunner.js`)
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.js
index 9c3024b400..2deb892649 100644
--- a/server/services/pipeline/editorial/checkRunner.js
+++ b/server/services/pipeline/editorial/checkRunner.js
@@ -493,6 +493,11 @@ export async function runEditorialChecks(seriesId, options = {}) {
const findings = [];
const perCheck = [];
+ // Deterministic checks self-heal (see seeding below): track which ones actually
+ // RAN to completion this pass (not gated-out, not errored), so we can fresh-mode
+ // reconcile each of them — including those that produced zero findings, which
+ // must dismiss their now-stale prior open comments.
+ const deterministicRanIds = new Set();
let canceled = false;
for (const { check, config } of enabled) {
if (signal?.aborted) { canceled = true; break; }
@@ -511,6 +516,11 @@ export async function runEditorialChecks(seriesId, options = {}) {
const sourceContentHash = fingerprintForCheck(check, resolvedSources);
const stamped = raw.map((f) => ({ ...f, checkId: check.id, sourceContentHash }));
findings.push(...stamped);
+ // A deterministic check is a pure function of its sources, so a finding it
+ // no longer produces is genuinely resolved (not provider variance) — mark it
+ // for fresh-mode reconciliation. LLM checks stay merge-only (an absent
+ // finding could just be sampling noise).
+ if (check.kind === 'deterministic') deterministicRanIds.add(check.id);
perCheck.push({ checkId: check.id, count: stamped.length });
onProgress?.({ type: 'check:complete', checkId: check.id, count: stamped.length });
} catch (err) {
@@ -525,25 +535,43 @@ export async function runEditorialChecks(seriesId, options = {}) {
if (signal?.aborted) { canceled = true; break; }
}
- // Seed in 'merge' mode (never 'fresh'): a per-series seed of only the editorial
- // checks' findings must not auto-dismiss completeness or other-check open
- // comments. Merge dedups via findingKey (which now includes checkId) and keeps
- // dismissed findings suppressed per-check. Skip entirely on cancellation — a
- // canceled run emits a `canceled` terminal event and must not mutate the
- // review with partial findings collected before the abort.
+ // Seeding strategy (skip entirely on cancellation — a canceled run emits a
+ // `canceled` terminal event and must not mutate the review with partial
+ // findings collected before the abort):
+ //
+ // - DETERMINISTIC checks self-heal: each that ran is seeded in 'fresh' mode
+ // SCOPED to its own checkId, so a finding the (possibly just-corrected) check
+ // no longer surfaces is auto-dismissed (a sync-safe status flip, never a
+ // deletion — see seedReviewFromFindings). This includes checks that found
+ // nothing this pass: their prior open findings must clear. Scoping by checkId
+ // means one deterministic check's reconciliation can't touch another check's
+ // or the completeness pass's (null-checkId) open comments.
+ // - LLM checks (and everything else) stay 'merge' mode: an absent LLM finding
+ // could be sampling variance, so it must not auto-dismiss a prior open one.
+ //
+ // accepted/dismissed comments are untouched by either mode.
if (!canceled) {
- // Seed only when there are findings (merge dedups); but record a revision-trend
- // snapshot for EVERY non-canceled run (#1316) — a run is a revision boundary,
- // and a CLEAN run (0 new findings, or fixes that closed prior ones) is exactly
- // the improving point the trend should capture. When findings were seeded we
- // pass the just-merged comments (no re-read); otherwise recordTrendSnapshot
- // reads the current review itself. Best-effort — a ledger write must never
- // fail the check run (it's telemetry).
- const review = findings.length
- ? await seedReviewFromFindings(seriesId, findings, { runId, mode: 'merge' })
- : null;
+ let lastReview = null;
+ // Fresh-reconcile each deterministic check that ran, scoped to its checkId —
+ // passing only that check's findings so the scoped 'fresh' pass dismisses the
+ // stale opens it no longer produces.
+ for (const checkId of deterministicRanIds) {
+ const own = findings.filter((f) => f.checkId === checkId);
+ lastReview = await seedReviewFromFindings(seriesId, own, { runId, mode: 'fresh', checkId });
+ }
+ // Seed the remaining (non-deterministic) findings in merge mode.
+ const merged = findings.filter((f) => !deterministicRanIds.has(f.checkId));
+ if (merged.length) {
+ lastReview = await seedReviewFromFindings(seriesId, merged, { runId, mode: 'merge' });
+ }
+ // Record a revision-trend snapshot for EVERY non-canceled run (#1316) — a run
+ // is a revision boundary, and a CLEAN run (0 new findings, or a reconciliation
+ // that closed prior ones) is exactly the improving point the trend should
+ // capture. Reuse the freshest seeded review when we have one; otherwise
+ // recordTrendSnapshot reads the current review itself. Best-effort — a ledger
+ // write must never fail the check run (it's telemetry).
const gate = readReadinessGate(settings) || undefined;
- await recordTrendSnapshot(seriesId, { runId, gate, comments: review?.comments }).catch((err) => {
+ await recordTrendSnapshot(seriesId, { runId, gate, comments: lastReview?.comments }).catch((err) => {
console.error(`⚠️ editorial trend snapshot failed — series=${String(seriesId).slice(0, 12)} ${err.message}`);
});
}
diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.js
index 5c9d4b55e1..7301df2be1 100644
--- a/server/services/pipeline/editorial/checkRunner.test.js
+++ b/server/services/pipeline/editorial/checkRunner.test.js
@@ -119,9 +119,24 @@ describe('runEditorialChecks', () => {
expect(result.findings.some((f) => f.checkId === 'naming.dissimilar-names')).toBe(true);
expect(result.findings.some((f) => f.checkId === 'prose.info-dumping')).toBe(true);
- // Seeded once, in 'merge' mode (never auto-dismiss other checks' findings).
- expect(seedReviewFromFindings).toHaveBeenCalledTimes(1);
- expect(seedReviewFromFindings.mock.calls[0][2]).toMatchObject({ mode: 'merge' });
+ // Deterministic checks self-heal: each is seeded in 'fresh' mode scoped to
+ // its own checkId (so a finding it no longer produces auto-dismisses), while
+ // LLM checks seed in 'merge' mode (an absent LLM finding could be variance).
+ // Here: naming (deterministic) → fresh+scoped, info-dump (LLM) → merge.
+ const calls = seedReviewFromFindings.mock.calls;
+ const naming = calls.find((c) => c[2]?.checkId === 'naming.dissimilar-names');
+ expect(naming, 'naming seeded fresh, scoped to its checkId').toBeTruthy();
+ expect(naming[2]).toMatchObject({ mode: 'fresh', checkId: 'naming.dissimilar-names' });
+ const merge = calls.find((c) => c[2]?.mode === 'merge');
+ expect(merge, 'LLM findings seeded in merge mode').toBeTruthy();
+ expect(merge[2].checkId ?? null).toBeNull();
+ // No deterministic finding leaked into the merge batch — they're all routed to
+ // their own fresh+scoped seed instead. (The merge batch is LLM findings only.)
+ const deterministicIds = new Set(
+ listChecks().filter((c) => c.kind === 'deterministic').map((c) => c.id),
+ );
+ expect(merge[1].some((f) => deterministicIds.has(f.checkId))).toBe(false);
+ expect(merge[1].some((f) => f.checkId === 'prose.info-dumping')).toBe(true);
});
it('reports per-check counts', async () => {
@@ -194,6 +209,22 @@ describe('runEditorialChecks', () => {
expect(seedReviewFromFindings).not.toHaveBeenCalled();
});
+ it('self-heals a deterministic check that finds nothing (fresh+scoped seed dismisses stale opens)', async () => {
+ // A clean canon → the naming check produces zero findings. It must STILL seed
+ // in 'fresh' mode scoped to its checkId so any prior open naming findings are
+ // reconciled away — otherwise stale deterministic findings linger forever and
+ // can permanently block the health gate.
+ getSeriesCanon.mockResolvedValueOnce({
+ characters: [{ name: 'Zebediah' }, { name: 'Wolfgang' }], places: [], objects: [],
+ });
+ const result = await runEditorialChecks('s1', { checkIds: ['naming.dissimilar-names'] });
+ expect(result.findings).toEqual([]);
+ expect(seedReviewFromFindings).toHaveBeenCalledTimes(1);
+ const [, findings, opts] = seedReviewFromFindings.mock.calls[0];
+ expect(findings).toEqual([]); // nothing found this pass
+ expect(opts).toMatchObject({ mode: 'fresh', checkId: 'naming.dissimilar-names' });
+ });
+
it('skips seeding when canceled mid-run (no partial review mutation)', async () => {
// Abort during the LLM check; the deterministic naming check already
// collected findings, but a canceled run must not persist them.