From 68038cc6046198f0a5847e01a03a15343641ed64 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sun, 10 May 2026 11:05:27 -0700 Subject: [PATCH] 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) --- bin/gstack-memory-ingest.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/gstack-memory-ingest.ts b/bin/gstack-memory-ingest.ts index 56b072b2b..e6934ae45 100644 --- a/bin/gstack-memory-ingest.ts +++ b/bin/gstack-memory-ingest.ts @@ -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,