Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Wave B 1b-i: body scan uses a fresh decoder for the head

garrytan1b36dec8732a
diff --git a/src/core/page-body/body-scan.ts b/src/core/page-body/body-scan.ts
index 842949dca9..fbd308dbf9 100644
--- a/src/core/page-body/body-scan.ts
+++ b/src/core/page-body/body-scan.ts
@@ -254,7 +254,7 @@ export class BodyScanner {
const headBytes = complete ? all : all.subarray(0, FRONTMATTER_HEAD_MAX_BYTES);
let text: string;
try {
- text = this.decoder.decode(headBytes, { stream: !complete });
+ text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(headBytes, { stream: !complete });
} catch {
this.refusal = { kind: 'invalid_utf8', offset: firstInvalidUtf8(headBytes, complete) };
return;
diff --git a/test/large-pages/body-scan.test.ts b/test/large-pages/body-scan.test.ts
index b52b857365..7f5447c8ac 100644
--- a/test/large-pages/body-scan.test.ts
+++ b/test/large-pages/body-scan.test.ts
@@ -159,9 +159,9 @@ describe('body scan on files larger than the head bound', () => {
return;
}
expectAgrees(content, 'notes/x.md', { validate });
- }), { numRuns: 120 });
- expect(refused).toBeLessThan(120);
- });
+ }), { numRuns: 80 });
+ expect(refused).toBeLessThan(80);
+ }, 120_000);
const pad = (line: string) => `${line}\n`.repeat(Math.ceil((FRONTMATTER_HEAD_MAX_BYTES + 1000) / (line.length + 1)));
@@ -229,7 +229,7 @@ describe('chunking', () => {
const small = sizes.map(s => (large ? s : Math.max(1, s % 17)));
expect(capture(() => scanChunks(bytes, small))).toEqual(whole);
}), { numRuns: 200 });
- });
+ }, 120_000);
test('the async form equals the push form, and pieces read back from the file', async () => {
const content = `---\ntitle: Alpha Example\n---\nintro 😀\n${'line\n'.repeat(70_000)}<!-- timeline -->\n- 2024: t\n`;