Repository navigation
fix(sse): parse the chat request body once by threading it from the route guard (#4380) - #4416
Merged
Merged
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
diegosouzapw
force-pushed
the
fix/4380-parse-once
branch
from
June 20, 2026 19:59
bacc082 to
fcce1d5
Compare
This was referenced Jun 20, 2026
tkgo11
pushed a commit
to tkgo11/OmniRoute
that referenced
this pull request
Sep 23, 2026
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.
Closes #4380
Problem
Large
/v1/chat/completionsJSON bodies (270–550 KB coding-agent payloads) were JSON-parsed twice: once in the route (request.clone().json()for the prompt-injection guard), then again inhandleChat(request.json()). Under concurrent load this doubled the body's heap residency on the hot path and contributed to the heap-OOM crash-loop (exit 134) reported in #4380.Fix
src/sse/handlers/requestBody.ts::resolveChatRequestBody(request, preParsedBody)— returns the already-parsed body when present, otherwise parses the request. (Standalone module so it's unit-testable without importing the DB-bound chat pipeline.)handleChatgains an optional 3rd parampreParsedBody = null(additive — the 12 existing callers are unchanged and parse as before).handleChat, so the handler no longer re-parses it.Validation (TDD)
New
tests/unit/chat-request-body-parse-once-4380.test.ts(3/3): pre-parsed body is returned without callingrequest.json()(parse-once), null/undefined fall back to parsing, and a present-but-empty body is used as-is. Verified RED by temporarily reverting the guard (the parse-once assertions fail), then GREEN after restore.typecheck:coreclean (validates the new signature + the 12handleChatcallers + the new import).chat-pipelineintegration: 28/29 — the one failure (Codex CLI fingerprint to OAuth responses requests) reproduces identically on the base branch without this change, i.e. a pre-existing flake unrelated to this PR. Lint clean.This is the parse-once slice of the broader #4041 OOM work (injection-guard scan bound + heap-guard already shipped;
system_prompt_leakheuristic in the #4041 PR).