mirror of
https://github.com/coder/coder.git
synced 2026-10-30 18:12:29 +08:00
PostgreSQL jsonb rejects \u0000, so persisting Gemini responses failed with "pq: unsupported Unicode escape sequence": binary thought signatures reach ProviderMetadata as strings containing NUL, and the sentinel codec only covered six fields. Real recorded Gemini signatures contain NUL in 22 of 34 cases. Classify every string-bearing part field in one table, partNulFields. Free-form and opaque fields encode NUL reversibly as PUA sentinel pairs; structured fields (identifiers, paths, URLs) reject it with an error naming the part, field, and offset, since their consumers cannot handle NUL anyway. Raw JSON is also normalized for lone surrogate escapes, which jsonb equally rejects. A reflection-driven test injects NUL into every field and fails when a future field is missing from the table. The Gemini regression asserts the sentinel-encoded row in the database and a byte-exact signature round-trip. Known limits: json.Marshal corrupts other invalid UTF-8 upstream of this codec (CODAGT-986), and chat debug steps have always dropped silently on NUL prompt text (CODAGT-987, pre-existing). Fixes coder/coder#25555 Fixes CODAGT-463