Skip to content

Fix PGCR route decode for plain JSON storage (API-1N) - #149

Merged
owens1127 merged 1 commit into
mainfrom
fix-sentry-api-pgcr-decompress
Jun 23, 2026
Merged

Fix PGCR route decode for plain JSON storage (API-1N)#149
owens1127 merged 1 commit into
mainfrom
fix-sentry-api-pgcr-decompress

Conversation

@owens1127

Copy link
Copy Markdown
Contributor

Summary

  • Fixes API-1N (incorrect header check on /pgcr/:instanceId) by detecting gzip magic bytes before decompressing
  • Services StoreRawJSON writes plain JSON to pgcr; legacy raw.pgcr rows remain gzip — matches log-raw-pgcr behavior
  • Adds unit tests for both gzip and plain JSON payloads

Test plan

  • bun test src/services/pgcr.test.ts
  • CI green
  • After deploy: spot-check /pgcr/<instanceId> for a known stored PGCR

Fixes API-1N

Made with Cursor

Services stores uncompressed JSON in pgcr; always gunzipSync caused incorrect header check errors on /pgcr/:instanceId.

Co-authored-by: Cursor <cursoragent@cursor.com>
@barecheck

barecheck Bot commented Jun 23, 2026

Copy link
Copy Markdown

Barecheck - Code coverage report

Total: 91.52%

Your code coverage diff: 0.01% ▴

✅ All code changes are covered

Comment thread src/services/pgcr.ts
Comment on lines +12 to +16
export function decodePgcrPayload(data: Buffer): string {
if (isGzipCompressed(data)) {
return decoder.decode(gunzipSync(data))
}
return decoder.decode(data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts
  • src/services/pgcr.ts:20-23

Did we get this right? 👍 / 👎 to inform future reviews.

@owens1127
owens1127 marked this pull request as draft June 23, 2026 23:58
@owens1127
owens1127 marked this pull request as ready for review June 23, 2026 23:59
@owens1127
owens1127 merged commit 30d2499 into main Jun 23, 2026
7 checks passed
@owens1127
owens1127 deleted the fix-sentry-api-pgcr-decompress branch June 23, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant