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): run setup-summary on the check's pinned stage provider (#1403)

[._.]/ Adam Eivyaab001ba64fa
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 2c4179911d..f1c964f265 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -139,4 +139,4 @@
- **[issue-1395] Universe canon section-local renders now persist durably even if the page unmounts mid-render.** A single reference/clean-plate render fired from the Universe canon section round-tripped a client `updateUniverse` PATCH to append the new filename onto the entry's `imageRefs[]` — so a render that completed *after* the user navigated away, refreshed, or switched universes silently lost its attachment (the image reached the media library, but no `imageRefs[]` row was ever written). These renders now carry the same durable `universeRun.entryRef` job tag the batch path uses, so the server-side completion hook (`universeBuilderCollectionHook`) appends `imageRefs[]` independent of any mounted client — converging the section-local and batch surfaces onto one durable path (mirrors the catalog hook from #1359). The hook fires the `appendEntryImageRef` even when the render carries no collection (and the route preserves `entryRef` through a gallery-collection provisioning failure, so the imageRefs append never depends on the collection existing). The client `handleRefCompleted` keeps its optimistic/immediate-refresh role (no PATCH); the hook is idempotent against it (`mapAppendImageRef` dedupes by filename). Backbone the durable path depends on: `updateUniverse` now preserves canon-entry `imageRefs[]` per-id across a stale whole-array PATCH (an inline canon edit/add/lock that round-trips a snapshot loaded before the render landed no longer clobbers the freshly-appended filename — the same guard variations and composite sheets already had); `purgeImageRefFromAllUniverses` switches to the trusted mutator form so its intentional ref-removal isn't undone by that guard; and the route rejects an `entryRef` missing its locating key (canon→`kindKey`, variation→`categoryKey`) instead of silently no-opping the append. (`server/services/universeBuilderCollectionHook.js`, `server/routes/imageGen.js`, `server/services/universeBuilder.js`, `server/services/universeCanon.js`, `client/src/components/universe/UniverseCanonSection.jsx`, #1395)
-- **[issue-1403] Chunked LLM editorial checks now also carry clean cross-chapter *setup* between chunks, not just prior findings.** The #1383 prior-findings digest stops a later chunk from re-flagging a problem an earlier chunk recorded — but clean setup produces no finding, so a payoff in chunk 2 could still be mis-flagged "missing setup" when chunk 1 cleanly established it, and `style.conformance` had no signal of which tense/POV chapter 1 set when judging chapter 3. `objects.unmotivated-interaction` and `style.conformance` now additionally opt into a **cross-chunk clean-setup digest** (`crossChunkSetup` + a per-check `setupFocus`): after each non-final chunk, one extra inline summarization call (`ctx.callInlineLLM`, tagged `pipeline-editorial-setup-digest`, built by `buildSetupDigestPrompt`) rolls a short "setup so far" summary forward, and `editorialSetupDigest` prepends it to later chunks alongside the findings digest — riding INSIDE the manuscript var (no stage-prompt change). Both digests **yield to manuscript coverage**: the setup digest is fitted *after* the findings digest into whatever spare room remains, so a tight chunk drops the digest rather than the manuscript. A single-chunk (whole-fits) run never summarizes, so the common case pays nothing; a summarizer failure keeps the prior summary and never aborts the check. When the reverse-outline (#1349) or continuity-bible (#1305) artifacts land, either could feed this context more cheaply than a per-chunk call. (`server/lib/editorial/checkRegistry.js`, #1403)
+- **[issue-1403] Chunked LLM editorial checks now also carry clean cross-chapter *setup* between chunks, not just prior findings.** The #1383 prior-findings digest stops a later chunk from re-flagging a problem an earlier chunk recorded — but clean setup produces no finding, so a payoff in chunk 2 could still be mis-flagged "missing setup" when chunk 1 cleanly established it, and `style.conformance` had no signal of which tense/POV chapter 1 set when judging chapter 3. `objects.unmotivated-interaction` and `style.conformance` now additionally opt into a **cross-chunk clean-setup digest** (`crossChunkSetup` + a per-check `setupFocus`): after each non-final chunk, one extra **stage-scoped** inline summarization call (`ctx.callStageScopedInlineLLM`, tagged `pipeline-editorial-setup-digest`, built by `buildSetupDigestPrompt`) rolls a short "setup so far" summary forward, and `editorialSetupDigest` prepends it to later chunks alongside the findings digest — riding INSIDE the manuscript var (no stage-prompt change). The summary call resolves the **same provider the check's stage is pinned to** (a new `runStageScopedInlineLLM` in `stageRunner.js`), so manuscript text never routes to a different (e.g. cloud) provider than the stage chose. Both digests **yield to manuscript coverage**: the setup digest is fitted *after* the findings digest into whatever spare room remains, so a tight chunk drops the digest rather than the manuscript. A single-chunk (whole-fits) run never summarizes, so the common case pays nothing; the stored summary is capped (so a verbose response can't compound across chunks) and a summarizer failure keeps the prior summary and never aborts the check. When the reverse-outline (#1349) or continuity-bible (#1305) artifacts land, either could feed this context more cheaply than a per-chunk call. (`server/lib/editorial/checkRegistry.js`, #1403)
diff --git a/server/lib/editorial/README.md b/server/lib/editorial/README.md
index 7fe897e7c5..78a94c209f 100644
--- a/server/lib/editorial/README.md
+++ b/server/lib/editorial/README.md
@@ -35,9 +35,13 @@ The findings digest carries prior *problems* forward but not clean prior *setup*
chunk established it without producing a finding. A check can additionally opt
into a **cross-chunk clean-setup digest** (#1403): pass `crossChunkSetup: true`
(plus a per-check `setupFocus` string) to `runManuscriptLlmCheck`, and after each
-non-final chunk one extra inline summarization call (`ctx.callInlineLLM`, tagged
-`EDITORIAL_SETUP_DIGEST_SOURCE`, built by `buildSetupDigestPrompt`) rolls a short
-"setup so far" summary forward. `editorialSetupDigest` wraps it and prepends it to
+non-final chunk one extra inline summarization call (`ctx.callStageScopedInlineLLM`,
+tagged `EDITORIAL_SETUP_DIGEST_SOURCE`, built by `buildSetupDigestPrompt`) rolls a
+short "setup so far" summary forward. The summary call is **stage-scoped** — it
+resolves the same provider/model the check's stage is pinned to (not the active
+provider), so manuscript text never routes to a different (e.g. cloud) provider
+than the stage chose. The stored summary is capped to `EDITORIAL_SETUP_DIGEST_BODY_CHARS`
+so a verbose summarizer response can't compound across chunks. `editorialSetupDigest` wraps it and prepends it to
later chunks alongside the findings digest — also yielding to spare budget, and
fitted *after* the findings digest so manuscript coverage and the findings digest
both win when budget is tight. A single-chunk (whole-fits) run never summarizes,
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 5d3f814450..3f0978a1ee 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -447,12 +447,15 @@ async function runManuscriptLlmCheck(ctx, { stage, category, overheadTokens = 0,
const chunks = await ctx.planManuscriptChunks(stage, { overheadTokens });
// Clean-setup digest (#1403): roll a short "setup so far" summary forward via an
// inline summarization call. Only wired when the check opts in AND the runner
- // injected an inline LLM caller — absent it (unit tests of the findings-digest
- // path), the check degrades to findings-only with no extra calls.
- const summarizeChunk = crossChunkSetup && typeof ctx.callInlineLLM === 'function'
+ // injected the stage-scoped inline caller — absent it (unit tests of the
+ // findings-digest path), the check degrades to findings-only with no extra calls.
+ // The call is STAGE-SCOPED (not plain callInlineLLM) so the summary runs on the
+ // same provider the stage is pinned to — never leaking manuscript text to the
+ // active/cloud provider when the check's stage targets a private/local one.
+ const summarizeChunk = crossChunkSetup && typeof ctx.callStageScopedInlineLLM === 'function'
? async (priorSummary, manuscript) => {
const prompt = buildSetupDigestPrompt({ focus: setupFocus, priorSummary, manuscript });
- const { content } = await ctx.callInlineLLM(prompt, { source: EDITORIAL_SETUP_DIGEST_SOURCE });
+ const { content } = await ctx.callStageScopedInlineLLM(stage, prompt, { source: EDITORIAL_SETUP_DIGEST_SOURCE });
return typeof content === 'string' ? content : '';
}
: null;
diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.js
index 5b938f02d7..a1cba32cf4 100644
--- a/server/lib/editorial/checkRegistry.test.js
+++ b/server/lib/editorial/checkRegistry.test.js
@@ -778,7 +778,7 @@ describe('cross-chunk clean-setup digest (#1403)', () => {
seen.push(vars.manuscript);
return { content: { findings: [] } }; // no findings → isolate the setup digest
},
- callInlineLLM: async (prompt) => {
+ callStageScopedInlineLLM: async (_stage, prompt) => {
setupPrompts.push(prompt);
return { content: '- SETUP: past tense, first person' };
},
@@ -815,20 +815,25 @@ describe('cross-chunk clean-setup digest (#1403)', () => {
expect(seen[1].endsWith('CHUNK_TWO')).toBe(true);
});
- it('uses the dedicated run source tag for setup-summary calls', async () => {
+ it('runs the setup-summary on the check STAGE (so it follows the stage provider pin) with the dedicated source tag', async () => {
let source = null;
+ let stageSeen = null;
await getCheck('style.conformance').run({
config: { maxFindings: 12 },
severityDefault: 'medium',
series: { styleGuide: { tense: 'past', povPerson: 'first' } },
planManuscriptChunks: async () => ['CHUNK_ONE', 'CHUNK_TWO'],
callStagedLLM: async () => ({ content: { findings: [] } }),
- callInlineLLM: async (_prompt, opts) => {
+ callStageScopedInlineLLM: async (stage, _prompt, opts) => {
+ stageSeen = stage;
source = opts?.source;
return { content: 'summary' };
},
});
expect(source).toBe(EDITORIAL_SETUP_DIGEST_SOURCE);
+ // Pinned to the same stage the findings call uses, so the summary call resolves
+ // the stage's provider rather than the active/cloud one.
+ expect(stageSeen).toBe('pipeline-editorial-style-conformance');
});
it('does not summarize a single-chunk run (no later chunk consumes it)', async () => {
@@ -840,7 +845,7 @@ describe('cross-chunk clean-setup digest (#1403)', () => {
series: { styleGuide: { tense: 'past', povPerson: 'first' } },
planManuscriptChunks: async () => ['ONLY_CHUNK'],
callStagedLLM: async (_stage, vars) => { seen.push(vars.manuscript); return { content: { findings: [] } }; },
- callInlineLLM: async () => { inlineCalls += 1; return { content: 'summary' }; },
+ callStageScopedInlineLLM: async () => { inlineCalls += 1; return { content: 'summary' }; },
});
expect(seen).toEqual(['ONLY_CHUNK']);
expect(inlineCalls).toBe(0);
@@ -857,7 +862,7 @@ describe('cross-chunk clean-setup digest (#1403)', () => {
});
it('degrades to findings-only when no inline LLM caller is injected (no setup digest, no crash)', async () => {
- // No callInlineLLM in ctx → the setup-summary path stays off entirely.
+ // No callStageScopedInlineLLM in ctx → the setup-summary path stays off entirely.
const seen = [];
await getCheck('style.conformance').run({
config: { maxFindings: 12 },
@@ -880,7 +885,7 @@ describe('cross-chunk clean-setup digest (#1403)', () => {
series: { styleGuide: { tense: 'past', povPerson: 'first' } },
planManuscriptChunks: async () => ['CHUNK_ONE', 'CHUNK_TWO', 'CHUNK_THREE'],
callStagedLLM: async () => ({ content: { findings: [] } }),
- callInlineLLM: async (prompt) => {
+ callStageScopedInlineLLM: async (_stage, prompt) => {
// Capture the "Setup recorded so far" section the prompt embedded.
const m = prompt.match(/# Setup recorded so far \(from earlier parts\)\n([\s\S]*?)\n\n# New manuscript part/);
priorSummariesSeen.push(m ? m[1] : '');
@@ -901,7 +906,7 @@ describe('cross-chunk clean-setup digest (#1403)', () => {
series: { styleGuide: { tense: 'past', povPerson: 'first' } },
planManuscriptChunks: async () => ['CHUNK_ONE', 'CHUNK_TWO'],
callStagedLLM: async (_stage, vars) => { seen.push(vars.manuscript); return { content: { findings: [] } }; },
- callInlineLLM: async () => { inlineCalls += 1; throw new Error('summarizer down'); },
+ callStageScopedInlineLLM: async () => { inlineCalls += 1; throw new Error('summarizer down'); },
});
// The summarizer was attempted but threw → no setup digest, and the run still
// processed both chunks to completion.
diff --git a/server/lib/stageRunner.js b/server/lib/stageRunner.js
index a088cbfcbb..bb32158535 100644
--- a/server/lib/stageRunner.js
+++ b/server/lib/stageRunner.js
@@ -281,6 +281,27 @@ export async function runInlineLLM(prompt, options = {}) {
return executeStagePrompt({ stage: null, label: options.source || 'inline-llm', prompt, options });
}
+/**
+ * Run a caller-supplied (inline) prompt but resolve the provider/model/timeout
+ * from a NAMED STAGE's pin — not just the active/overridden provider. Use this for
+ * an inline helper call that SUPPORTS a stage-pinned check (e.g. a cross-chunk
+ * setup summary for an editorial stage pinned to a private local provider): the
+ * helper then runs on the SAME provider as the stage, so manuscript text is never
+ * silently routed to a different (e.g. cloud) provider than the stage chose. The
+ * prompt body is still caller-supplied (no stage template is rendered). With a
+ * falsy `stageName` this is identical to `runInlineLLM` (active/overridden provider).
+ *
+ * Same options as runStagedLLM (providerOverride / modelOverride /
+ * timeoutOverride / returnsJson / source).
+ */
+export async function runStageScopedInlineLLM(stageName, prompt, options = {}) {
+ if (typeof prompt !== 'string' || !prompt.trim()) {
+ throw new ServerError('runStageScopedInlineLLM requires a non-empty prompt', { status: 400, code: 'INLINE_PROMPT_REQUIRED' });
+ }
+ const stage = stageName ? getStage(stageName) : null;
+ return executeStagePrompt({ stage, label: options.source || stageName || 'inline-llm', prompt, options });
+}
+
/**
* Shared execution body for runStagedLLM / runInlineLLM. Takes an already-built
* prompt + an optional resolved stage (null for inline), resolves the provider/
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.js
index ab168bef03..270f7754ab 100644
--- a/server/services/pipeline/editorial/checkRunner.js
+++ b/server/services/pipeline/editorial/checkRunner.js
@@ -17,7 +17,7 @@
import { randomUUID, createHash } from 'crypto';
import { createSseRunner } from '../../../lib/sseUtils.js';
-import { runStagedLLM, runInlineLLM, resolveStageContext } from '../../../lib/stageRunner.js';
+import { runStagedLLM, runInlineLLM, runStageScopedInlineLLM, resolveStageContext } from '../../../lib/stageRunner.js';
import { planManuscriptPass } from '../../../lib/contextBudget.js';
import { getEnabledChecks, getEnabledCheckRows, getAllChecks, EDITORIAL_SOURCES } from '../../../lib/editorial/index.js';
import { getSettings } from '../../settings.js';
@@ -167,6 +167,13 @@ export async function runEditorialChecks(seriesId, options = {}) {
// model overrides as callStagedLLM so a custom check honors the run's choice.
callInlineLLM: (prompt, opts = {}) =>
runInlineLLM(prompt, { providerOverride, modelOverride, ...opts }),
+ // Inline-prompt caller that resolves the provider/model from a NAMED STAGE's
+ // pin (#1403). The cross-chunk setup-summary call rides alongside a stage-
+ // pinned manuscript check, so it must run on the SAME provider as that stage —
+ // routing it through the active provider (plain callInlineLLM) could leak
+ // manuscript text to a different (e.g. cloud) provider than the stage chose.
+ callStageScopedInlineLLM: (stage, prompt, opts = {}) =>
+ runStageScopedInlineLLM(stage, prompt, { providerOverride, modelOverride, ...opts }),
// Injected manuscript chunker — plans the stitched manuscript into chunks
// sized to `stage`'s resolved provider context window (reusing the same
// budgeter as the completeness pass), so a long series is fully reviewed