-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
fix(oom): prevent per-request memory accumulation (256MB heap) #2973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegosouzapw
merged 13 commits into
diegosouzapw:release/v3.8.8
from
soyelmismo:fix/cpu-leak-sse-streaming
Jun 1, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b778ad2
feat(notion): add Notion MCP context source with 6 tools, dashboard t…
branben 38221f2
fix(mcp): reorder enforceScopes guard before MCP_TOOL_MAP lookup, add…
branben 379b72c
fix(routing): add agy to executor map so it uses AntigravityExecutor …
ReqX 8477990
fix: CPU leak from Bottleneck limiter accumulation + per-request opti…
soyelmismo af8e134
fix: combo credential resolution ignores target.providerId — prefer c…
oyi77 8b074d2
fix(claude): sanitize tool schemas + cloak third-party tool names on …
NomenAK 2b613d9
fix combo vision and codex tool history (#2940)
charithharshana 4c38961
fix(claude): map WebSearch to Responses web_search (#2938)
makcimbx ec72330
fix(claude): strip empty Read pages tool input (#2937)
makcimbx e51ab94
Improve self-service provider quota visibility (#2931)
guanbear 41a3279
fix(oom): prevent per-request memory accumulation in chatCore.ts
fe1fb0f
fix: address Gemini review — use estimateSizeFast + add tests
b5dc193
Merge remote-tracking branch 'origin/release/v3.8.8' into fix/cpu-lea…
diegosouzapw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
|
|
||
| // ── estimateSizeFast (truncateForLog dependency) ─────────────────────── | ||
|
|
||
| test("estimateSizeFast estimates small objects correctly", async () => { | ||
| const { estimateSizeFast } = await import("../../open-sse/utils/estimateSize.ts"); | ||
| const small = { model: "gpt-4", messages: [{ role: "user", content: "hello" }] }; | ||
| const size = estimateSizeFast(small); | ||
| assert.ok(size > 0, "Size should be positive"); | ||
| assert.ok(size < 1024, `Small object should be < 1KB, got ${size}`); | ||
| }); | ||
|
|
||
| test("estimateSizeFast estimates large objects correctly", async () => { | ||
| const { estimateSizeFast } = await import("../../open-sse/utils/estimateSize.ts"); | ||
| const largeContent = "x".repeat(100 * 1024); | ||
| const large = { model: "gpt-4", messages: [{ role: "user", content: largeContent }] }; | ||
| const size = estimateSizeFast(large); | ||
| assert.ok(size > 100 * 1024, `Large object should be > 100KB, got ${size}`); | ||
| }); | ||
|
|
||
| test("estimateSizeFast handles null and primitives", async () => { | ||
| const { estimateSizeFast } = await import("../../open-sse/utils/estimateSize.ts"); | ||
| assert.equal(estimateSizeFast(null), 0); | ||
| assert.equal(estimateSizeFast(undefined), 0); | ||
| assert.equal(estimateSizeFast("hello"), 5); | ||
| assert.equal(estimateSizeFast(42), 8); | ||
| assert.equal(estimateSizeFast(true), 4); | ||
| }); | ||
|
|
||
| test("estimateSizeFast handles circular references", async () => { | ||
| const { estimateSizeFast } = await import("../../open-sse/utils/estimateSize.ts"); | ||
| const obj: Record<string, unknown> = { a: 1 }; | ||
| obj.self = obj; | ||
| const size = estimateSizeFast(obj); | ||
| assert.ok(size > 0, "Should handle circular refs"); | ||
| assert.ok(size < 1000, `Simple circular ref should be small, got ${size}`); | ||
| }); | ||
|
|
||
| // ── HEAP_PRESSURE_THRESHOLD_MB default ───────────────────────────────── | ||
|
|
||
| test("HEAP_PRESSURE_THRESHOLD_MB defaults to 200 when env is unset", () => { | ||
| const val = parseInt(process.env.HEAP_PRESSURE_THRESHOLD_MB || "200", 10); | ||
| assert.equal(val, 200); | ||
| }); | ||
|
|
||
| // ── estimateSizeFast vs MAX_LOG_BODY_CHARS threshold ─────────────────── | ||
| // This validates the logic that truncateForLog uses: if estimateSizeFast | ||
| // returns <= 8KB, the object is kept as-is; otherwise it's summarized. | ||
|
|
||
| test("estimateSizeFast distinguishes small vs large for 8KB threshold", async () => { | ||
| const { estimateSizeFast } = await import("../../open-sse/utils/estimateSize.ts"); | ||
| const MAX_LOG_BODY_CHARS = 8 * 1024; | ||
|
|
||
| // Small: 50 messages with short content | ||
| const small = { | ||
| model: "gpt-4", | ||
| messages: Array.from({ length: 50 }, (_, i) => ({ | ||
| role: "user", | ||
| content: `message ${i}`, | ||
| })), | ||
| }; | ||
| assert.ok( | ||
| estimateSizeFast(small) <= MAX_LOG_BODY_CHARS, | ||
| `Small payload (${estimateSizeFast(small)}B) should be <= ${MAX_LOG_BODY_CHARS}` | ||
| ); | ||
|
|
||
| // Large: 500 messages with long content | ||
| const large = { | ||
| model: "gpt-4", | ||
| messages: Array.from({ length: 500 }, (_, i) => ({ | ||
| role: "user", | ||
| content: `x`.repeat(500), | ||
| })), | ||
| }; | ||
| assert.ok( | ||
| estimateSizeFast(large) > MAX_LOG_BODY_CHARS, | ||
| `Large payload (${estimateSizeFast(large)}B) should be > ${MAX_LOG_BODY_CHARS}` | ||
| ); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the new hard-coded 200 MB default, any deployment using the repo defaults can start returning 503s while still far from OOM: Docker sets
OMNIROUTE_MEMORY_MB=1024inDockerfile, andomniroute servedefaults/clamps to 512 MB, but the guard rejects all chat requests onceheapUsedcrosses 200 MB unless operators discover and set this separate env var. This makes normal high-memory-but-healthy processes unavailable; derive the threshold from the actual V8 heap limit /OMNIROUTE_MEMORY_MBor default it proportionally.Useful? React with 👍 / 👎.