Repository navigation
fix(sites): make screenshot capture deterministic and diagnosable - #13315
Conversation
The screenshot worker resolved a deployment's domain with findOne and no order, so on deployments carrying several rules the domain was whichever the adapter returned first and an unreachable one failed some captures but not others. Order by $sequence and record the chosen domain and trigger on the span. The HTTP client to the browser shared _APP_SITES_TIMEOUT, which caps a site's own request, so its budget equalled the browser's navigation default and left nothing for the settle, render and encode that follow. Give it _APP_BROWSER_TIMEOUT at 90s and send an explicit 60s navigation budget, so each layer exceeds the one below and the browser can report its own errors. Report the failure reason in the deployment log instead of a bare 'Screenshot capturing failed', which was shown even when the capture succeeded and only the upload failed, and record per-capture duration so cold start is visible.
Greptile SummaryThe PR makes screenshot processing more deterministic and diagnosable.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (3): Last reviewed commit: "fix(sites): keep the existing screenshot..." | Re-trigger Greptile |
|
|
||
| // The first capture pays the site's cold start and the second | ||
| // finds it warm, so record them separately rather than as a total. | ||
| $this->recordDuration($duration, \microtime(true) - $captureStart, $theme); |
There was a problem hiding this comment.
Capture durations exclude failures
When Screenshots\Client::create() throws for a timeout, HTTP error, or invalid response, control skips recordDuration() and the failure path records only the counter. The histogram therefore excludes the slowest failed captures and cannot show elapsed time for the production failures it was added to diagnose.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php
Line: 177
Comment:
**Capture durations exclude failures**
When `Screenshots\Client::create()` throws for a timeout, HTTP error, or invalid response, control skips `recordDuration()` and the failure path records only the counter. The histogram therefore excludes the slowest failed captures and cannot show elapsed time for the production failures it was added to diagnose.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
🔵 Tier A · Mergeable after minor fixes
The screenshot worker now selects deployment rules in sequence order and records the selected domain and trigger on its span. It also measures capture duration separately for light and dark themes and includes exception details in deployment failure logs.
Fix with agent prompt### Issue 1
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php:114
**Cover deterministic rule selection with a regression test**
The existing `testSiteScreenshot` E2E test checks screenshot output but does not distinguish which of multiple deployment rules is selected, so removing this ordering would still pass. Please add an E2E regression with distinguishable rule candidates that verifies the intended selection through observable capture behavior, especially since this query has not been exercised against a real rules table.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 1
⏳ Still open from earlier reviews · 1
Merged |
| Query::equal("projectInternalId", [$project->getSequence()]), | ||
| Query::equal("type", ["deployment"]), | ||
| Query::equal('deploymentInternalId', [$deployment->getSequence()]), | ||
| Query::orderAsc('$sequence'), |
There was a problem hiding this comment.
Cover deterministic rule selection with a regression test
The existing testSiteScreenshot E2E test checks screenshot output but does not distinguish which of multiple deployment rules is selected, so removing this ordering would still pass. Please add an E2E regression with distinguishable rule candidates that verifies the intended selection through observable capture behavior, especially since this query has not been exercised against a real rules table.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php
Line: 114
Comment:
**Cover deterministic rule selection with a regression test**
The existing `testSiteScreenshot` E2E test checks screenshot output but does not distinguish which of multiple deployment rules is selected, so removing this ordering would still pass. Please add an E2E regression with distinguishable rule candidates that verifies the intended selection through observable capture behavior, especially since this query has not been exercised against a real rules table.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
…t worker findOne already breaks ties on $sequence ascending when no unique order is given, so the rule pick was never left to the adapter. The explicit order emits the same ORDER BY and needs no comment.
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Context
Investigating screenshot failures in production turned up three separate causes behind the same
Screenshot capturing failedmessage. This PR covers the ones that live in this repo. The browser service dying is handled separately in appwrite/docker-browser#17.1. The deployment domain was picked non-deterministically
findOneonruleshad no ordering, so the domain was whichever row the adapter returned first:In production 200,411 of 308,919 deployments (65%) carry more than one
type=deploymentrule, and the candidates are not equivalent. On one deployment I tested, one domain served in 0.64s while the other returned a persistent 503 backend read error — same deployment, same build. The capture that picked the second one failed after 30s having received nothing.Now ordered by
$sequence, and the chosenrule.domainandrule.triggerare recorded on the span so the next occurrence is diagnosable from logs instead of requiring a live reproduction.2. The timeout layers were all equal, so none had headroom
The client to the browser used
_APP_SITES_TIMEOUT, which caps a site's own request — an unrelated concern that also happens to default to 30. The browser's navigation timeout defaults to 30s too, and we never sent one.Server-side the sequence is navigate → settle (3–5s, per framework) → render → PNG encode at 1.5×. With both budgets at 30s, the client aborts captures the browser would have completed, and because both deadlines land together the browser can never report why. Every such failure looked identical:
Operation timed out after 30025 milliseconds with 0 bytes received._APP_BROWSER_TIMEOUT, default 90s, replaces the borrowed_APP_SITES_TIMEOUTEach layer now exceeds the one below it.
3. The failure message said nothing, and sometimes said the wrong thing
Screenshot capturing failed. Deployment will continue.carried no reason. Worse, it was shown for failures where the spans recordedscreenshot.count: 2— both screenshots captured fine and only the S3 upload failed. The log now includes the reason.4. Capture duration was never measured
Added a
worker.screenshots.capture.durationhistogram, tagged by theme. Light and dark are recorded separately on purpose: the first capture pays the site's cold start and the second finds it warm, so a combined number hides the thing worth watching. Only a success/failure counter existed before, so how close captures run to the ceiling was invisible.Verification
php -l,composer lintand PHPStan level 4 pass on the changed files. Fullcomposer analyzeand the E2E suite were not run.Review notes
Query::orderAsc('$sequence')is valid perDatabase::INTERNAL_ATTRIBUTESbut has no precedent in this repo. The filter is selective and limited to 1, so I would not expect a filesort, but it was not executed against a realrulestable.trigger=deploymentdomains turn out to be the unreliable ones generally, preferring by trigger explicitly would be better than relying on creation order.