Repository navigation
fix(storage): stop OOM-killing studio-worker on large thread-message parts - #4426
Conversation
…parts serializeParts synchronously JSON.stringify'd every part with no yielding and no upper bound, which has been repeatedly OOM-killing deco-studio-worker in production (55 container restarts / 24h, one pod OOMKilled 40 times in ~3h) whenever a large tool result (e.g. a big file read) flows through. Yield to the event loop every 25 parts during a batch so a large flush doesn't block request handling for the whole call, and add a 50MB per-payload circuit breaker as a last resort for truly pathological sizes only — normal large tool output is still stored in full, not dropped.
…yloads The circuit breaker still ran JSON.stringify on the full payload before checking its size, so it only avoided storing an oversized result — not the expensive/blocking serialization that actually caused the stall and memory spike. Estimate size via a cheap traversal (string .length is O(1), no copy) instead, so an oversized payload is caught before ever being stringified.
PR: #4426 fix(storage): stop OOM-killing studio-worker on large thread-message parts Bump type: patch - decocms (apps/mesh/package.json): 4.0.4 -> 4.0.5 Deploy-Scope: server
Trace that led to this fixSymptom (Prometheus,
Root cause (VictoriaLogs, pod logs right before each kill):
That maps onto This unguarded path has existed since the stream-of-record feature was dark-shipped ( |
…TS.md (#4475) Mined ~300 merged PRs for the delta between the first PR proposal and the work added before merge. The dominant shape: a first draft ships the happy path, then a hardening pass (often a different engineer who takes over the branch and merges — the vibecoder→engineer handoff) adds the same categories every time. Encoded those 9 categories as an actionable first-pass checklist, each citing a real PR (#4008, #4230, #4365, #4409, #4426, #4445, #4357, #4355, #4449, #4350, #4373, #4416, #4446, #4461, #4134, #4469). Covers: variant/edge-case handling, tenant/permission scoping, concurrency & silent-data-loss, test-per-fix + invert-bug-tests + real-PG, dead-code/knip, lifecycle symmetry + state reset, kill-switch/GC/git-exclude for risky infra, input validation vs over-engineering, compile-time type-safety. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Summary
SqlThreadMessagePartStorage.serializeParts: itJSON.stringifys every thread-message part synchronously, with no yielding and no size bound, whenever a run flushes parts (e.g. a large tool result / file read comes through).serializePartsnow yields to the event loop every 25 parts during a batch instead of doing the whole flush in one synchronous pass.d54b94ca9, June 7) — not a recent regression, just not exercised hard enough to surface until now.Testing
bun test apps/mesh/src/storage/thread-message-parts.test.tsbun run --cwd=apps/mesh checkbun run fmtSummary by cubic
Prevents OOM kills and event-loop stalls in the studio worker when flushing large thread-message parts by yielding during serialization and adding a per-payload size guard that estimates size without stringifying.
Written for commit 7fd361b. Summary will update on new commits.