Repository navigation
fix(workers): stop dead-lettering refusals a retry cannot fix - #14545
Conversation
…ing them A schedule that fires after its project is deleted reaches the worker with a project that resolves to nothing. dbForProject then falls back to the platform database, and the run threw 'Collection not found' and was dead-lettered. Nothing can run it on any attempt, so log a warning and acknowledge it.
…er drops them The schedulers sync incrementally from rows whose resourceUpdatedAt moved, so a hard-deleted schedule kept firing from memory until the next full snapshot (up to five minutes). Deactivating the rows reaches them on the next sync; the maintenance sweep removes the inactive rows of deleted projects as before.
An unroutable host, a deployment or site deleted before the capture, and a deployment deleted during it now throw PermanentFailure, so they are not retried. A deployment deleted mid-capture no longer fails on the log append with 'Must define $id attribute' or overwrites the site's preview with an empty one. Page timeouts and other browser errors stay retriable.
|
Review complete. 🟡 1 medium 📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Screenshots worker lacks the deleted-project guard · Screenshots.php:65–78 · // src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php
65 Span::add('project.id', $project->getId());
66
67 $payload = $message->getPayload();
68
69 if (empty($payload)) {
70 throw new \Exception('Missing payload');
71 }
72
73 $screenshotMessage = Screenshot::fromArray($payload);
74 $counter = $telemetry->createCounter('worker.screenshots.capture');
75
76 $deploymentId = $screenshotMessage->deploymentId;The patch adds 🧹 Nitpicks (2) — 🟢 2 low
The change closes race windows where queued work races against project/deployment deletion. Deactivation-with-later-sweep replaces immediate schedule deletion so in-memory schedulers converge via
Reviewed commit: 2c6b8ab |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
🔵 Tier A · Mergeable after minor fixes
The workers now acknowledge function runs whose projects have been deleted, deactivate schedules during project cleanup so schedulers see the change incrementally, and classify unrecoverable screenshot refusals as permanent failures. The screenshot worker also skips log updates for missing deployments and avoids replacing a site's preview when a deployment disappears during capture.
Fix with agent prompt### Issue 1
tests/unit/Platform/Workers/DeletesTest.php:60
**Keep worker behavior tests out of the unit tier**
This test, the new screenshot tests, and the added Functions test invoke worker behavior directly from `tests/unit`. AGENTS.md's Tests rule explicitly says not to unit-test workers (E2E covers those surfaces), so these additions do not follow the repository's required test tier.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 6
Reviewed |
| * project. Deleting the project has to reach the scheduler on its next | ||
| * incremental sync. | ||
| */ | ||
| public function testDeletedProjectSchedulesStopFiringOnTheNextSync(): void |
There was a problem hiding this comment.
Keep worker behavior tests out of the unit tier
This test, the new screenshot tests, and the added Functions test invoke worker behavior directly from tests/unit. AGENTS.md's Tests rule explicitly says not to unit-test workers (E2E covers those surfaces), so these additions do not follow the repository's required test tier.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/unit/Platform/Workers/DeletesTest.php
Line: 60
Comment:
**Keep worker behavior tests out of the unit tier**
This test, the new screenshot tests, and the added Functions test invoke worker behavior directly from `tests/unit`. AGENTS.md's Tests rule explicitly says not to unit-test workers (E2E covers those surfaces), so these additions do not follow the repository's required test tier.
---
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.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What does this PR do?
Some function and screenshot jobs can never succeed, but they were thrown as ordinary errors, so they landed on the dead letter streams and counted toward the "Dead letter stream is growing" alert. This PR stops the ones a retry can't fix. Production evidence is in appwrite-labs/cloud#6470.
Functions: runs of a deleted project. A project the platform no longer has resolves to an empty document, and
dbForProjectfalls back to the platform database. Every scheduled run then threwCollection not foundatFunctions.php:311, withproject.id="". sfo3 got 13 of these from one deleted project, plus about 3 a night since. The worker now logs a warning and acknowledges the run. The project's database is gone, so nothing could run it on a later attempt either.Deletes: why the schedules kept firing for about 4 minutes.
deleteProject()did remove the project'sschedulesrows, but it hard-deleted them. The schedulers sync incrementally from rows whoseresourceUpdatedAtmoved (Scheduler::reconcile(): "a change feed cannot report a hard delete"), so the entries stayed in memory until the next full snapshot, which comes every 30 syncs (300s). The worker now deactivates the rows instead (active=false,resourceUpdatedAt=now), the same way function deletion does. The scheduler drops them on its next sync, about 10s later. The existing maintenance sweep (deleteSchedules,DELETE_TYPE_SCHEDULES) still removes the inactive rows of deleted projects once they are past_APP_MAINTENANCE_RETENTION_SCHEDULES.Screenshots. These now throw
PermanentFailure:Host '<x>' is not publicly routable., from the browser service (HTTP 400). The customer's DNS points at a private address, so every attempt is refused the same way. nyc3 dead-lettered one site's screenshots over and over for this.Deployment not foundandSite not found, when the resource was deleted before the capture ran.Must define $id attribute, the retry then failed withDeployment not found, and the site's preview could be overwritten with an empty one. Now the log append skips a missing deployment, the site keeps its preview, and the job ends once.Page timeouts (
screenshot: Timeout 30000ms exceeded, which is also a 400), connection errors and certificate errors are still retried.Test Plan
Unit tests, each seen failing with its production hunk reverted:
tests/unit/Platform/Workers/FunctionsTest.php::testRunOfDeletedProjectIsAcknowledgedWithoutExecuting(schedule and http). The database double throwsNotFound('Collection not found'), like the platform database does. Red: the sameUtopia\Database\Exception\NotFound: Collection not foundseen in production.tests/unit/Platform/Workers/DeletesTest.php::testDeletedProjectSchedulesStopFiringOnTheNextSync. This runs the realSchedulerwithSource\Functionsover a Memory-adapter database that uses the realschedules/projects/functionsschemas. Red with the old hard delete:Failed asserting that 3 is identical to 1after the incremental sync.tests/unit/Platform/Modules/Functions/Workers/ScreenshotsTest.php, which drives the real worker with Memory databases and a fake browser that returns the service's real error bodies. Red: unroutable host asAppwrite\Screenshots\Exception, deleted deployment asException, deleted mid-capture asUtopia\Database\Exception(Must define $id attribute). The timeout case is a guard and passes both ways.pint --test,phpstanon the changed files, andrector --dry-runon the tests are clean.tests/unit/Platform,tests/unit/Workers,tests/unit/Screenshotsandtests/unit/Schedulepass (346 + 6 tests).There is no E2E test for the scheduler ↔ deletes path. The Deletes test covers that seam in-process, but it doesn't run a real database engine.
Related PRs and Issues
Checklist