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): size the editorial chunk output reserve + floor the slice
[._.]/ Adam Eivyc2725a2eecdc
diff --git a/server/services/pipeline/editorial/checkRunner.js b/server/services/pipeline/editorial/checkRunner.jsindex b63edab673..ba0a74b1ff 100644--- a/server/services/pipeline/editorial/checkRunner.js+++ b/server/services/pipeline/editorial/checkRunner.js@@ -27,6 +27,20 @@ import { getSeriesCanon } from '../seriesCanon.js';import { collectManuscriptSections, sectionsCorpus, manuscriptSectionHeader } from '../arcPlanner.js';import { seedReviewFromFindings } from '../manuscriptReview.js';+// Output room reserved for an editorial check's findings JSON. Sized for the+// editorial output (a bounded findings list — far smaller than the completeness+// pass's full-page rewrites), NOT the 8_000-token contextBudget default: that+// default exceeds the 8_192-token fallback window, so inheriting it would drive+// the usable input budget to 0 on an unknown/small local provider — the exact+// case this chunking targets — and silently feed the model an empty manuscript.+const EDITORIAL_OUTPUT_RESERVE_TOKENS = 2_000;++// Floor on the per-chunk manuscript slice. Guarantees a chunk is never empty even+// when a pathologically small window (or a large static-var overhead) would leave+// a zero/negative input budget — reviewing a truncated slice beats reviewing+// nothing. On a healthy window usableChars far exceeds this, so it never bites.+const MIN_EDITORIAL_CHUNK_CHARS = 4_000;+/*** Run the enabled editorial checks for a series and seed their findings into the* manuscript review.@@ -88,12 +102,15 @@ export async function runEditorialChecks(seriesId, options = {}) {// Each section's full contribution = header + body, matching sectionsCorpus.sections: sections.map((s) => ({ ...s, text: `${manuscriptSectionHeader(s)}\n\n${s.content || ''}` })),overheadTokens,+ outputReserveTokens: EDITORIAL_OUTPUT_RESERVE_TOKENS,});- // One whole chunk or many — the same usable-char cap applies to each.+ // One whole chunk or many — the same usable-char cap applies to each,+ // floored so a tiny window can never slice a chunk down to the empty string.+ const cap = Math.max(plan.usableChars, MIN_EDITORIAL_CHUNK_CHARS);const corpora = plan.mode === 'whole'? [manuscript]: plan.chunks.map((c) => sectionsCorpus(c.sections));- return corpora.map((c) => c.slice(0, plan.usableChars));+ return corpora.map((c) => c.slice(0, cap));},};diff --git a/server/services/pipeline/editorial/checkRunner.test.js b/server/services/pipeline/editorial/checkRunner.test.jsindex d805e797e8..06d5feaf34 100644--- a/server/services/pipeline/editorial/checkRunner.test.js+++ b/server/services/pipeline/editorial/checkRunner.test.js@@ -149,7 +149,7 @@ describe('runEditorialChecks', () => {{ number: 2, title: 'Two', stageId: 'prose', content: big('SEC2') },{ number: 3, title: 'Three', stageId: 'prose', content: big('SEC3') },]);- resolveStageContext.mockResolvedValueOnce({ provider: { type: 'api', endpoint: 'http://localhost:11434' }, model: 'm', contextWindow: 15_000 });+ resolveStageContext.mockResolvedValueOnce({ provider: { type: 'api', endpoint: 'http://localhost:11434' }, model: 'm', contextWindow: 10_000 });await runEditorialChecks('s1', { checkIds: ['prose.info-dumping'] });@@ -162,6 +162,19 @@ describe('runEditorialChecks', () => {expect(allSent).toContain('SEC3');});+ it('still sends a non-empty manuscript on a small/fallback context window (issue #1340)', async () => {+ // An unknown local provider falls back to the 8K window. With the contextBudget+ // default 8K output reserve this would leave a 0-char input budget and feed the+ // model an empty manuscript — the editorial reserve + floor must prevent that.+ resolveStageContext.mockResolvedValueOnce({ provider: { type: 'api', endpoint: 'http://localhost:1234' }, model: 'm', contextWindow: 8_192 });+ let sent = null;+ runStagedLLM.mockImplementationOnce(async (_stage, vars) => { sent = vars.manuscript; return { content: { findings: [] } }; });+ await runEditorialChecks('s1', { checkIds: ['prose.info-dumping'] });+ expect(sent).toBeTruthy();+ expect(sent.trim().length).toBeGreaterThan(0);+ expect(sent).toContain('kingdom fell'); // the actual section content, not an empty slice+ });+it('one failing check does not abort the pass', async () => {// Make info-dumping the only enabled LLM check so the single rejection lands// on it (the object LLM checks would otherwise consume the mockRejectedOnce).