fix: use null-byte delimiter in observation content hash to prevent collisions

Fields concatenated without separators allowed different tuples to produce
identical hashes (e.g. session="ab", title="cd" vs session="abc", title="d").
This could cause legitimate observations to be silently deduplicated.

Join with \x00 so field boundaries are unambiguous.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
79475432@qq.com
2026-03-26 17:16:17 +08:00
parent e2a230286d
commit 9cfa57d498
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ export function computeObservationContentHash(
narrative: string | null
): string {
return createHash('sha256')
.update((memorySessionId || '') + (title || '') + (narrative || ''))
.update([memorySessionId || '', title || '', narrative || ''].join('\x00'))
.digest('hex')
.slice(0, 16);
}