Skip to content

fix: fallback platform#10971

Merged
loks0n merged 1 commit into1.8.xfrom
fix-fallback-platfor
Dec 16, 2025
Merged

fix: fallback platform#10971
loks0n merged 1 commit into1.8.xfrom
fix-fallback-platfor

Conversation

@loks0n
Copy link
Copy Markdown
Member

@loks0n loks0n commented Dec 16, 2025

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 16, 2025

📝 Walkthrough

Walkthrough

Default platform initialization was changed to use Config::getParam('platform', []) when payload.platform is absent. Several places now compute a protocol (http vs https) from _APP_OPTIONS_FORCE_HTTPS and derive an API endpoint as "{protocol}://{platform['apiHostname']}/v1". Code that previously used platform['endpoint'] was updated to use this computed endpoint (affecting function/site environment variables, messaging image URLs, and worker/function execution contexts). The platform resource registration was simplified to return Config::getParam('platform', []) directly (removed Request-based resolver logic). Build-related code also adds several deployment/project/runtime/capacity environment variables for functions and sites.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas needing extra attention:
    • Consistency and type handling for _APP_OPTIONS_FORCE_HTTPS comparisons (loose vs strict) and effects on protocol selection.
    • Correctness of computed endpoint usage replacing platform['endpoint'] across messaging, general router, function execution, and build flows.
    • The simplified platform resource resolver (removed Request) and places expecting platform.endpoint or other fields.
    • New function/site environment variables added in Builds.php for naming/values and any downstream consumers.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'fix: fallback platform' is vague and does not clearly convey the specific changes made to the codebase, such as the endpoint computation logic or HTTPS protocol handling. Provide a more descriptive title that explains the specific fix, such as 'fix: compute API endpoint dynamically from HTTPS settings and platform hostname' or 'fix: fallback platform endpoint construction'.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether the description relates to the changeset. Add a detailed pull request description explaining the purpose of the changes, what platform fallback issue is being fixed, and why the endpoint computation logic needs to be dynamic.
✨ 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 fix-fallback-platfor

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
Copy Markdown

github-actions bot commented Dec 16, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libpng 1.6.51-r0 CVE-2025-66293 HIGH
libpng-dev 1.6.51-r0 CVE-2025-66293 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
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

📜 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 eabe06d and fafc223.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Workers/Functions.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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 16, 2025

✨ Benchmark results

  • Requests per second: 1,228
  • Requests with 200 status code: 221,099
  • P99 latency: 0.15677251

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,228 1,302
200 221,099 234,393
P99 0.15677251 0.154755315

@loks0n loks0n force-pushed the fix-fallback-platfor branch from fafc223 to 3c3aa6d Compare December 16, 2025 22:56
Copy link
Copy Markdown
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: 0

Caution

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

⚠️ Outside diff range comments (1)
app/controllers/api/messaging.php (1)

3538-3577: Fix undefined $currentScheduledAt when building push image URL

In this create‑push path, $scheduleTime = $currentScheduledAt ?? $scheduledAt; uses $currentScheduledAt, which is never defined in this action, causing a PHP notice and relying on undefined‑var behavior. For new messages there is no prior schedule anyway, so you can just use $scheduledAt here; the new $protocol/$endpoint logic looks fine.

-            $scheduleTime = $currentScheduledAt ?? $scheduledAt;
+            $scheduleTime = $scheduledAt;
♻️ Duplicate comments (2)
app/controllers/general.php (1)

461-462: Add validation for the 'apiHostname' key (duplicate issue).

This code has the same undefined array key issue as identified in src/Appwrite/Platform/Workers/Functions.php. Line 462 accesses $platform['apiHostname'] without validation, which could cause a runtime error if the key is missing.

Apply the same defensive validation as suggested for the Functions.php file:

 $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https';
-$endpoint = "$protocol://{$platform['apiHostname']}/v1";
+$endpoint = "$protocol://{$platform['apiHostname'] ?? 'localhost'}/v1";
src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php (1)

371-372: Add validation for the 'apiHostname' key (duplicate issue).

This code has the same undefined array key issue as identified in the other reviewed files. Line 372 accesses $platform['apiHostname'] without validation.

Apply the same defensive validation:

 $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https';
-$endpoint = "$protocol://{$platform['apiHostname']}/v1";
+$endpoint = "$protocol://{$platform['apiHostname'] ?? 'localhost'}/v1";
🧹 Nitpick comments (1)
src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (1)

639-671: Consider guarding $platform['apiHostname'] when computing $endpoint

The new $protocol/$endpoint logic and the added APPWRITE_* vars look good, but $endpoint = "$protocol://{$platform['apiHostname']}/v1"; assumes apiHostname is always present in the payload‑provided $platform. If a build message ever arrives without that field (e.g., from an older producer or misconfigured sender), you’ll get notices and malformed APPWRITE_*_API_ENDPOINT values.

To make this more robust and match the “fallback platform” goal of the PR, consider falling back to the config platform when $platform is empty or missing apiHostname:

-            $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https';
-            $endpoint = "$protocol://{$platform['apiHostname']}/v1";
+            $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https';
+            $platformConfig = $platform ?: Config::getParam('platform', []);
+            $apiHostname = $platformConfig['apiHostname'] ?? null;
+            if (empty($apiHostname)) {
+                throw new \Exception('Platform apiHostname is not configured');
+            }
+            $endpoint = "$protocol://{$apiHostname}/v1";

This keeps behavior for well‑formed payloads while failing fast (or you could choose a silent fallback) when platform data is missing.

📜 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 fafc223 and 3c3aa6d.

📒 Files selected for processing (6)
  • app/controllers/api/messaging.php (3 hunks)
  • app/controllers/general.php (2 hunks)
  • app/init/resources.php (1 hunks)
  • src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php (1 hunks)
  • src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (2 hunks)
  • src/Appwrite/Platform/Workers/Functions.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Appwrite/Platform/Workers/Functions.php (1)
src/Appwrite/Event/Event.php (1)
  • getParam (319-322)
⏰ 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). (20)
  • GitHub Check: E2E Service Test (Messaging)
  • GitHub Check: E2E Service Test (Users)
  • GitHub Check: E2E Service Test (Functions)
  • GitHub Check: E2E Service Test (Storage)
  • GitHub Check: E2E Service Test (Sites)
  • GitHub Check: E2E Service Test (Tokens)
  • GitHub Check: E2E Service Test (Locale)
  • GitHub Check: E2E Service Test (Databases/TablesDB)
  • GitHub Check: E2E Service Test (Teams)
  • GitHub Check: E2E Service Test (GraphQL)
  • GitHub Check: E2E Service Test (Proxy)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (Realtime)
  • GitHub Check: E2E Service Test (Console)
  • GitHub Check: E2E Service Test (Account)
  • GitHub Check: E2E Service Test (Site Screenshots)
  • GitHub Check: Unit Test
  • GitHub Check: E2E General Test
  • GitHub Check: E2E Service Test (Dev Keys)
  • GitHub Check: scan
🔇 Additional comments (4)
app/init/resources.php (1)

167-169: LGTM! Clean refactor of platform resource.

The platform resource now returns static configuration directly from Config::getParam('platform', []), removing the previous Request-based endpoint construction logic. This simplifies the resolver and properly delegates dynamic endpoint computation to the consumers (as seen in the other files where protocol and endpoint are computed based on _APP_OPTIONS_FORCE_HTTPS).

src/Appwrite/Platform/Workers/Functions.php (2)

90-90: Good fix for the type mismatch.

The fallback now correctly defaults to Config::getParam('platform', []) instead of an empty string, aligning with the array $platform parameter type at line 353.


494-495: The code at lines 494-495 is safe and does not require validation. The apiHostname key is guaranteed to exist in the platform configuration array, which is statically defined in app/config/platform.php with a fallback default value of 'localhost'.

Likely an incorrect or invalid review comment.

app/controllers/api/messaging.php (1)

4566-4573: Endpoint derivation for push image update looks consistent

Deriving $protocol from _APP_OPTIONS_FORCE_HTTPS and building APPWRITE storage URLs via $endpoint = "$protocol://{$platform['apiHostname']}/v1" is consistent with the create‑push path and the rest of the PR; the updated image['url'] construction is correct.

@loks0n loks0n merged commit 052c8d4 into 1.8.x Dec 16, 2025
72 of 73 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.

2 participants