fix(nextjs): add force dynamic exports for new copilot routes#784
fix(nextjs): add force dynamic exports for new copilot routes#784waleedlatif1 merged 3 commits intostagingfrom
Conversation
- Convert YAML_WORKFLOW_PROMPT from static export to lazy function - Prevents 281-line string literal from being loaded during static generation - Fixes exit code 137 memory exhaustion during Docker builds
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
There was a problem hiding this comment.
Greptile Summary
This PR addresses build performance and memory issues in the Sim Studio Next.js application through three targeted improvements:
Performance Enhancement: The GitHub Actions workflow now uses an 8-core self-hosted runner (ubuntu-latest-8-cores) instead of the standard ubuntu-latest runner. This change specifically targets the Docker build process, which builds three different images (simstudio, migrations, and realtime) in a matrix strategy with multi-platform support (linux/amd64, linux/arm64). The additional CPU cores should significantly reduce build times for these resource-intensive operations.
Memory Optimization: The large YAML workflow prompt (300+ lines) in apps/sim/lib/copilot/prompts.ts has been converted from a static constant (YAML_WORKFLOW_PROMPT) to a lazy-loaded function (getYamlWorkflowPrompt()). This prevents the content from being loaded during Next.js static generation, reducing build-time memory consumption.
Dynamic Route Configuration: Five copilot-related API routes now include export const dynamic = 'force-dynamic' directives:
/api/workflows/[id]/autolayout/route.ts/api/tools/get-yaml-structure/route.ts/api/workflows/[id]/yaml/route.ts/api/tools/edit-workflow/route.ts
These routes handle complex operations like YAML parsing, workflow conversion, autolayout algorithms, and database operations. The force-dynamic export prevents Next.js from attempting static optimization of these routes during build time, eliminating out-of-memory (OOM) errors that were occurring during static analysis of the complex workflow processing logic.
The changes work together as a comprehensive solution: the lazy-loaded prompt reduces memory pressure from large static content, the dynamic route exports prevent memory-intensive static analysis, and the enhanced CI runner provides more resources for the build process.
Confidence score: 4/5
• This PR is safe to merge as it addresses legitimate performance and memory issues without changing core functionality
• The changes are well-targeted fixes for specific build and memory problems, with minimal risk of introducing new issues
• All files need attention to verify the 8-core runner is properly configured in the CI environment
6 files reviewed, no comments
…dioai#784) * feat: use 8-core self-hosted runner for faster Docker builds * fix: lazy load large YAML prompt to prevent build memory exhaustion - Convert YAML_WORKFLOW_PROMPT from static export to lazy function - Prevents 281-line string literal from being loaded during static generation - Fixes exit code 137 memory exhaustion during Docker builds * fix(nextjs): add force dynamic for copilot routes to resolve OOM issue
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
Checklist:
bun run test)Security Considerations:
Additional Information:
Any additional information, configuration or data that might be necessary to reproduce the issue or use the feature.