fix: eliminate OOM in execution history trim under syslog load#354
Merged
Conversation
Under sustained syslog throughput, _trim_execution_history was called as
a fire-and-forget background task every 5 messages per workflow. Each
invocation called Storage.list_entries("workflow_execution/") which
json.loads every execution record in the table into Python objects.
Execution records included full alert payloads (resp_body, req_header,
etc.) written by the dedup_and_write node, making each record several
hundred KB. As the table grew to 3+ GB, a single trim scan materialised
gigabytes of transient objects — py-spy confirmed 100% GIL time in
json.raw_decode attributed to _trim_execution_history → list_entries.
Because multiple trim tasks could be in flight simultaneously (one spawned
per 5 messages, each taking tens of seconds to complete), the transient
allocations multiplied, driving RSS to 20 GB without bound.
Fix:
- Storage.list_raw(): new method that returns (key, raw_value_str) pairs
without any Python-side JSON parsing, compatible with all SQLite versions.
- _trim_execution_history: replaced list_entries + json.loads with
list_raw + regex extraction of workflowId/startedAt from the first 400
bytes of each value string. Avoids constructing large Python objects
entirely; regex on a 400-byte prefix is ~100x cheaper than full parse.
- _trim_in_flight: Set[str] guard ensures at most one trim task per
workflow runs at a time, preventing concurrent scans from multiplying
peak memory usage.
Co-authored-by: Cursor <cursoragent@cursor.com>
xiami762
approved these changes
Jun 2, 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.
Under sustained syslog throughput, _trim_execution_history was called as a fire-and-forget background task every 5 messages per workflow. Each invocation called Storage.list_entries("workflow_execution/") which json.loads every execution record in the table into Python objects. Execution records included full alert payloads (resp_body, req_header, etc.) written by the dedup_and_write node, making each record several hundred KB. As the table grew to 3+ GB, a single trim scan materialised gigabytes of transient objects — py-spy confirmed 100% GIL time in json.raw_decode attributed to _trim_execution_history → list_entries. Because multiple trim tasks could be in flight simultaneously (one spawned per 5 messages, each taking tens of seconds to complete), the transient allocations multiplied, driving RSS to 20 GB without bound.
Fix: