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
fix: reserve setup digest from raw manuscript and guard against over-window digests (#1667)
[._.]/ Adam Eivy48625ea0c12a
diff --git a/server/lib/editorial/checkRegistry.js b/server/lib/editorial/checkRegistry.jsindex b322595735..1286bc54aa 100644--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@ -1142,9 +1142,11 @@ export function buildSetupDigestPrompt({ focus, priorSummary, manuscript }) {// so a final chunk packed to within a few hundred chars of the window silently// drops the digest and the final-only finding is missed. When this opt-in is set// and the digest doesn't fit the final chunk's spare room, the manuscript TAIL is-// trimmed by the digest's size (the inverse of the usual yield) so the verdict-// keeps its carried context. Scoped to the final chunk and to opt-in checks only —-// every other chunk, and every non-reserving check, keeps full manuscript coverage.+// trimmed to reserve the digest's room (the inverse of the usual yield) so the+// verdict keeps its carried context. Scoped to the final chunk and to opt-in checks+// only — every other chunk, and every non-reserving check, keeps full manuscript+// coverage. If the digest alone is larger than the whole window it still yields+// (never prepended past the budget), preserving the no-overflow contract.async function runChunkedManuscriptCheck(ctx, { chunks, category, max, callChunk, crossChunkDigest = false, summarizeChunk = null, reserveSetupDigest = false }) {const usableChars = Number.isFinite(chunks?.usableChars) ? chunks.usableChars : Infinity;const merged = new Map();@@ -1178,14 +1180,18 @@ async function runChunkedManuscriptCheck(ctx, { chunks, category, max, callChunk// Fits into whatever spare room remains AFTER the findings digest — manuscript// coverage and the findings digest both win over the setup digest if budget is tight.text = `${setup}${text}`;- } else if (setup && reserveSetupDigest && isFinal && Number.isFinite(usableChars)) {+ } else if (setup && reserveSetupDigest && isFinal && setup.length <= usableChars) {// #1667: the digest didn't fit, but this check gates its verdict to the final- // part and anchors it on the carried snippet — so trim the manuscript tail to- // make room rather than drop the carried context. Slicing `text` (findings- // digest + manuscript) from the end keeps the higher-value front (the findings- // digest and the manuscript head) and total stays at exactly `usableChars`.- const room = Math.max(0, usableChars - setup.length);- text = `${setup}${text.slice(0, room)}`;+ // part and anchors it on the carried snippet — so reserve the digest's room and+ // fill the rest with the manuscript HEAD (trimming its tail) rather than drop+ // the carried context. Rebuild from the RAW `manuscript`, NOT the+ // findings-digest-prefixed `text`: slicing `text` could truncate the findings+ // digest mid-block into a malformed prefix, and the findings digest's job+ // (suppressing duplicate re-flags) is already covered by the first-wins merge,+ // so it safely yields here. Gated on `setup.length <= usableChars` so a digest+ // larger than the whole window yields instead of overflowing it — preserving+ // the pre-reserve no-overflow contract on a tiny/high-overhead window.+ text = `${setup}${manuscript.slice(0, usableChars - setup.length)}`;}}const content = await callChunk(text, { isFinal });diff --git a/server/lib/editorial/checkRegistry.test.js b/server/lib/editorial/checkRegistry.test.jsindex f2d8847546..9fac5cdf66 100644--- a/server/lib/editorial/checkRegistry.test.js+++ b/server/lib/editorial/checkRegistry.test.js@@ -3408,6 +3408,51 @@ describe('cross-chunk clean-setup digest (#1403)', () => {expect(seen[1]).not.toContain('Setup already established in EARLIER parts');});+ it('yields (no overflow) when the setup digest alone is larger than the whole window, even for an opt-in check (#1667)', async () => {+ const digest = editorialSetupDigest('- SETUP: past tense, first person');+ const usableChars = digest.length - 5; // even the digest alone overflows the window+ const { seen } = await runTwoChunksWithSetup('arc.climax-agency', {}, { usableChars });+ // A digest that can't fit the window at all must not be prepended — fall back to+ // the manuscript chunk untouched rather than send an over-budget prompt.+ expect(seen[1]).toBe('CHUNK_TWO');+ expect(seen[1]).not.toContain('Setup already established in EARLIER parts');+ });++ it('reserves from the RAW manuscript so a prepended findings digest is never truncated mid-block (#1667)', async () => {+ const setupDigest = editorialSetupDigest('- SETUP: past tense, first person');+ // A finding from the first chunk produces a findings digest carried into the final+ // chunk; size the window so the findings digest fits there but the setup digest+ // doesn't, forcing the reserve branch.+ const findingsDigest = editorialPriorFindingsDigest([{ category: 'arc', problem: 'passive climax', issueNumber: 1, location: '' }]);+ const usableChars = setupDigest.length + findingsDigest.length + 2;+ const seen = [];+ let call = 0;+ await getCheck('arc.climax-agency').run({+ config: { maxFindings: 12 },+ severityDefault: 'medium',+ planManuscriptChunks: async () => {+ const chunks = ['CHUNK_ONE', 'CHUNK_TWO'];+ chunks.usableChars = usableChars;+ return chunks;+ },+ callStagedLLM: async (_stage, vars) => {+ seen.push(vars.manuscript);+ call += 1;+ // First chunk emits a finding so the final chunk carries a findings digest.+ return call === 1+ ? { content: { findings: [{ problem: 'passive climax', severity: 'medium', issueNumber: 1 }] } }+ : { content: { findings: [] } };+ },+ callStageScopedInlineLLM: async () => ({ content: '- SETUP: past tense, first person' }),+ });+ // Final chunk: setup digest guaranteed + the manuscript head, rebuilt from the raw+ // manuscript — so the findings digest is dropped whole, never sliced into a+ // malformed fragment (the old `text.slice` would have emitted a partial header).+ expect(seen[1]).toBe(`${setupDigest}CHUNK_TWO`);+ expect(seen[1]).not.toContain('Editorial findings already recorded');+ expect(seen[1].length).toBeLessThanOrEqual(usableChars);+ });+it('only reserves on the FINAL chunk — a non-final chunk still yields the digest to manuscript coverage (#1667)', async () => {const digest = editorialSetupDigest('- SETUP: past tense, first person');const seen = [];