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): ride the digest in the safety margin instead of reserving budget (#1383)

[._.]/ Adam Eivy780479181f04
diff --git a/server/lib/editorial/README.md b/server/lib/editorial/README.md
index b12641915c..193c5fe41d 100644
--- a/server/lib/editorial/README.md
+++ b/server/lib/editorial/README.md
@@ -21,8 +21,10 @@ Checks whose problems span chapters can opt into a **cross-chunk continuity
digest** (#1383): pass `crossChunkDigest: true` to `runManuscriptLlmCheck` and
each chunk after the first is prefixed with `editorialPriorFindingsDigest` of the
findings gathered so far (it rides INSIDE the manuscript var, so no prompt
-template change). The chunk planner reserves `EDITORIAL_PRIOR_DIGEST_TOKENS` for
-it. `style.conformance` (tense/POV established earlier) and
+template change). The digest body is capped (`EDITORIAL_PRIOR_DIGEST_CHARS`) so it
+rides in the budgeter's safety margin rather than reserving a slice of the usable
+budget — which would needlessly truncate the first/only chunk that carries no
+digest. `style.conformance` (tense/POV established earlier) and
`objects.unmotivated-interaction` (setup/payoff across chapters) opt in;
`prose.info-dumping` stays per-chunk (its problems are localized).
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index a99093b10e..ec36375757 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -25,7 +25,7 @@
*/
import { z } from 'zod';
-import { estimateTokens, CHARS_PER_TOKEN } from '../contextBudget.js';
+import { estimateTokens } from '../contextBudget.js';
export const CHECK_SCOPES = Object.freeze(['series', 'issue', 'scene', 'noun']);
export const CHECK_KINDS = Object.freeze(['deterministic', 'llm']);
@@ -229,13 +229,11 @@ const EDITORIAL_PRIOR_DIGEST_HEADER = '# Editorial findings already recorded for
+ 'continuity these earlier findings reveal (e.g. an object set up earlier, or a tense/POV '
+ 'choice established in an earlier chapter).\n\n';
const EDITORIAL_PRIOR_DIGEST_SEPARATOR = '\n\n---\n\n';
-// Whole-digest char ceiling = fixed wrapper + capped body, so the token reserve
-// below is an exact upper bound on what gets prepended to a chunk.
+// Whole-digest char ceiling = fixed wrapper + capped body. Kept small enough to
+// ride inside the budgeter's safety margin rather than reserving a slice of the
+// usable budget (see runManuscriptLlmCheck).
export const EDITORIAL_PRIOR_DIGEST_CHARS =
EDITORIAL_PRIOR_DIGEST_HEADER.length + EDITORIAL_PRIOR_DIGEST_BODY_CHARS + EDITORIAL_PRIOR_DIGEST_SEPARATOR.length;
-// Token budget the chunk planner reserves for the digest so prepending it can't
-// push a chunk over the provider window.
-export const EDITORIAL_PRIOR_DIGEST_TOKENS = Math.ceil(EDITORIAL_PRIOR_DIGEST_CHARS / CHARS_PER_TOKEN);
// One-block digest of findings already recorded for earlier chunks, prepended
// INSIDE the next chunk's manuscript var so no prompt template changes (mirrors
@@ -300,11 +298,12 @@ async function runChunkedManuscriptCheck(ctx, { chunks, category, max, callChunk
// provider window.
async function runManuscriptLlmCheck(ctx, { stage, category, overheadTokens = 0, buildVars, crossChunkDigest = false }) {
const max = ctx.config?.maxFindings ?? 12;
- // Reserve room for the prior-findings digest later chunks ride so prepending
- // it can't push a chunk over the provider window (only when this check opts in).
- const chunks = await ctx.planManuscriptChunks(stage, {
- overheadTokens: overheadTokens + (crossChunkDigest ? EDITORIAL_PRIOR_DIGEST_TOKENS : 0),
- });
+ // No extra digest reserve here: the digest is only prepended to chunks AFTER
+ // the first, but the planner's usableChars budget is uniform across chunks —
+ // reserving would needlessly truncate the first/only chunk (which carries no
+ // digest). The digest body is capped (EDITORIAL_PRIOR_DIGEST_CHARS) to ride in
+ // the budgeter's safety margin instead, mirroring completenessPass.
+ const chunks = await ctx.planManuscriptChunks(stage, { overheadTokens });
return runChunkedManuscriptCheck(ctx, {
chunks,
category,
diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.js
index 34c43e6a96..d5044b51b8 100644
--- a/server/lib/editorial/checkRegistry.test.js
+++ b/server/lib/editorial/checkRegistry.test.js
@@ -21,7 +21,6 @@ import {
editorialPriorFindingsDigest,
EDITORIAL_PRIOR_DIGEST_MAX,
EDITORIAL_PRIOR_DIGEST_CHARS,
- EDITORIAL_PRIOR_DIGEST_TOKENS,
} from './checkRegistry.js';
const NAMING = 'naming.dissimilar-names';
@@ -568,13 +567,12 @@ describe('cross-chunk continuity digest (#1383)', () => {
expect(digest).toMatch(/\(\+5 more earlier findings\)/);
});
- it('caps the whole digest to EDITORIAL_PRIOR_DIGEST_CHARS so the reserve is an exact upper bound', () => {
+ it('caps the whole digest to EDITORIAL_PRIOR_DIGEST_CHARS so it stays within the safety margin', () => {
const huge = Array.from({ length: EDITORIAL_PRIOR_DIGEST_MAX }, (_, i) => ({
issueNumber: i + 1, category: 'continuity', problem: 'x'.repeat(500),
}));
const digest = editorialPriorFindingsDigest(huge);
expect(digest.length).toBeLessThanOrEqual(EDITORIAL_PRIOR_DIGEST_CHARS);
- expect(EDITORIAL_PRIOR_DIGEST_TOKENS * 4).toBeGreaterThanOrEqual(EDITORIAL_PRIOR_DIGEST_CHARS);
});
it('keeps the trailing --- separator intact even when the body overflows the cap', () => {
@@ -625,8 +623,10 @@ describe('cross-chunk continuity digest (#1383)', () => {
expect(seen[1]).toContain('EARLIER parts of this manuscript');
expect(seen[1]).toContain('tense slip in chapter one');
expect(seen[1].endsWith('CHUNK_TWO')).toBe(true);
- // The digest reserve is folded into the chunk-planner overhead.
- expect(overhead).toBeGreaterThanOrEqual(EDITORIAL_PRIOR_DIGEST_TOKENS);
+ // The style-guide expectations are budgeted as prompt overhead; the digest is
+ // NOT reserved (it rides the safety margin, so the first/only chunk keeps its
+ // full budget).
+ expect(overhead).toBeGreaterThan(0);
});
it('objects.unmotivated-interaction feeds the prior-chunk digest to later chunks', async () => {