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

refactor(issue-1340): tidy chunk-cap and document overhead accounting

[._.]/ Adam Eivya8d9aa570b26
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index e601cc9235..4987f3e024 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -226,6 +226,12 @@ export function mergeChunkFindings(lists, max = Infinity) {
// returns the stage vars — only the manuscript var changes per chunk. These
// checks are all manuscript-scoped, so findings keep a model-supplied issue
// number (`withIssueNumber: true`).
+//
+// `overheadTokens` MUST account for every non-manuscript prompt var the check
+// re-sends on each chunk (the objects summary, the style-guide expectations,
+// etc.) on top of EDITORIAL_PROMPT_OVERHEAD_TOKENS — those vars ride alongside
+// the chunked manuscript, so under-counting them lets a chunk overrun the
+// provider window.
async function runManuscriptLlmCheck(ctx, { stage, category, overheadTokens = 0, buildVars }) {
const max = ctx.config?.maxFindings ?? 12;
const chunks = await ctx.planManuscriptChunks(stage, { overheadTokens });
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.js
index a3b550c359..b63edab673 100644
--- a/server/services/pipeline/editorial/checkRunner.js
+++ b/server/services/pipeline/editorial/checkRunner.js
@@ -89,8 +89,11 @@ export async function runEditorialChecks(seriesId, options = {}) {
sections: sections.map((s) => ({ ...s, text: `${manuscriptSectionHeader(s)}\n\n${s.content || ''}` })),
overheadTokens,
});
- if (plan.mode === 'whole') return [manuscript.slice(0, plan.usableChars)];
- return plan.chunks.map((c) => sectionsCorpus(c.sections).slice(0, plan.usableChars));
+ // One whole chunk or many — the same usable-char cap applies to each.
+ const corpora = plan.mode === 'whole'
+ ? [manuscript]
+ : plan.chunks.map((c) => sectionsCorpus(c.sections));
+ return corpora.map((c) => c.slice(0, plan.usableChars));
},
};