Fix PGCR route decode for plain JSON storage (API-1N) - #149
Merged
Conversation
Services stores uncompressed JSON in pgcr; always gunzipSync caused incorrect header check errors on /pgcr/:instanceId. Co-authored-by: Cursor <cursoragent@cursor.com>
Barecheck - Code coverage reportTotal: 91.52%Your code coverage diff: 0.01% ▴ ✅ All code changes are covered |
Comment on lines
+12
to
+16
| export function decodePgcrPayload(data: Buffer): string { | ||
| if (isGzipCompressed(data)) { | ||
| return decoder.decode(gunzipSync(data)) | ||
| } | ||
| return decoder.decode(data) |
There was a problem hiding this comment.
Bug: The code expects a Buffer from the BYTEA database column but receives a string. Passing this string to TextDecoder.decode() will cause a TypeError at runtime.
Severity: CRITICAL
Suggested Fix
Configure a type parser for the BYTEA type (OID 17) in src/integrations/postgres/parsers.ts. This will ensure that BYTEA columns are correctly parsed into Buffer objects, matching the expected data: Buffer type annotation and preventing the runtime error.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: src/services/pgcr.ts#L12-L16
Potential issue: The `getRawCompressedPGCR` function expects the `BYTEA` data column
from the database to be a `Buffer`. However, the `node-postgres` driver is not
configured with a type parser for `BYTEA` columns (type 17), so it returns a
backslash-escaped string by default. This string is passed to `decodePgcrPayload`, which
then calls `TextDecoder.decode()`. Since `TextDecoder.decode()` does not accept a
string, it will throw a `TypeError`, causing a runtime crash whenever the application
attempts to retrieve a plain JSON PGCR.
Also affects:
src/integrations/postgres/parsers.tssrc/services/pgcr.ts:20-23
Did we get this right? 👍 / 👎 to inform future reviews.
owens1127
marked this pull request as draft
June 23, 2026 23:58
owens1127
marked this pull request as ready for review
June 23, 2026 23:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
API-1N(incorrect header checkon/pgcr/:instanceId) by detecting gzip magic bytes before decompressingStoreRawJSONwrites plain JSON topgcr; legacyraw.pgcrrows remain gzip — matcheslog-raw-pgcrbehaviorTest plan
bun test src/services/pgcr.test.ts/pgcr/<instanceId>for a known stored PGCRFixes API-1N
Made with Cursor