Skip to content

improvement(execution): memory usage for aggregated results#4650

Merged
icecrasher321 merged 15 commits into
stagingfrom
improvement/execution-mem-usage
May 19, 2026
Merged

improvement(execution): memory usage for aggregated results#4650
icecrasher321 merged 15 commits into
stagingfrom
improvement/execution-mem-usage

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

Large array manifests to prevent excessive memory usage of data produced in loops.

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 19, 2026 6:34am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 18, 2026

PR Summary

Medium Risk
Touches core execution/runtime plumbing (function execution, workflow API responses, loop/parallel aggregation, and snapshot serialization), so regressions could impact workflow outputs and run-from-block behavior. Changes are well-covered by new tests but introduce new manifest/materialization paths and access-control tracking.

Overview
Large array results are now compacted into manifest references to reduce memory/response payload size, including loop/parallel aggregated outputs, function results, and Variables block assignments; manifests can be materialized back when required.

Execution/runtime support is extended with sim.values.readArray(...) (isolated-vm broker + docs), stricter rejection of large refs in runtimes without ref-native helpers (shell/E2B/imports), and end-to-end propagation of largeValueKeys/fileKeys to precisely authorize/materialize only the large values/files actually touched.

API response handling is hardened: Response block HTTP output now materializes inline refs/manifests under size limits, runFromBlock snapshots preserve source execution lineage for large-value access, and pause snapshot serialization adds bounded-size checks to avoid full JSON.stringify on oversized state.

Reviewed by Cursor Bugbot for commit ec1e107. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 18, 2026

Greptile Summary

This PR introduces a LargeArrayManifest system that stores large arrays produced in loops as chunked references in durable storage, preventing excessive in-memory accumulation. It adds fine-grained key-based access control alongside the existing execution-ID-scoped approach and refactors the streaming response to materialize large values before sending them to clients.

  • New chunked manifest type: LargeArrayManifest splits large arrays into separately-stored chunks, offloading loop iteration results to durable storage.
  • Access control overhaul: The DAG executor collects keys from the filtered source snapshot for runFromBlock so exact cross-execution refs are authorized without broadening workflow-scope access.
  • Streaming/response materialization: createHttpResponseFromBlock is now async and calls materializeInlineExecutionValue; the streaming onBlockComplete handler materializes each selected output inline.

Confidence Score: 4/5

The critical execution paths have all been correctly wired and the refactoring is internally consistent.

The three previously-flagged regressions are all addressed in the current diff. The remaining findings are quality/performance concerns. The score reflects the breadth of interconnected changes touching core execution, access control, streaming, variables, and loop state, which warrants thorough end-to-end testing.

streaming.ts and inline-materialization.server.ts deserve a second look, but neither finding is blocking.

Important Files Changed

Filename Overview
apps/sim/lib/execution/payloads/large-array-manifest.ts New core chunked-manifest implementation; chunking arithmetic and slice reads are correctly bounded.
apps/sim/lib/execution/payloads/inline-materialization.server.ts New recursive materializer with budget tracking. Memoized/shared object references contribute byteLength 0, which can undercount the true JSON size for shared object graphs.
apps/sim/lib/workflows/streaming/streaming.ts onBlockComplete now materializes selected outputs inline with budget tracking; buildMinimalResult re-serializes the entire growing output object after each selected output is appended (O(n²) JSON.stringify calls).
apps/sim/lib/execution/payloads/materialization.server.ts assertLargeValueRefAccess and assertExecutionFileScope now support an allowedKeys fast-path before the execution-ID checks.
apps/sim/executor/execution/executor.ts Collects largeValueKeys/fileKeys from the filtered source snapshot for runFromBlock, enabling precise cross-execution key access.
apps/sim/lib/workflows/executor/execution-core.ts Removed warmLargeValueRefs call for source snapshot; parseVariableValueByType gains a parseLargeExecutionValue guard for JSON-serialized refs.
apps/sim/executor/orchestrators/loop.ts Iteration results compacted before accumulation; new hasReachedConfiguredIterationLimit short-circuits doWhile loops at maxIterations.
apps/sim/lib/workflows/utils.ts createHttpResponseFromBlock is now async and calls materializeInlineExecutionValue(data, context), properly materializing LargeArrayManifest before sending to external callers.
apps/sim/executor/handlers/variables/variables-handler.ts Variables block now calls compactWorkflowVariableValue on assignment values before storing, converting large arrays to manifests.
apps/sim/app/api/workflows/[id]/execute/route.ts largeValueExecutionIds/Keys/fileKeys/allowLargeValueWorkflowScope threaded through all execution paths correctly.

Reviews (13): Last reviewed commit: "fix tests" | Re-trigger Greptile

Comment thread apps/sim/lib/workflows/streaming/streaming.ts
Comment thread apps/sim/executor/variables/resolver.ts
Comment thread apps/sim/lib/execution/payloads/large-array-manifest.ts Outdated
Comment thread apps/sim/lib/execution/payloads/large-array-manifest.ts
Comment thread apps/sim/executor/handlers/variables/variables-handler.ts Outdated
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread apps/sim/executor/orchestrators/loop.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread apps/sim/executor/variables/resolvers/reference-async.server.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread apps/sim/executor/handlers/variables/variables-handler.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

Comment thread apps/sim/executor/orchestrators/loop.ts Outdated
Comment thread apps/sim/lib/execution/payloads/large-array-manifest-metadata.ts
Comment thread apps/sim/lib/execution/payloads/serializer.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 47e693c. Configure here.

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread apps/sim/executor/orchestrators/loop.ts Outdated
Comment thread apps/sim/executor/execution/snapshot-serializer.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

Comment thread apps/sim/app/api/workflows/[id]/execute/route.ts
Comment thread apps/sim/lib/execution/payloads/hydration.ts
Comment thread apps/sim/app/api/workflows/[id]/execute/route.ts
Comment thread apps/sim/executor/handlers/function/function-handler.ts Outdated
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e87c280. Configure here.

Comment thread apps/sim/lib/execution/payloads/hydration.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ec1e107. Configure here.

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321 icecrasher321 merged commit 279010a into staging May 19, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant