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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): never skip refresh on an outline-content gate's stale verdict (#1614)
[._.]/ Adam Eivyb6e13ff43c7c
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.jsindex 52e8c7c223..c0c4231a78 100644--- a/server/services/pipeline/editorial/checkRunner.js+++ b/server/services/pipeline/editorial/checkRunner.js@@ -852,17 +852,33 @@ export async function buildEditorialCheckPlan(seriesId, { checkIds = null, setti* Gate-aware refinement (#1614): an enabled consumer whose runtime `gate(ctx)`* declines won't actually run — so it doesn't justify spending an LLM call to* refresh the outline. When the caller supplies a `gateCtx` (the autopilot- * refresh path, which already holds a complete-but-stale outline to evaluate- * against), a consumer must ALSO pass its gate to count. The sources-only signal- * stands when no ctx is given (the dry-run plan + the cheap pre-filter, neither- * of which builds a ctx) so existing callers are unchanged.+ * refresh path, which holds the current — stale — outline), a consumer must ALSO+ * pass its gate to count. The sources-only signal stands when no ctx is given+ * (the dry-run plan + the cheap pre-filter, neither of which builds a ctx) so+ * existing callers are unchanged.+ *+ * Critically, the refresh REGENERATES the outline — so a gate that reads the+ * outline can't be predicted from the stale copy (its "declines" may flip to+ * "passes" once the outline is fresh, e.g. a `pov.justified` gate that finds no+ * POV-tagged scenes in a stale outline a refresh would re-tag). We therefore+ * only trust a DECLINING gate that decided WITHOUT touching the outline (from+ * manuscript/canon/series, which the refresh leaves unchanged); a consumer whose+ * gate read the outline stays a consumer so the refresh still runs. A passing+ * gate always counts.*/export function enabledChecksConsumeReverseOutline(settings, checkIds = null, gateCtx = null) {return getEnabledChecks(settings, checkIds).some(({ check }) => {const sources = checkSources(check);if (!sources.includes('reverseOutline') && !sources.includes('reverseOutline.plotlines')) return false;- if (gateCtx && typeof check.gate === 'function' && !check.gate(gateCtx)) return false;- return true;+ if (!gateCtx || typeof check.gate !== 'function') return true;+ let readOutline = false;+ const tracked = new Proxy(gateCtx, {+ get(target, key) {+ if (key === 'reverseOutline' || key === 'reverseOutlinePlotlines') readOutline = true;+ return target[key];+ },+ });+ return check.gate(tracked) || readOutline;});}diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.jsindex 98f72e5b2a..75f139e713 100644--- a/server/services/pipeline/editorial/checkRunner.test.js+++ b/server/services/pipeline/editorial/checkRunner.test.js@@ -1003,9 +1003,20 @@ describe('enabledChecksConsumeReverseOutline (#1349)', () => {// Gate-aware consumption (#1614): a supplied ctx narrows the signal to checks// that would ACTUALLY run for this series, not just declare the source.describe('gate-aware via ctx (#1614)', () => {- // No manuscript, no named canon, no scenes → every outline consumer's- // runtime gate declines, so nothing would run even though sources match.- const gatedOutCtx = { manuscript: '', canon: { characters: [] }, reverseOutline: [], reverseOutlinePlotlines: [] };+ // Does a check's gate read the outline? The refresh regenerates the outline,+ // so an outline-reading gate's verdict against the STALE outline can't be+ // trusted — such a check must stay a consumer. Probe it the same way the+ // function does (mirrors the implementation's Proxy).+ const gateReadsOutline = (check) => {+ if (typeof check.gate !== 'function') return false;+ let read = false;+ const probe = new Proxy(+ { manuscript: 'x', canon: { characters: [{ name: 'A' }] }, series: { styleGuide: {} }, reverseOutline: [{ povCharacter: 'A' }], reverseOutlinePlotlines: [{ id: 'p' }] },+ { get(t, k) { if (k === 'reverseOutline' || k === 'reverseOutlinePlotlines') read = true; return t[k]; } },+ );+ try { check.gate(probe); } catch { /* a partial probe ctx may throw — irrelevant to the read flag */ }+ return read;+ };// A drafted manuscript re-opens the manuscript-gated outline consumers.const liveCtx = { manuscript: 'The kingdom fell.', canon: { characters: [{ name: 'Bob' }] }, reverseOutline: [{ povCharacter: 'Bob' }], reverseOutlinePlotlines: [] };@@ -1014,13 +1025,27 @@ describe('enabledChecksConsumeReverseOutline (#1349)', () => {expect(enabledChecksConsumeReverseOutline({}, null, null)).toBe(true);});- it('is false when every consumer is gated out by the ctx', () => {- expect(enabledChecksConsumeReverseOutline({}, null, gatedOutCtx)).toBe(false);+ it('is false only when the surviving consumers are gated out for OUTLINE-INDEPENDENT reasons', () => {+ // Disable consumers whose gate reads the outline (those can't be skipped on+ // a stale outline). The rest are manuscript/canon/series-gated, and an+ // empty-manuscript empty-canon ctx makes each decline → no consumer runs.+ const settings = disableWhere((c) => consumesOutline(c) && gateReadsOutline(c));+ const ctx = { manuscript: '', canon: { characters: [] }, series: {}, reverseOutline: [], reverseOutlinePlotlines: [] };+ expect(enabledChecksConsumeReverseOutline(settings, null, ctx)).toBe(false);});it('is true when at least one consumer passes its gate against the ctx', () => {expect(enabledChecksConsumeReverseOutline({}, null, liveCtx)).toBe(true);});++ it('keeps an outline-content-gated consumer that declines on the STALE outline (#1614, codex P2)', () => {+ // Scoped to pov.justified only — its gate reads ctx.reverseOutline. A stale+ // outline with scenes but no POV tags makes the gate decline, yet a refresh+ // might re-tag POV, so the refresh must NOT be skipped: still a consumer.+ const onlyPov = disableWhere((c) => consumesOutline(c) && c.id !== 'pov.justified');+ const staleNoPov = { manuscript: 'x', canon: { characters: [] }, series: {}, reverseOutline: [{ heading: 'h', summary: 's' }], reverseOutlinePlotlines: [] };+ expect(enabledChecksConsumeReverseOutline(onlyPov, null, staleNoPov)).toBe(true);+ });});});diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.jsindex fbb54862e8..16f474826c 100644--- a/server/services/pipeline/seriesAutopilot.js+++ b/server/services/pipeline/seriesAutopilot.js@@ -1065,17 +1065,16 @@ async function runReverseOutlineRefresh(sId, record) {return {};}// Gate 3 (#1614) — gate-aware consumption. A check that DECLARES the outline as- // a source still won't run if its runtime gate declines for this series (e.g.- // no POV-tagged scenes, a canon-less roster). Evaluate each consumer's gate- // against the current outline so a refresh is skipped when nothing that would- // actually run reads it. Gate on SCENE PRESENCE, not `status`: the real- // precondition is "there's scene content to gate against" — a never-generated- // (`status:'none'`) or empty outline has none, so the outline-content gates- // would all falsely decline; we bootstrap the first generation unconditionally- // rather than chicken-and-egg ourselves out of it. (This predicts the- // regenerated outline's consumption from the stale one's content — a leaky but- // safe proxy: the worst case is a wasted refresh, never a missed one, because- // a manuscript-gated consumer keeps the refresh alive whenever a draft exists.)+ // a source still won't run if its runtime gate declines for this series (e.g. a+ // canon-less roster). Evaluate each consumer's gate against the current outline+ // and skip the refresh when none would run. Gate on SCENE PRESENCE, not+ // `status`: the precondition is "there's scene content to evaluate gates+ // against" — a never-generated (`status:'none'`) or empty outline has none, so+ // we bootstrap the first generation unconditionally rather than chicken-and-egg+ // ourselves out of it. enabledChecksConsumeReverseOutline only trusts a+ // DECLINING gate that didn't read the outline (the refresh regenerates it, so+ // an outline-content gate's stale verdict can't be trusted and keeps the check+ // a consumer) — so a scoped run of only outline-gated checks still refreshes.if (Array.isArray(current.scenes) && current.scenes.length > 0) {const gateCtx = await buildReverseOutlineGateContext(sId, { outline: current }).catch(() => null);if (gateCtx && !enabledChecksConsumeReverseOutline(settings, checkIds, gateCtx)) {