Skip to content

Conversation

@hmacr
Copy link
Contributor

@hmacr hmacr commented Nov 4, 2025

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2025

📝 Walkthrough

Walkthrough

This pull request refactors how application function runtimes are configured and managed. It removes the dynamic getVersions() helper function and replaces it with direct consumption of runtime data from templateRuntimes. The configuration flow shifts from static, hard-coded runtimes to dynamically fetched runtimes via Config::getParam(). An environment-based allow-list mechanism (_APP_FUNCTIONS_RUNTIMES) is introduced to filter available runtimes. The function signature for getRuntimes() changes to accept an allow-list instead of a deny-list. Configuration loading is consolidated earlier in the initialization phase to eliminate duplicate loads.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45–60 minutes

This refactor involves interconnected changes across multiple configuration files with varying logic patterns. Key areas requiring extra attention:

  • All call sites of getRuntimes() throughout the templates directory to verify correct argument passing and the new function signature
  • The allow-list filtering logic and environment variable parsing in app/config/templates/function.php to ensure correct runtime inclusion/exclusion
  • The dynamic configuration retrieval and array mapping logic in app/config/template-runtimes.php
  • The removal of getVersions() function and verification that frameworks.php correctly uses templateRuntimes data directly
  • The configuration loading order changes in app/init/configs.php to ensure no dependency ordering issues and that duplicates are properly eliminated

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: using supported runtimes from environment configuration instead of hardcoded values, which aligns with the codebase modifications.
Description check ✅ Passed The description references a specific task (SER-359) related to filtering function runtimes, which directly corresponds to the changeset's purpose of implementing allow-list filtering based on environment configuration.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ser-359

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.44-r2 CVE-2025-5244 HIGH
binutils 2.44-r2 CVE-2025-5245 HIGH
libxml2 2.13.8-r0 CVE-2025-49794 CRITICAL
libxml2 2.13.8-r0 CVE-2025-49796 CRITICAL
libxml2 2.13.8-r0 CVE-2025-49795 HIGH
libxml2 2.13.8-r0 CVE-2025-6021 HIGH
pcre2 10.43-r1 CVE-2025-58050 CRITICAL
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH
stdlib 1.22.10 CVE-2025-47907 HIGH
stdlib 1.22.10 CVE-2025-47912 HIGH
stdlib 1.22.10 CVE-2025-58183 HIGH
stdlib 1.22.10 CVE-2025-58186 HIGH
stdlib 1.22.10 CVE-2025-58187 HIGH
stdlib 1.22.10 CVE-2025-58188 HIGH
stdlib 1.22.10 CVE-2025-61724 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/config/frameworks.php (1)

203-203: Critical: Undefined function call will cause fatal error.

Line 203 still calls getVersions($templateRuntimes['NODE']['versions'], 'node'), but the getVersions helper function was removed in this refactor. This will cause a fatal error when the configuration is loaded.

Apply this diff to fix the issue:

-        'runtimes' => getVersions($templateRuntimes['NODE']['versions'], 'node'),
+        'runtimes' => $templateRuntimes['NODE'],
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55103a1 and 3739ee2.

📒 Files selected for processing (4)
  • app/config/frameworks.php (14 hunks)
  • app/config/template-runtimes.php (1 hunks)
  • app/config/templates/function.php (41 hunks)
  • app/init/configs.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (6)
app/init/configs.php (1)

7-8: LGTM: Early runtime configuration loading.

Moving the runtime configuration loading to the top ensures that runtime data is available when other configuration files (like template-runtimes.php, frameworks.php, and templates/function.php) need to reference it.

app/config/template-runtimes.php (1)

5-12: LGTM: Dynamic runtime configuration.

The refactoring from hard-coded runtime arrays to dynamically built mappings from Config::getParam('runtimes') provides better flexibility. The structure—uppercase keys mapping to arrays of "key-version" strings—aligns with the consumption pattern in frameworks.php and templates/function.php.

app/config/frameworks.php (1)

17-17: LGTM: Consistent direct runtime references.

All frameworks (except tanstack-start on Line 203) correctly use direct references to $templateRuntimes['NODE'] or $templateRuntimes['FLUTTER'], eliminating the need for the removed getVersions helper function.

Also applies to: 43-43, 69-69, 94-94, 111-111, 136-136, 153-153, 178-178, 228-228, 253-253, 270-270, 286-286, 303-303, 319-319

app/config/templates/function.php (3)

9-21: LGTM: Refactored to use allow-list filtering.

The function signature change from a deny-list to an allow-list approach is consistent with the PR objective. The filtering logic correctly uses in_array($runtime, $allowList) to include only explicitly allowed runtimes.


37-2158: LGTM: Consistent allow-list propagation across all templates.

All getRuntimes() calls throughout the file have been consistently updated to pass the $allowList parameter. This ensures uniform runtime filtering across all function templates.


7-7: Confirm this is intentional—template runtimes behavior when env var is unset differs from other parts of the codebase.

The review comment is correct. When _APP_FUNCTIONS_RUNTIMES is empty or unset, the code in this file filters out all runtimes (since in_array($runtime, []) always returns false), resulting in zero available runtimes for templates. This behavior is inconsistent with other parts of the codebase:

  • Create.php (line 191): Uses if (!empty($allowList)) first, so validation is skipped when empty—allowing all runtimes
  • This file: Uses array_filter with in_array directly—filters out all runtimes when empty

While the default in app/config/variables.php is 'node-16.0,php-8.0,python-3.9,ruby-3.0', this inconsistency should be addressed to ensure predictable behavior and prevent silent failures in edge cases where the env var is unset.

Recommend:

  • Add !empty($allowList) guard before applying the filter, or
  • Use the same ternary pattern as runtimes-v2.php for consistency, or
  • Document this behavior explicitly

use Utopia\System\System;

$templateRuntimes = Config::getParam('template-runtimes');
$allowList = \array_filter(\explode(',', System::getEnv('_APP_FUNCTIONS_RUNTIMES', '')));
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Potential issue: Whitespace in environment variable will break filtering.

The explode(',', ...) call doesn't trim whitespace from the resulting array elements. If the _APP_FUNCTIONS_RUNTIMES environment variable contains spaces (e.g., "node-18.0, node-20.0"), the allow-list will include strings with leading spaces, causing the in_array() check on Line 19 to fail.

Apply this diff to trim whitespace:

-$allowList = \array_filter(\explode(',', System::getEnv('_APP_FUNCTIONS_RUNTIMES', '')));
+$allowList = \array_filter(\array_map('trim', \explode(',', System::getEnv('_APP_FUNCTIONS_RUNTIMES', ''))));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$allowList = \array_filter(\explode(',', System::getEnv('_APP_FUNCTIONS_RUNTIMES', '')));
$allowList = \array_filter(\array_map('trim', \explode(',', System::getEnv('_APP_FUNCTIONS_RUNTIMES', ''))));
🤖 Prompt for AI Agents
In app/config/templates/function.php around line 7, the allow-list is built with
explode(',', ...) but elements are not trimmed so entries with surrounding
whitespace will fail in_array checks; after exploding, trim each element (e.g.,
map trim over the array) and then filter out empty strings so the resulting
$allowList contains clean runtime names without leading/trailing spaces.

@github-actions
Copy link

github-actions bot commented Nov 4, 2025

✨ Benchmark results

  • Requests per second: 19,156
  • Requests with 200 status code: n,ull
  • P99 latency: 0.00758266

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 19,156 1,202
200 n,ull 216,487
P99 0.00758266 0.171118754

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.

2 participants