Skip to content

fix(sites): keep screenshot worker within one HTTP timeout budget - #15077

Merged
ChiragAgg5k merged 4 commits into
mainfrom
cursor/fix-screenshot-worker-flake-ec62
Oct 29, 2026
Merged

ChiragAgg5k merged 4 commits into
mainfrom
cursor/fix-screenshot-worker-flake-ec62

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Evidence

Flaky failure on Tests\E2E\Services\Sites\SitesCustomServerTest::testDeleteDeployment (Sites / PostgreSQL dedicated lane): deployment reaches ready, buildLogs ends with Screenshot capturing started. and never gains Screenshot capturing finished. or Screenshot capturing failed. before the test’s 120s assertEventually window expires. Reported on three CI runs (2026-10-17–10-23); two passed on rerun. Still observed after e86564f (delete/snapshot race fix).

Root cause

The screenshots worker logged “started” then called Appwrite\Screenshots\Client::create() twice in series (light, then dark). Each HTTP call is bounded by _APP_SITES_TIMEOUT (60s in CI). Worst case wall time for one job is therefore ~120s of browser work plus DB I/O, while the test waits only 120s for a terminal log line. Under load the job can still be inside the first or second capture when the assertion times out, so logs stay at “started” with no “failed” line yet (the worker has not thrown).

Parallel Sites E2E increases how many jobs are in flight, which lengthens queue wait, but the flake signature here is started without any terminal line within 120s while status is already ready — consistent with the per-job 2× timeout budget, not with production screenshot worker concurrency settings.

This is unrelated to the deployment-delete snapshot race fixed in e86564f.

Fix

  1. Screenshots worker — After routing/bucket checks, capture light and dark concurrently in the Swoole worker (go() + channel) so one job completes within ~one HTTP timeout instead of two. Log “capturing started” immediately before capture. Sequential fallback when not in a coroutine (unit/CLI).

  2. testDeleteDeployment — Treat populated screenshotLight / screenshotDark as completion signals alongside finished/failed buildLogs (same terminal outcomes the worker already writes).

  3. Screenshots concurrency — the screenshots queue drops from 8 to 4 jobs (app/config/workers.php, and _APP_WORKER_MAX_COROUTINES=4 on appwrite-worker-screenshots in docker-compose.yml and the console compose generator). With two captures per job the browser still sees at most 8 at once, and throughput is similar because each job takes about half as long. The combined worker pool size (sum of per-queue caps) goes from 79 to 75.

No CI-only browser compose change in this PR: saturated browser requests should hit the existing HTTP timeout and append “failed”, which the test already accepts. If Sites CI still shows pre-timeout stalls after this lands, browser capacity should be tuned in CI compose/env only (e.g. .github compose overlay or workflow env for appwrite-browser), not worker defaults.

Verification

Check Result
tests/unit/Workers/JobsTest.php OK
tests/unit/Screenshots/ClientTest.php OK
testDeleteDeployment (single run with fix, local compose) Passed (~71s) when stack stable
20× paratest Sites loop (before/after) Not completed reliably on the cloud agent VM (appwrite exited on DB/Redis timeouts under sustained load). CI Sites lane remains the authoritative stress test.

No retries, sleeps, timeout changes, or weaker failure handling were added.

Related

  • appwrite-labs/cloud#6673
Open in Web Open in Cursor 

Related: appwrite-labs/cloud#6673

Parallel Sites E2E runs enqueue many screenshot jobs at once. Each job
called the browser twice in series while the HTTP client timeout is 60s,
so a loaded browser could leave buildLogs at "capturing started" until
after the test's 120s wait expired.

Capture light and dark previews concurrently in the Swoole worker, log
"started" only once routing is ready, and process one screenshots queue
job at a time so Playwright is not flooded.

Co-authored-by: Chirag Aggarwal <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high

💬 Inline comments (1)

  • 🟠 Dedicated-mode override defeats the screenshots cap — workers.php:61

The change pins the screenshots worker to a single coroutine with an inline rationale about Playwright capture load, and extends tests for the screenshots/themes flow (Sites custom-server e2e plus a workers jobs unit test).

Files Change
app/config/workers.php Lowers the screenshots worker from 8 coroutines to 1, citing capture timeouts.
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Adjusts the screenshots worker logic accompanying the concurrency change.
tests/e2e/Services/Sites/SitesCustomServerTest.php Updates Sites custom-server e2e coverage for the screenshots behavior.
tests/unit/Workers/JobsTest.php Adds/updates unit coverage for workers job configuration.

Reviewed commit: 71cf41c

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 28, 2026
@ghost

ghost commented Oct 28, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental telemetry change records each capture outcome without altering capture or error-handling behavior.

The PR updates Sites screenshot capture to request light and dark previews concurrently in the worker, records per-theme capture duration, and lowers screenshot queue concurrency to preserve the intended browser request cap. It also updates the deployment deletion E2E completion checks and aligns the Compose generator, checked-in Compose configuration, and self-hosting topology documentation with the new worker limits.

Latest changes: The newest commit adds a duration histogram for each light and dark capture, recording elapsed time and success or failure while keeping telemetry errors from affecting screenshot processing.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
app/config/workers.php Lowers screenshot queue concurrency to account for two parallel theme captures per job.
apps/console/src/content/docs/advanced/self-hosting/configuration/topologies/index.markdoc Documents the screenshots worker concurrency cap and parallel theme capture behavior.
apps/console/src/lib/docs/compose-generator/composeData.ts Updates generated worker pool sizing and screenshots worker coroutine limits.
docker-compose.yml Aligns checked-in Compose worker pool sizing and screenshots coroutine limits.
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Captures light and dark previews concurrently, records per-theme duration telemetry, and retains sequential capture outside coroutines.
tests/e2e/Services/Sites/SitesCustomServerTest.php Treats populated screenshot fields as completion signals in the deployment deletion test.

Reviewed the commits since e30f93c · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

…hput

Queue concurrency is a product default, not part of the CI flake fix.
The per-job wall-time race is addressed by parallel theme capture.

Co-authored-by: Chirag Aggarwal <[email protected]>
Comment thread app/config/workers.php Resolved

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR reduces the screenshots worker concurrency (coroutines 8→1) and updates the related e2e and unit tests, but the new cap is silently overridden in the dedicated worker topology, so the intended fix only takes effect in the combined mode.

Key findings

  • 🟠 Dedicated-mode override defeats the screenshots cap — workers.php:61

Comment thread app/config/workers.php Resolved
@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/fix-screenshot-worker-flake-ec62 (after).

Metric Before After Change
🚀 Requests/sec 213.01 221.89 ⚪ +4.2%
⏱️ Latency P50 80.86 ms 78.88 ms ⚪ -2.4%
⏱️ Latency P95 190.47 ms 177.93 ms 🟢 -6.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 78.88 177.93 13,680 221.89 -12.53
Account 140.92 270.52 720 12.45 -2.28
TablesDB 77.67 144.31 7,440 123.19 +3.34
Storage 71.67 166.5 3,600 60.96 -31.43
Functions 105.23 196.3 1,920 33.18 -25.64

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.create 448.01
storage.buckets.create 424.91
account.name.update 387.77
functions.delete 319.58
functions.create 311.52

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Tier B · See the inline comments. Summary

Each job now captures light and dark in parallel, so 8 jobs would put 16 captures on the browser. 4 jobs keeps it at 8 with similar throughput, since each job finishes in about half the time. The dedicated worker's _APP_WORKER_MAX_COROUTINES and the combined pool size (79 -> 75) follow.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@15077

commit: 4f8c849

…-worker-flake-ec62

# Conflicts:
#	src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php
@ChiragAgg5k
ChiragAgg5k merged commit 15866ed into main Oct 29, 2026
73 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the cursor/fix-screenshot-worker-flake-ec62 branch October 29, 2026 13:22
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