René's URL Explorer Experiment


Title: Memory exhaustion in loop executions with agent blocks making tool calls · Issue #2525 · simstudioai/sim · GitHub

Open Graph Title: Memory exhaustion in loop executions with agent blocks making tool calls · Issue #2525 · simstudioai/sim

X Title: Memory exhaustion in loop executions with agent blocks making tool calls · Issue #2525 · simstudioai/sim

Description: Summary When running workflows with loops containing agent blocks that make many tool calls (e.g., MCP file operations), memory accumulates unbounded until system OOM. This caused my 64GB system to run out of memory during workflow execu...

Open Graph Description: Summary When running workflows with loops containing agent blocks that make many tool calls (e.g., MCP file operations), memory accumulates unbounded until system OOM. This caused my 64GB system to...

X Description: Summary When running workflows with loops containing agent blocks that make many tool calls (e.g., MCP file operations), memory accumulates unbounded until system OOM. This caused my 64GB system to...

Opengraph URL: https://github.com/simstudioai/sim/issues/2525

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory exhaustion in loop executions with agent blocks making tool calls","articleBody":"## Summary\n\nWhen running workflows with loops containing agent blocks that make many tool calls (e.g., MCP file operations), memory accumulates unbounded until system OOM. This caused my 64GB system to run out of memory during workflow execution.\n\n## Environment\n\n- Self-hosted via Docker\n- macOS with 64GB RAM\n- Docker containers with no memory limits (default)\n\n## Root Cause Analysis\n\nAfter investigating the codebase, I identified **6 critical memory accumulation points** with no bounds:\n\n### 1. `allIterationOutputs` in LoopScope (CRITICAL)\n\n**File:** `apps/sim/executor/orchestrators/loop.ts` (line 144)\n\n```typescript\nif (iterationResults.length \u003e 0) {\n  scope.allIterationOutputs.push(iterationResults)  // UNBOUNDED\n}\n```\n\nEvery loop iteration pushes results to this array with no size limit or pruning.\n\n### 2. `blockLogs` array in ExecutionContext (CRITICAL)\n\n**File:** `apps/sim/executor/execution/block-executor.ts` (lines 60-62)\n\n```typescript\nblockLog = this.createBlockLog(ctx, node.id, block, node)\nctx.blockLogs.push(blockLog)  // UNBOUNDED - every block execution adds\n```\n\nEvery block execution (including each loop iteration) pushes to this array.\n\n### 3. TraceSpans accumulation\n\n**File:** `apps/sim/lib/logs/execution/trace-spans/trace-spans.ts`\n\nThe `buildTraceSpans()` function creates spans for ALL block logs and tool calls, building an unbounded in-memory tree structure.\n\n### 4. Tool calls array per agent\n\n**File:** `apps/sim/executor/handlers/agent/agent-handler.ts` (lines 250-318)\n\nEach agent execution stores all tool calls in `span.toolCalls` array. With 100 tool calls per agent × 1000 iterations = 100,000 ToolCall objects.\n\n### 5. File extraction unbounded recursion\n\n**File:** `apps/sim/lib/logs/execution/logger.ts` (lines 621-695)\n\n`extractFilesFromExecution()` recursively walks the entire trace span tree with no depth limits.\n\n### 6. Memory table JSONB concatenation\n\n**File:** `apps/sim/executor/handlers/agent/memory.ts` (line ~580)\n\n```typescript\ndata: sql`${memory.data} || ${JSON.stringify([message])}::jsonb`  // Unbounded append\n```\n\n## Memory Growth Calculation\n\nFor a workflow with:\n- Loop: 1000 iterations\n- Agent block per iteration with 100 tool calls (file read/write via MCP)\n\n**Memory consumption:**\n- `blockLogs`: 1000 entries × 50KB = 50MB\n- `allIterationOutputs`: 1000 × 1MB = 1GB  \n- Tool calls in spans: 100,000 objects = 1GB\n- TraceSpans tree traversal: O(GB) object graph\n- **Total**: 2-10+ GB in memory, persisted to `executionData` JSONB\n\n## Reproduction Steps\n\n1. Create a workflow with a Loop block (while condition)\n2. Inside loop: StateTracker function → Agent with MCP tools (file read/write) → Reviewer\n3. Run the workflow with multiple tasks that require many file operations\n4. Monitor Docker container memory with `docker stats`\n5. Observe memory climbing until OOM\n\n## Suggested Fixes\n\n### Short-term mitigations:\n\n1. **Add iteration limits check with memory awareness:**\n```typescript\nconst MAX_MEMORY_PER_LOOP = 100 * 1024 * 1024; // 100MB\nif (estimateSize(scope.allIterationOutputs) \u003e MAX_MEMORY_PER_LOOP) {\n  logger.warn('Loop memory limit reached, truncating older iterations');\n  scope.allIterationOutputs = scope.allIterationOutputs.slice(-10);\n}\n```\n\n2. **Stream block logs to database instead of accumulating:**\n```typescript\n// Instead of ctx.blockLogs.push(blockLog)\nawait this.persistBlockLog(blockLog);\n```\n\n3. **Truncate tool call results in spans:**\n```typescript\nconst MAX_TOOL_RESULT_SIZE = 10000;\ntoolCall.result = truncate(toolCall.result, MAX_TOOL_RESULT_SIZE);\n```\n\n### Long-term solutions:\n\n1. Implement streaming execution logs (write to DB incrementally)\n2. Add configurable memory limits per execution\n3. Implement log rotation/pruning during long-running executions\n4. Add memory pressure monitoring with graceful degradation\n\n## Workaround\n\nSet Docker memory limits to prevent system-wide OOM:\n\n```yaml\n# docker-compose.override.yml\nservices:\n  simstudio-app:\n    deploy:\n      resources:\n        limits:\n          memory: 8G\n```\n\n## Related Files\n\n- `apps/sim/executor/orchestrators/loop.ts`\n- `apps/sim/executor/execution/block-executor.ts`\n- `apps/sim/lib/logs/execution/trace-spans/trace-spans.ts`\n- `apps/sim/lib/logs/execution/logger.ts`\n- `apps/sim/executor/handlers/agent/agent-handler.ts`\n- `apps/sim/executor/handlers/agent/memory.ts`\n- `packages/db/schema.ts` (executionData JSONB field)","author":{"url":"https://github.com/aadamsx","@type":"Person","name":"aadamsx"},"datePublished":"2025-12-22T18:38:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2525/sim/issues/2525"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:32069f63-2ca0-f257-8f0e-ccfc0b92e7d4
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEDAA:12D78F:1F66E88:2AC4B21:6964C28A
html-safe-nonce965edffddf74d5ae757c439597bf565a42fba26ef82fe20ac75028f2e39ce613
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFREFBOjEyRDc4RjoxRjY2RTg4OjJBQzRCMjE6Njk2NEMyOEEiLCJ2aXNpdG9yX2lkIjoiMTAwNDAyOTgyMDc0NDgxMTE0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb4e26b9139647e4e66d98fc5de38fec99de96bb410b2272cf3e484b73d93a650
hovercard-subject-tagissue:3754813921
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/simstudioai/sim/2525/issue_layout
twitter:imagehttps://opengraph.githubassets.com/4bd02f6bd3c8b8987060a30b7655644579930d97eb2bb9bc25cf06257ad32423/simstudioai/sim/issues/2525
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/4bd02f6bd3c8b8987060a30b7655644579930d97eb2bb9bc25cf06257ad32423/simstudioai/sim/issues/2525
og:image:altSummary When running workflows with loops containing agent blocks that make many tool calls (e.g., MCP file operations), memory accumulates unbounded until system OOM. This caused my 64GB system to...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaadamsx
hostnamegithub.com
expected-hostnamegithub.com
None21df671ce2c9f1a16940ccbd3af6cb4f3f12a856929ca7eb1b4aea8e384ea442
turbo-cache-controlno-preview
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5707c685ac172d50a0bdd7533dde4f8aabcf8eef
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/issues/2525#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fissues%2F2525
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fissues%2F2525
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=simstudioai%2Fsim
Reloadhttps://github.com/simstudioai/sim/issues/2525
Reloadhttps://github.com/simstudioai/sim/issues/2525
Reloadhttps://github.com/simstudioai/sim/issues/2525
simstudioai https://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Notifications https://github.com/login?return_to=%2Fsimstudioai%2Fsim
Fork 3.2k https://github.com/login?return_to=%2Fsimstudioai%2Fsim
Star 25.5k https://github.com/login?return_to=%2Fsimstudioai%2Fsim
Code https://github.com/simstudioai/sim
Issues 97 https://github.com/simstudioai/sim/issues
Pull requests 50 https://github.com/simstudioai/sim/pulls
Actions https://github.com/simstudioai/sim/actions
Projects 0 https://github.com/simstudioai/sim/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/simstudioai/sim/security
Please reload this pagehttps://github.com/simstudioai/sim/issues/2525
Insights https://github.com/simstudioai/sim/pulse
Code https://github.com/simstudioai/sim
Issues https://github.com/simstudioai/sim/issues
Pull requests https://github.com/simstudioai/sim/pulls
Actions https://github.com/simstudioai/sim/actions
Projects https://github.com/simstudioai/sim/projects
Security https://github.com/simstudioai/sim/security
Insights https://github.com/simstudioai/sim/pulse
New issuehttps://github.com/login?return_to=https://github.com/simstudioai/sim/issues/2525
New issuehttps://github.com/login?return_to=https://github.com/simstudioai/sim/issues/2525
#2527https://github.com/simstudioai/sim/pull/2527
Memory exhaustion in loop executions with agent blocks making tool callshttps://github.com/simstudioai/sim/issues/2525#top
#2527https://github.com/simstudioai/sim/pull/2527
https://github.com/aadamsx
https://github.com/aadamsx
aadamsxhttps://github.com/aadamsx
on Dec 22, 2025https://github.com/simstudioai/sim/issues/2525#issue-3754813921
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.