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): cap only the digest body so the --- separator always survives (#1383)

[._.]/ Adam Eivy106be6ec96b2
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.js
index 8bc768636e..a99093b10e 100644
--- a/server/lib/editorial/checkRegistry.js
+++ b/server/lib/editorial/checkRegistry.js
@@ -219,10 +219,22 @@ export const editorialFindingKey = (f) => [
// These constants bound the rolling digest of prior-chunk findings fed to later
// chunks so it stays small enough to ride in the chunk's spare budget.
export const EDITORIAL_PRIOR_DIGEST_MAX = 40;
-export const EDITORIAL_PRIOR_DIGEST_CHARS = 2_400;
+// Only the findings BODY is capped — the fixed header and the trailing `---`
+// delimiter are always added AFTER the cap (the next manuscript chunk is
+// concatenated right after the digest, so the delimiter MUST survive or the
+// manuscript bleeds into the "already recorded" list).
+export const EDITORIAL_PRIOR_DIGEST_BODY_CHARS = 2_000;
+const EDITORIAL_PRIOR_DIGEST_HEADER = '# Editorial findings already recorded for EARLIER parts of this manuscript\n'
+ + 'Do not repeat these. Flag only NEW problems in the text below, plus any cross-chapter '
+ + '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.
+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 (the digest string is capped to
-// EDITORIAL_PRIOR_DIGEST_CHARS, so this reserve is an exact upper bound).
+// 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
@@ -237,11 +249,10 @@ export function editorialPriorFindingsDigest(findings) {
});
const more = findings.length > EDITORIAL_PRIOR_DIGEST_MAX
? `\n(+${findings.length - EDITORIAL_PRIOR_DIGEST_MAX} more earlier findings)` : '';
- const header = '# Editorial findings already recorded for EARLIER parts of this manuscript\n'
- + 'Do not repeat these. Flag only NEW problems in the text below, plus any cross-chapter '
- + 'continuity these earlier findings reveal (e.g. an object set up earlier, or a tense/POV '
- + 'choice established in an earlier chapter).\n\n';
- return `${header}${lines.join('\n')}${more}\n\n---\n\n`.slice(0, EDITORIAL_PRIOR_DIGEST_CHARS);
+ // Cap the body only — the header and the trailing `---` separator are appended
+ // afterwards so they always survive (see EDITORIAL_PRIOR_DIGEST_BODY_CHARS).
+ const body = `${lines.join('\n')}${more}`.slice(0, EDITORIAL_PRIOR_DIGEST_BODY_CHARS);
+ return `${EDITORIAL_PRIOR_DIGEST_HEADER}${body}${EDITORIAL_PRIOR_DIGEST_SEPARATOR}`;
}
// Shared chunk loop for the manuscript-consuming LLM checks: run `callChunk` on
diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.js
index 4fb908a770..34c43e6a96 100644
--- a/server/lib/editorial/checkRegistry.test.js
+++ b/server/lib/editorial/checkRegistry.test.js
@@ -576,6 +576,20 @@ describe('cross-chunk continuity digest (#1383)', () => {
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', () => {
+ // The next manuscript chunk is concatenated right after the digest, so the
+ // delimiter must survive truncation or the manuscript bleeds into the
+ // "already recorded" list (codex P2).
+ 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.endsWith('\n\n---\n\n')).toBe(true);
+ expect(digest.startsWith('# Editorial findings already recorded')).toBe(true);
+ // A following chunk stays clearly separated from the digest body.
+ expect(`${digest}NEXT_CHUNK`).toContain('---\n\nNEXT_CHUNK');
+ });
});
// A check that opts into the digest prefixes every chunk AFTER the first with a