Skip to content

fix(cli): Reject bodies that are not envelopes - #2436

Merged
MathurAditya724 merged 6 commits into
mainfrom
fix/local-reject-malformed
Nov 19, 2026
Merged

MathurAditya724 merged 6 commits into
mainfrom
fix/local-reject-malformed

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

The receiver accepted anything posted to it. An empty body or a body whose first line isn't a JSON object got a 204 and took a retention slot. An envelope whose event item wasn't JSON showed up as a fake error in the tail and in event list.

Before:

POST /stream  (empty body)              ->  204, stored
POST /stream  "{not json\n…"            ->  204, stored
POST /stream  '{}\n{"type":"event"}\nnot-json'  ->  204, shows "[ERROR] Error: Unknown error"

After:

POST /stream  (empty body)              ->  400 {"error":"The envelope is empty."}, nothing stored
POST /stream  "{not json\n…"            ->  400 {"error":"The envelope header is not a JSON object."}, nothing stored
POST /stream  '{}\n{"type":"event"}\nnot-json'  ->  accepted, shows "[INVALID] Event payload is not JSON"

Relay also answers 400 for the first two cases, and it accepts the last one and drops it later. So the last case is still accepted here, but it's labelled invalid ("type":"invalid" in JSON output) instead of counting as an error. It still shows under -f error. A body that fails to decompress now gets an {"error": …} reason too. Unknown item types and items without length are still accepted. The size limits and the other status codes stay the same.

--verify now checks each item. An invalid event never counts, and neither do sessions or client reports. With -f, only items those filters show count. Before, an invalid event sent next to a session was enough to pass. This uses the same check as #2430, so whichever lands second only has a small merge.

Possible follow-up: the hosted viewer labels events its own way, so it may still show that last case as an error.

via @MathurAditya724.

--

View Session [Sentry]

An empty body or a first line that is not a JSON object got 204, took a
retention slot, and could show up as "Error: Unknown error". Answer these
with 400 and a short reason and keep nothing, as Relay does. Relay still
accepts an event item whose payload is not JSON and drops it later, so
keep accepting it, but show it as invalid instead of as an error.

Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 19, 2026 9:07pm UTC
sentry-local Ready Ready Preview Nov 19, 2026 9:07pm UTC

Request Review

An event item that is not JSON now proves nothing to --verify, while the
tail still shows it under -f error. Document the invalid JSON record, move
the check into event-kind, and give a failed decompression a JSON reason
like the other rejected bodies.

Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>

@MathurAditya724 MathurAditya724 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Independent real CLI testing found an actionable gap; see the inline reproduction and requested regression. Holding merge until it is addressed.

An envelope with an event that is not JSON next to a session or a
filtered-out item still passed --verify. Check each item instead: an
invalid event never counts, housekeeping items never count, and with -f
only items the filters show count.
@MathurAditya724

Copy link
Copy Markdown
Member

Thanks for the per-item verification fix. This updated head still conflicts with current main after #2432–#2434 merged. Please rebase and resolve the ingest result conflict carefully: accepted envelopes must retain HTTP 200/JSON acknowledgements, rejected envelopes must retain HTTP 400/JSON errors, and only accepted outcomes should record session activity. Keep the valid-matching-item verification rule when coordinating with #2430. I will retest the rebased combination before merging.

sentry-junior Bot and others added 2 commits November 19, 2026 20:17
Keep #2432's 200 acknowledgement next to the 400 rejection: ingest now
returns a tagged result, reads the envelope header once, and both
receivers answer through the shared ingestResponse.

Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
@sentry-junior

sentry-junior Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the conflict with main. Good envelopes still get a 200 with the JSON ack, bad ones get a 400 with a JSON error, and only accepted ones count as session activity. The --verify rule is unchanged. I merged main in instead of rebasing so the history stays intact. Should be ready to retest.

Preserve sanitized verification diagnostics, skip invalid event items, and pin accepted-ingest activity to the resolved session ID. Keep both regression suites and consolidate the shared verification helper.

Co-Authored-By: Codex (GPT-6) <noreply@openai.com>
@MathurAditya724

Copy link
Copy Markdown
Member

Resolved the overlaps with the just-merged #2430 and #2435 in 1341b1c. The resolution keeps one shared verification helper with invalid-item exclusion, preserves sanitized connected-SDK diagnostics and both regression suites, and records activity only for an accepted delivery using the request's pinned session ID.

Full workspace type checking and lint passed. The full test retry passed (13,697 CLI tests, 2,469 MCP core, 476 Cloudflare, 501 Local); the first run hit the previously observed unrelated issue-integrations unlink flake, which also passed all 63 tests in isolation. Independent real-process probes passed six mixed-invalid verification cases, 15 malformed-ingest checks, 64 accepted plain/scoped/compressed SDK deliveries, and the terminal-sanitization regression. Waiting for fresh hosted checks before final approval/merge.

@MathurAditya724 MathurAditya724 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed and retested 1341b1c against current main. The prior mixed-invalid verification finding is fixed per item. The main integration preserves #2430's sanitized connected-SDK diagnostics, #2435's pinned session selection, the Relay-compatible accepted response, and activity updates only for accepted deliveries. One shared verification helper remains, and both regression suites are retained.

Full workspace tsc and lint passed; the full test retry passed (13,697 CLI tests; MCP core 2,469; Cloudflare 476; Local 501). The initial unrelated issue-integrations unlink flake passed all 63 tests in isolation before the successful complete retry. Independent real CLI/HTTP probes passed six invalid/mixed verification cases, 15 rejected-body/retention checks, 64 accepted deliveries across plain/scoped receivers and identity/gzip/deflate/Brotli encoding, plus terminal sanitization. No remaining actionable findings.

Hosted checks are green on this exact head. The Windows Local job initially exceeded the existing five-second limit in an unchanged viewer test; that case passed locally in isolation, and the targeted Windows job rerun passed through viewer integration, npm daemon E2E, native build and native daemon E2E. Linux, macOS, Node 24 CLI E2E, Swift/TypeScript analysis, and security gates also passed.

After main advanced to 77050b1, repeated the complete tsc/lint/test gate on the new integration; all passed, including 13,697 CLI tests. The final tested tree is 05d54a40168e1e181089500d46937ccf625a3145.

@MathurAditya724
MathurAditya724 merged commit 926baf2 into main Nov 19, 2026
33 of 34 checks passed
@MathurAditya724
MathurAditya724 deleted the fix/local-reject-malformed branch November 19, 2026 22:45

This branch was successfully deployed

2 active deployments
Preview – sentry-local — 1341b1cb Deployed Nov 19, 2026 by vercel[bot]
Preview – cli — 1341b1cb Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant