Skip to content

fix(cli): reduce memory usage during SDK generation by skipping dynamic IR#12029

Open
tstanmay13 wants to merge 5 commits intomainfrom
devin/1770080830-fix-memory-issue-dynamic-ir
Open

fix(cli): reduce memory usage during SDK generation by skipping dynamic IR#12029
tstanmay13 wants to merge 5 commits intomainfrom
devin/1770080830-fix-memory-issue-dynamic-ir

Conversation

@tstanmay13
Copy link
Contributor

@tstanmay13 tstanmay13 commented Feb 3, 2026

Description

Refs: Slack thread from @tstanmay13

Fixes JavaScript heap out of memory errors during SDK generation for large APIs when upgrading from CLI 0.51.28 to 3.57.0.

Root Cause: The dynamic IR (used for dynamic snippets) was being generated as part of the main IR generation phase. For large APIs, this duplicates significant amounts of data and causes memory pressure (~4GB heap usage before crash).

Solution 1: Added a skipDynamicIr parameter to skip dynamic IR generation during the main IR generation phase for remote SDK generation. The dynamic IR is still generated separately when needed for uploading to FDR.

Solution 2: Automatically increase Node.js heap size to 8GB. The CLI now detects when the heap limit is below 8GB and re-spawns itself with --max-old-space-size=8192 to prevent out-of-memory errors.

Link to Devin run: https://app.devin.ai/sessions/a0edfc74953f442aafab5dde8ced88cc
Requested by: @tstanmay13

Changes Made

  • Added skipDynamicIr optional parameter to generateIntermediateRepresentation function
  • Set skipDynamicIr: true for remote SDK generation in runRemoteGenerationForGenerator.ts
  • Dynamic IR is still generated for local generation (needed for seed tests and dynamic snippet tests)
  • Dynamic IR is still generated when needed for FDR upload in uploadDynamicIRForSdkGeneration
  • Added automatic heap size detection and re-spawn logic in cli.ts using v8.getHeapStatistics() and spawnSync
  • Uses FERN_HEAP_INCREASED env var to prevent infinite re-spawn loops
  • Added CLI version 3.57.1 entry in versions.yml with both fixes

Testing

  • Lint checks pass (pnpm run check)
  • CI seed tests pass (validates local generation still works)
  • Manual testing with large API (not tested - requires customer's API definition)

Human Review Checklist

  • Verify the re-spawn logic with spawnSync doesn't cause issues on different platforms (Windows, macOS, Linux)
  • Confirm 8GB is a reasonable default heap size (not too much for low-memory systems)
  • Verify SDK generators don't use the dynamic field from the IR directly
  • Confirm docs generation paths are not affected (they don't have skipDynamicIr: true)

…ic IR

Co-Authored-By: tanmay.singh@buildwithfern.com <tstanmay13@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 4 commits February 3, 2026 01:23
Co-Authored-By: tanmay.singh@buildwithfern.com <tstanmay13@gmail.com>
Co-Authored-By: tanmay.singh@buildwithfern.com <tstanmay13@gmail.com>
Co-Authored-By: tanmay.singh@buildwithfern.com <tstanmay13@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant