Repository navigation
fix: publish worker event payloads through the response model - #14316
Conversation
The functions worker built the executions update payload from a fresh in-memory document, so webhook, realtime and function-event payloads for async, scheduled and event-triggered executions had no $createdAt or $updatedAt, and #14295's response formatting never reached them. Model::payload() now shapes worker-built payloads the way the response does, including ISO 8601 datetimes, and the worker stamps the execution with its timestamps, keeping the creation time of executions queued by the API.
|
Review complete. 🟡 1 medium 📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Schedule trigger drops propagated execution // src/Appwrite/Platform/Workers/Functions.php
317 $this->execute(
318 dbForProject: $dbForProject,
319 queueForWebhooks: $queueForWebhooks,
320 publisherForFunctions: $publisherForFunctions,
321 queueForRealtime: $queueForRealtime,
322 queueForEvents: $queueForEvents,
323 bus: $bus,
324 project: $project,
325 function: $function,
326 executor: $executor,
327 trigger: 'schedule',
328 path: $path,The PR propagates the API-created execution's creation time to the functions worker for the This change centralizes event-payload shaping:
Reviewed commit: f0f789f |
🟢 Tier S · Ready to merge
This change adds a shared model payload formatter for worker-published events and reuses the response datetime normalization. It also stamps function execution timestamps, preserving the API creation time for queued async HTTP executions, and updates event payload builders and webhook E2E assertions.
📂 Walkthrough · 7
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Summary
Follow-up to #14295. That PR made
Response::output()render everydatetimefield in ISO 8601 with an offset, so event payloads copied from$response->getPayload()got it for free. Payloads that workers build themselves never pass through the response, so thefunctions.*.executions.*.updateevent for async, scheduled and event-triggered executions still went out without the response model's formatting, and in fact without$createdAt/$updatedAtat all.Root cause
The functions worker creates the execution as a fresh in-memory
Documentwith no timestamps (the execution store adds them only when it persists the row) and publishesgetArrayCopy(array_keys($model->getRules()))of it. So the webhook/realtime/function-event payload had no$createdAtor$updatedAt. Captured onorigin/main:Because the store fills in a missing
$createdAtwith the time it persists the row, an async execution's stored$createdAtalso moved from the time the API queued it to the time the worker finished it.The same hand-rolled
getArrayCopy(array_keys($model->getRules()))payload was also built inJobs::dispatchUpdate(deployments update), the certificates worker (rules.*.update) andFunctions/Create(rules.*.create). Those documents come back from the database, so their datetimes were already ISO 8601, but they skipped the shared formatting as well.Fix
Model::payload(Document)shapes a document as the model for an event published outside a response: the model'sfilter(), only the model's keys, and datetimes throughModel::formatDatetime().formatDatetime()moved from a private method onResponseto a public static onModel, soResponse::output()and worker payloads use the same normaliser and the formatting stays in one place.$createdAt/$updatedAtand keeps the$createdAtof an execution the API queued (async HTTP).$updatedAtis refreshed when the run finishes.(new Model())->payload($document).Tests
E2E only. I extended existing tests and added no new flows:
ProjectWebhooks/WebhooksCustomServerTest::testExecutions: theexecutions.*.updatewebhook now asserts that$createdAtand$updatedAtmatchY-m-d\TH:i:s.uP(the strictDateTime::createFromFormatcheck used in the account tests), and that$createdAtequals the one returned when the async execution was created.ProjectWebhooks/WebhooksCustomServerTest::testCreateDeployment: after the build completes, the deployments update webhook published by the worker asserts the same datetime format.Failing before the fix (
origin/mainsource, tests from this branch):The deployment assertion already passes on
origin/main, because that document is read back from the database. It is there as regression coverage for the worker-built deployment payload.After the fix the captured payload is
'createdAt' => '2026-10-09T13:45:36.926+00:00', 'updatedAt' => '2026-10-09T13:45:46.921+00:00'.Verification
Run locally on a docker stack built from this branch:
ProjectWebhooks: OK (82 tests, 7358 assertions)Functions: OK (88 tests, 2606 assertions)Webhooks: OK (135 tests, 1032 assertions)FunctionsSchedule: OK (15 tests, 392 assertions)composer lint): pass on the changed filesCloses #14317