fix(memory-ingest): strip NUL bytes from transcript body before put

Postgres rejects 0x00 in UTF-8 text columns. Some Claude Code transcripts
contain NUL inside user-pasted content or tool output, and surfacing those
as `internal_error: invalid byte sequence` from the brain is unhelpful when
we can sanitize at write time.

Uses the \x00 escape form in the regex literal so the source survives
editors that strip control chars and remains reviewable in diffs.

Contributed by @billy-armstrong (#1411).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-05-10 11:05:27 -07:00
parent 79f7a24eb4
commit 68038cc604
+5
View File
@@ -819,6 +819,11 @@ function gbrainPutPage(page: PageRecord): { ok: boolean; error?: string } {
body,
].join("\n");
}
// Strip NUL bytes — Postgres rejects 0x00 in UTF-8 text columns. Some Claude
// Code transcripts contain NUL inside user-pasted content or tool output, and
// surfacing those as `internal_error: invalid byte sequence` from the brain
// is unhelpful when we can sanitize at write time.
body = body.replace(/\x00/g, "");
try {
execFileSync("gbrain", ["put", page.slug], {
input: body,