Skip to content

Add execution delay headers to async, event-triggered and sync executions #10191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 1.7.x
Choose a base branch
from

Conversation

vermakhushboo
Copy link
Member

@vermakhushboo vermakhushboo commented Jul 23, 2025

What does this PR do?

  • Add x-appwrite-scheduled-at, x-appwrite-executed-at and x-appwrite-execution-delay headers to sync, async and event-triggered executions.
  • Add relevant tests to ensure flow works as expected.

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@vermakhushboo vermakhushboo requested a review from Meldiron July 23, 2025 07:21
Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

📝 Walkthrough

Walkthrough

This change set introduces the tracking and propagation of function execution timing headers throughout the Appwrite platform. A new header, x-appwrite-scheduled-at, is generated and included in function execution requests and added to the allowed headers list. When functions are executed, the worker records the actual execution time (x-appwrite-executed-at) and calculates the execution delay (x-appwrite-execution-delay) between the scheduled and actual execution. These headers are merged into execution documents and propagated through the system. The function runtime code and end-to-end tests have been updated to validate the presence and correctness of these headers, with new assertions and logging added. Minor documentation corrections were also made.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • Meldiron

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd2a04b and 2f94b71.

📒 Files selected for processing (3)
  • app/controllers/general.php (1 hunks)
  • app/controllers/shared/api.php (1 hunks)
  • tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/controllers/shared/api.php
  • app/controllers/general.php
⏰ 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 (1)
tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php (1)

121-121: LGTM! Test assertion correctly updated for new timing header.

The assertion now expects exactly one request header instead of zero, which aligns with the introduction of the x-appwrite-scheduled-at header for scheduled executions as described in the PR objectives.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-add-new-headers-to-async-executions

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Jul 23, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
git 2.45.3-r0 CVE-2025-48384 HIGH
git 2.45.3-r0 CVE-2025-48385 HIGH
git-init-template 2.45.3-r0 CVE-2025-48384 HIGH
git-init-template 2.45.3-r0 CVE-2025-48385 HIGH
icu 74.2-r0 CVE-2025-5222 HIGH
icu-data-en 74.2-r0 CVE-2025-5222 HIGH
icu-dev 74.2-r0 CVE-2025-5222 HIGH
icu-libs 74.2-r0 CVE-2025-5222 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
pyc 3.12.9-r0 CVE-2024-12718 HIGH
pyc 3.12.9-r0 CVE-2025-4138 HIGH
pyc 3.12.9-r0 CVE-2025-4330 HIGH
pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3 3.12.9-r0 CVE-2024-12718 HIGH
python3 3.12.9-r0 CVE-2025-4138 HIGH
python3 3.12.9-r0 CVE-2025-4330 HIGH
python3 3.12.9-r0 CVE-2025-4517 HIGH
python3-pyc 3.12.9-r0 CVE-2024-12718 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4138 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4330 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2024-12718 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4138 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4330 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4517 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 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: 3

🧹 Nitpick comments (3)
app/controllers/shared/api.php (1)

716-721: Consider a more descriptive variable name.

The implementation correctly adds the scheduling timestamp header. However, the variable name $scheduledAt might be misleading since this represents when the function is queued for execution rather than a user-scheduled execution time.

Consider renaming to $queuedAt or $triggeredAt for clarity:

-            $scheduledAt = new \DateTime();
+            $queuedAt = new \DateTime();

             $queueForFunctions
-                ->setHeaders(['x-appwrite-scheduled-at' => $scheduledAt->format('Y-m-d\TH:i:s.v\Z')])
+                ->setHeaders(['x-appwrite-scheduled-at' => $queuedAt->format('Y-m-d\TH:i:s.v\Z')])

The ISO 8601 format with milliseconds and UTC timezone is appropriate for precise timing tracking.

app/controllers/general.php (1)

60-60: Consider implementing the header logic or removing the placeholder comment.

This TODO comment suggests headers should be added here, but no implementation is provided. Either implement the necessary header logic or remove the placeholder comment to avoid leaving incomplete TODOs in the codebase.

tests/e2e/Services/Functions/FunctionsCustomServerTest.php (1)

2314-2322: Consider using assertEventually for more robust async execution polling

While the fixed 5-second sleep works, consider using $this->assertEventually() pattern used elsewhere in this file for more reliable async execution polling. However, if the sleep is intentional to ensure meaningful delay values for timing validation, the current approach is acceptable.

-        sleep(5);
-
-        $execution = $this->getExecution($functionId, $executionId);
-        $this->assertEquals(200, $execution['headers']['status-code']);
-        $this->assertEquals('completed', $execution['body']['status']);
-        $this->assertEquals(200, $execution['body']['responseStatusCode']);
-        $this->assertGreaterThan(0, $execution['body']['duration']);
-        $this->assertNotEmpty($execution['body']['logs']);
-        $this->assertNotEmpty($execution['body']['responseHeaders']);
+        $this->assertEventually(function () use ($functionId, $executionId) {
+            $execution = $this->getExecution($functionId, $executionId);
+            $this->assertEquals(200, $execution['headers']['status-code']);
+            $this->assertEquals('completed', $execution['body']['status']);
+            $this->assertEquals(200, $execution['body']['responseStatusCode']);
+            $this->assertGreaterThan(0, $execution['body']['duration']);
+            $this->assertNotEmpty($execution['body']['logs']);
+            $this->assertNotEmpty($execution['body']['responseHeaders']);
+            return $execution;
+        }, 10000, 500);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd39bd6 and aeb497a.

📒 Files selected for processing (8)
  • app/controllers/general.php (2 hunks)
  • app/controllers/shared/api.php (1 hunks)
  • app/init/constants.php (1 hunks)
  • src/Appwrite/Event/Func.php (1 hunks)
  • src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php (1 hunks)
  • src/Appwrite/Platform/Workers/Functions.php (2 hunks)
  • tests/e2e/Services/Functions/FunctionsCustomServerTest.php (1 hunks)
  • tests/resources/functions/basic/index.js (1 hunks)
🧬 Code Graph Analysis (1)
app/controllers/shared/api.php (1)
src/Appwrite/Event/Func.php (1)
  • setHeaders (167-172)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/controllers/shared/api.php (1)
src/Appwrite/Event/Func.php (1)
  • setHeaders (167-172)
⏰ 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 (10)
src/Appwrite/Event/Func.php (1)

164-164: LGTM! Documentation correction.

The PHPDoc parameter type has been correctly updated to match the actual method signature and usage patterns. The method accepts an array of headers, not a string.

src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php (1)

224-225: LGTM! Consistent timestamp header implementation.

The addition of the x-appwrite-scheduled-at header is correctly implemented with consistent formatting (Y-m-d\TH:i:s.v\Z) that matches the usage in other parts of the codebase. The variable name $currentTime is more descriptive than $scheduledAt used elsewhere.

This header will enable accurate execution delay tracking when combined with the execution timestamp recorded during function processing.

app/init/constants.php (1)

145-145: LGTM! Essential allowlist update.

Adding x-appwrite-scheduled-at to the function request headers allowlist is necessary for the execution delay tracking feature to work properly. Without this addition, the header would be filtered out during function execution preparation.

The header name follows the established x-appwrite- convention used throughout the codebase.

tests/resources/functions/basic/index.js (1)

11-27: LGTM! Consistent header validation logging implementation.

The new timing header validations follow the same pattern as the existing JWT validation, which maintains consistency. The three headers being validated (x-appwrite-execution-delay, x-appwrite-scheduled-at, x-appwrite-executed-at) align perfectly with the PR objective of tracking execution delay for async executions.

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

455-460: LGTM! Proper header merging for existing executions.

The logic correctly merges the new timing headers into existing execution headers when the status is not "processing". This ensures that timing information is preserved when updating existing execution documents.

tests/e2e/Services/Functions/FunctionsCustomServerTest.php (5)

2288-2295: LGTM - Function setup follows established patterns

The function setup is correctly configured with appropriate parameters for testing execution headers functionality.


2297-2304: LGTM - Deployment setup is correct

The deployment setup properly creates and activates the function deployment with appropriate validation.


2305-2312: LGTM - Async execution creation is properly handled

The async execution is created correctly with proper status code validation and execution ID extraction.


2323-2331: LGTM - Header validation logic is comprehensive and correct

The header validation properly:

  • Extracts headers into a readable format using array_column
  • Validates presence of all required timing headers
  • Ensures the execution delay is numeric
  • Correctly validates timestamp ordering (executed-at > scheduled-at)
  • Verifies function-level validation through log messages

2333-2334: LGTM - Proper test cleanup

The cleanup follows the established pattern used throughout the test file.

Copy link

github-actions bot commented Jul 23, 2025

✨ Benchmark results

  • Requests per second: 966
  • Requests with 200 status code: 174,001
  • P99 latency: 0.189027696

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 966 923
200 174,001 166,137
P99 0.189027696 0.210620326

@vermakhushboo vermakhushboo changed the title Add execution delay headers to async executions Add execution delay headers to async, event-triggered and sync executions Jul 28, 2025
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