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
simplify(#1614): gate on scene-presence not status enum + add slim-ctx contract guard
[._.]/ Adam Eivyb09b318d15ad
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.jsindex ffe7df8d4f..52e8c7c223 100644--- a/server/services/pipeline/editorial/checkRunner.js+++ b/server/services/pipeline/editorial/checkRunner.js@@ -875,9 +875,14 @@ export function enabledChecksConsumeReverseOutline(settings, checkIds = null, ga** Deliberately lighter than buildEditorialContext: no issues / editorial-arc /* continuity-bible / comic projections and no injected LLM callers, because the- * gates of outline-consuming checks read only `manuscript`, `canon`, and- * `reverseOutline[.plotlines]`. Pass the already-read `outline` (the autopilot's- * Gate-2 read) to avoid a redundant outline fetch.+ * gates of outline-consuming checks read only `manuscript`, `canon`, `series`,+ * and `reverseOutline[.plotlines]`. Pass the already-read `outline` (the+ * autopilot's Gate-2 read) to avoid a redundant outline fetch.+ *+ * The slim field set is a contract: a checkRunner.test.js guard asserts every+ * reverse-outline-consuming check's `gate()` reads only the keys this builder+ * returns, so a future check whose gate reaches for `ctx.issues` (etc.) fails+ * loudly in CI instead of silently mis-evaluating against an absent field.*/export async function buildReverseOutlineGateContext(seriesId, { outline } = {}) {const series = await getSeries(seriesId);diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.jsindex 70cb76cf68..98f72e5b2a 100644--- a/server/services/pipeline/editorial/checkRunner.test.js+++ b/server/services/pipeline/editorial/checkRunner.test.js@@ -1043,6 +1043,37 @@ describe('buildReverseOutlineGateContext (#1614)', () => {expect(ctx2.reverseOutline).toEqual([]);expect(ctx2.reverseOutlinePlotlines).toEqual([]);});++ // Contract guard (#1614): the autopilot evaluates consumer gates against this+ // slim ctx, NOT the full buildEditorialContext. If a future reverse-outline+ // consumer's gate reaches for a field the slim ctx omits (ctx.issues,+ // ctx.editorialArcs, …), it would silently mis-evaluate against `undefined`+ // and wrongly skip/force a refresh. Fail loudly here instead. The allowed set+ // is exactly the keys buildReverseOutlineGateContext returns.+ it('every reverse-outline consumer gate reads only slim-ctx keys', () => {+ const ALLOWED = new Set(['seriesId', 'series', 'manuscript', 'canon', 'reverseOutline', 'reverseOutlinePlotlines']);+ const base = {+ seriesId: 's1',+ series: { styleGuide: { povPerson: 'third-limited' } },+ manuscript: 'The kingdom fell.',+ canon: { characters: [{ name: 'Bob' }] },+ reverseOutline: [{ povCharacter: 'Bob', heading: 'h' }],+ reverseOutlinePlotlines: [{ id: 'p1' }],+ };+ const consumers = listChecks().filter((c) => Array.isArray(c.sources)+ && (c.sources.includes('reverseOutline') || c.sources.includes('reverseOutline.plotlines'))+ && typeof c.gate === 'function');+ expect(consumers.length).toBeGreaterThan(0);+ for (const check of consumers) {+ const accessed = new Set();+ // Record only TOP-LEVEL ctx key reads — nested reads (ctx.canon.characters)+ // land on the real unproxied value, so they don't register.+ const proxy = new Proxy(base, { get(t, k) { if (typeof k === 'string') accessed.add(k); return t[k]; } });+ check.gate(proxy); // must also not throw against the slim ctx+ const leaked = [...accessed].filter((k) => !ALLOWED.has(k));+ expect(leaked, `${check.id} gate read non-slim ctx keys: ${leaked.join(', ')}`).toEqual([]);+ }+ });});// Inter-check context sharing (#1627) — dependency-scoped prior findings in ctx.diff --git a/server/services/pipeline/seriesAutopilot.js b/server/services/pipeline/seriesAutopilot.jsindex 15eed0ba72..fbb54862e8 100644--- a/server/services/pipeline/seriesAutopilot.js+++ b/server/services/pipeline/seriesAutopilot.js@@ -1068,11 +1068,15 @@ async function runReverseOutlineRefresh(sId, record) {// 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. Only applied to a COMPLETE-but-stale outline: a- // never-generated outline (`status:'none'`) has no scenes to gate against, so- // the outline-content gates would all decline — we bootstrap the first run- // unconditionally rather than chicken-and-egg ourselves out of it.- if (current.status === 'complete') {+ // 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.)+ if (Array.isArray(current.scenes) && current.scenes.length > 0) {const gateCtx = await buildReverseOutlineGateContext(sId, { outline: current }).catch(() => null);if (gateCtx && !enabledChecksConsumeReverseOutline(settings, checkIds, gateCtx)) {record.runState.reverseOutlineRefreshed = true;diff --git a/server/services/pipeline/seriesAutopilot.test.js b/server/services/pipeline/seriesAutopilot.test.jsindex 968e4c1de3..89b81a0f6f 100644--- a/server/services/pipeline/seriesAutopilot.test.js+++ b/server/services/pipeline/seriesAutopilot.test.js@@ -1280,7 +1280,9 @@ describe('autopilot conductor', () => {// spend an LLM call no runnable check consumes.reverseOutlineConsumed = true; // gate 1: a consumer declares the sourcereverseOutlineConsumedGated = false; // gate 3: but every consumer is gated out- reverseOutlineState = { status: 'complete', stale: true };+ // A complete-but-stale outline WITH scenes — gate 3 only evaluates when+ // there's scene content to gate against (a scene-less outline bootstraps).+ reverseOutlineState = { status: 'complete', stale: true, scenes: [{ id: 'sc1' }] };const { seriesId } = await seedComplete();await autopilot.startSeriesAutopilot(seriesId, { includeVisual: false });await waitFor(runFinished(seriesId));@@ -1304,7 +1306,7 @@ describe('autopilot conductor', () => {it('forces a regen when a cached refresh is still stale against the live manuscript (#1614)', async () => {reverseOutlineConsumed = true;- reverseOutlineState = { status: 'complete', stale: true };+ reverseOutlineState = { status: 'complete', stale: true, scenes: [{ id: 'sc1' }] };// First generate() no-ops as cached (hash matched at generate time), but the// live manuscript is still stale → the run forces one more regen.generateReverseOutline