Repository navigation
fix(queue): ship lean project and user contexts instead of whole documents - #14477
Conversation
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
🧹 Nitpicks (1) — 🟢 1 low
The PR replaces full user/project document serialization in queue and event messages with lean
Note: a few scans hit their step limits before publishing, but their verified conclusions were recovered and adjudicated; coverage across all 52 changed files is intact. Reviewed commit: 41d93d0 |
🔵 Tier A · Mergeable after minor fixes
This change serializes compact project and user contexts in queue messages, reduces audit payload retention, and resolves console projects from worker configuration. It also removes unused user fields from database and messaging queue messages and updates related unit-test setup.
Fix with agent prompt### Issue 1
tests/unit/Event/Message/ProjectContextTest.php:33
**Keep a round-trip assertion for the database field**
This assertion only covers `fromDocument()->toArray()`; if `fromArray()` stops restoring `database`, the test still passes. The removed round-trip test covered this field, and workers decode queued project contexts with `fromArray()`, so retaining that assertion would protect the queue contract.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 8
⏳ Still open from earlier reviews · 1
Reviewed |
Security rulesNo new WARNING or ERROR findings from security rules. 19 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)
|
There was a problem hiding this comment.
This PR slims queue message payloads via new ProjectContext/UserContext DTOs and adds a telemetry histogram around queue publishers, but silently disables audit payload capture for all endpoints.
Key findings
- 🟡 Restore
audits.payloaddefault oftrue— api.php:1063 - 🟡 Avoid double
json_encodewhen sizing queue payloads — Telemetry.php:75
45b1467 to
dd88996
Compare
…text Queue publishers route jobs on the project database DSN, so the lean project context has to carry it instead of the whole project document. UserContext replaces whole user documents (sessions, tokens, memberships, targets) in queue payloads with the identity fields workers actually read. Empty fields are dropped on serialization so an empty context stays an empty Document for isEmpty() checks.
No consumer reads the audit payload (cloud Activity writes data '' and CE has no audits worker), yet every audited route attached the full response body by default. That is how a single v1-audits job reached 138MB and OOMKilled workers. Routes can still opt in via the audits.payload label.
…ayload Workers used the console project document straight from the message payload, so publishers had to ship the full console document. Resolving it from the console resource (copied per job so the shared instance and its nested documents are never mutated) lets publishers send lean console context, while Deletes still reads auths.duration from the configured console project.
Workers re-fetch the project by $id, so keys, webhooks, templates and secrets copied into these messages went unread and inflated jobs (2026-10-13 v1-audits OOM).
Queue messages carried whole user Documents (sessions, tokens, memberships, targets, password hash), which let a single v1-audits job reach 138MB and OOMKill workers. Consumers only read $id, $sequence, name, email and type (cloud Activity for audits, the Functions worker for the execution JWT and user headers), so Audit and Func now serialize users through UserContext and projects through ProjectContext. The Databases and Messaging workers never read user, so both messages drop the property entirely; no CE caller passes it.
The webhooks worker reads only the user id for X-Appwrite-Webhook-User-Id; the full user with sessions and secrets rode every webhook job.
Without _APP_DOMAIN the worker treats every rule as the main domain and skips DNS validation, so the test only passed where the docker env set it.
dd88996 to
61f44f4
Compare
Main gained lean queue payloads (#14477): ProjectContext/UserContext in queue messages, the worker resolving the console project from config, and audits no longer shipping response bodies. The only conflict was the worker projectContext resource signature; the branch's explicit ProjectContext return type is kept alongside main's console-from-config project resolution. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follows main's lean queue payloads (#14477): function, webhook, event, delete and audit messages carry ProjectContext and UserContext instead of whole documents, and audits record no payload unless the route asks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
Queue messages serialized whole Documents with
getArrayCopy(): the full project (keys, webhooks, platforms, templates, decrypted SMTP/OAuth secrets), the full user (sessions with secrets, tokens, memberships, targets, password hash), and the auditpayload(the whole HTTP response). Workers re-fetch the project by$idand read at most five user fields, so almost all of it was dead weight. On 2026-10-13 a single ~138MBv1-auditsjob sat in the queue for 14h and OOMKilled everyworker-auditspod that reserved it (~360 restarts).UserContext($id,$sequence,name,email,type);databaseadded toProjectContextEvent/Messageproject→ProjectContextuser→UserContextuser,impersonatorUser), Func, webhook/event trimuserdropped (never read)audits.payloaddefaults to false; S3 audits send[]shared/api.php,S3/Base.phpapp/init/worker/message.phpKept full on purpose: Delete
document(row is gone before publish), Func httpfunction(vars used directly), Migrationmigration(working state), Execution records, and every customer-facing payload (webhook body, function event body, realtime).Benchmark
5,598 real jobs sampled from fra1 queue replicas, decoded with the new
fromArray()and re-encoded withtoArray(), weighted by 1.28h of queue throughput.v1-auditsv1-executionsv1-functionsv1-webhooksv1-stats-resourcesv1-stats-usage(119 GiB/day of metrics) is unaffected. Every sampled old-format job decodes with the new classes, so in-flight jobs survive the deploy.Test Plan
composer lint, phpstan and the existing unit suite pass;ProjectContextTestnow expectsdatabase.CertificatesDomainValidationTestpassed only with_APP_DOMAINset; it now pins the validation domain.Related PRs and Issues
Server, no re-encode).user:fromDatabaseMessagein the fourDelete.phpactions, return the injected console project in cloud's workermessage.php, trim cloud messages (threats, growth, ZDT, dedicated databases).Checklist
Related: #14478