Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(transcripts): part target stays under the content-sanity warn line (#5427)
Ziyang Guoc3daef37682d
diff --git a/src/core/transcripts/render.ts b/src/core/transcripts/render.tsindex 63fd2f2285..0aca2a0da2 100644--- a/src/core/transcripts/render.ts+++ b/src/core/transcripts/render.ts@@ -30,7 +30,7 @@import { safeDump } from 'js-yaml';import { homedir } from 'node:os';import { join } from 'node:path';-import { DEFAULT_BYTES_BLOCK } from '../content-sanity.ts';+import { DEFAULT_BYTES_WARN } from '../content-sanity.ts';import { applyRedaction, planRedaction, type EchoDictionary, type RedactionPlan } from '../secret-scan.ts';import { loadPatterns } from '../skillpack/harvest-lint.ts';import { sanitizeForJsonb } from '../batch-rows.ts';@@ -60,8 +60,18 @@ export const MESSAGE_CHAR_CAP = 4000;* would import as a zero-chunk, unsearchable page, defeating the split.* (Operators can lower the threshold via config; the 0.6 factor leaves* headroom for frontmatter overhead and modest overrides.)+ *+ * #5427: with the prior `min(300KB, floor(BLOCK * 0.6))` shape, the target+ * landed at 300KB — six times the content-sanity WARN line (50KB). Every+ * transcript-import part between 50KB and 300KB therefore took the+ * content-sanity warn branch (`oversize_warn` audit row + stderr+ * `exceeds warn threshold, consider splitting` — pointing at the very+ * splitter that produced the page) on every re-ingest, drowning the doctor+ * recent-events signal. The block tier stays untouched (the hard floor for+ * the no-zero-chunk invariant). The 0.9 headroom against WARN gives the+ * part header + OVERLAP_MESSAGES duplicates room to breathe.*/-export const PART_TARGET_BYTES = Math.min(300 * 1024, Math.floor(DEFAULT_BYTES_BLOCK * 0.6));+export const PART_TARGET_BYTES = Math.floor(DEFAULT_BYTES_WARN * 0.9);/** Messages repeated at each part boundary for cross-part fact grounding. */export const OVERLAP_MESSAGES = 2;diff --git a/test/transcript-render.test.ts b/test/transcript-render.test.tsindex c757641ee8..cbf77f174b 100644--- a/test/transcript-render.test.ts+++ b/test/transcript-render.test.ts@@ -16,6 +16,7 @@ import {redactSession,renderSessionParts,} from '../src/core/transcripts/render.ts';+import { DEFAULT_BYTES_WARN } from '../src/core/content-sanity.ts';import { parseConversation } from '../src/core/conversation-parser/parse.ts';import { FACTS_FENCE_BEGIN, FACTS_FENCE_END, parseFactsFence, stripFactsFence } from '../src/core/facts-fence.ts';import { TAKES_FENCE_BEGIN, parseTakesFence } from '../src/core/takes-fence.ts';@@ -277,6 +278,34 @@ describe('part splitting [embed-skip is the binding limit]', () => {expect(p2Body.startsWith(p1LastAnchor as string)).toBe(true);});+ // #5427: PART_TARGET_BYTES must stay under the content-sanity WARN line.+ // The prior `min(300KB, floor(BLOCK * 0.6))` shape landed at 300KB — six+ // times DEFAULT_BYTES_WARN (50KB) — so every transcript part between 50KB+ // and 300KB took the warn branch (`oversize_warn` audit row + stderr+ // noise pointing at the very splitter that produced the page) on every+ // re-ingest. The block tier stays untouched (the no-zero-chunk invariant).+ test('PART_TARGET_BYTES stays under the content-sanity warn line (#5427)', () => {+ expect(PART_TARGET_BYTES).toBeLessThan(DEFAULT_BYTES_WARN);+ });++ test('a session split at the new target produces no oversize_warn part (#5427)', async () => {+ // Each message is ~1KB; 80 messages (~80KB) used to fit one 80KB part+ // — well under the old 300KB target, but the part then triggered the+ // 50KB WARN branch on every re-ingest. With the new ~45KB target the+ // session now splits into ≥2 parts and each part stays below WARN.+ const chunk = 'x'.repeat(900);+ const msgs = Array.from({ length: 80 }, (_, i) => ({+ role: (i % 2 === 0 ? 'user' : 'assistant') as 'user' | 'assistant',+ timestamp: `2026-08-02T09:${String(Math.floor(i / 60)).padStart(2, '0')}:${String(i % 60).padStart(2, '0')}.000Z`,+ text: `m${i} ${chunk}`,+ }));+ const r = renderSessionParts(redactSession(session(msgs), { userPatternsPath: '/nonexistent' }));+ expect(r.parts.length).toBeGreaterThan(1);+ for (const p of r.parts) {+ expect(Buffer.byteLength(splitBody(p.content), 'utf8')).toBeLessThan(DEFAULT_BYTES_WARN);+ }+ });+test('sessions with zero timestamps are refused (never fabricate provenance)', () => {const noTs = session([{ role: 'user', timestamp: '', text: 'hello' }],