Skip to content

fix(api): read the onboarding project from the request params - #14807

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/onboarding-project-from-request
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/onboarding-project-from-request

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

The onboarding shutdown hook in app/controllers/shared/api.php resolved the target project for organization routes from $route->getParamsValues(). The Route object is shared by all requests in a worker process, and the framework writes each request's validated values onto it, so after the hook's own I/O the values could belong to a different request. The hook now takes projectId from the injected params, which come from the current dispatch frame.

The framework write (Hook::setParamValue() in packages/http) is left in place: getParamsValues() is public API of the package and nothing in Appwrite reads it any more, so removing it is a separate, breaking change for the package.

Test plan

  • PHPStan and Pint on the touched files
  • E2E StagesConsoleClientTest::testCreateProjectKeyFromConsoleCompletesStageOnPathProject: creating a project key through /v1/organization/projects/:projectId/keys on the console project completes organization.createProjectKey on the project in the path

Related: appwrite-labs/cloud#6672

The onboarding shutdown hook read projectId back from the route's param values. The route object is shared by every request in the worker, so after the hook's own I/O it could hold another request's values. The dispatch-frame params belong to the current request only.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟠 1 high

📍 Findings outside the diff (1) — 🟠 1 high — defects on lines GitHub can't attach comments to

🟠 High — Onboarding state read before lock, lost update under concurrency · api.php:1288–1339 · unchanged line

// app/controllers/shared/api.php
1288	        $byMethod = $project->getAttribute('onboarding', []);
1289	        if (! \is_array($byMethod)) {
1290	            $byMethod = [];
1291	        }
1292	
1293	        $actorType = ($apiKey !== null && $apiKey->getRole() === User::ROLE_KEYS)
1294	            ? match ($apiKey->getType()) {
1295	                API_KEY_ACCOUNT => ACTOR_TYPE_KEY_ACCOUNT,
1296	                API_KEY_ORGANIZATION => ACTOR_TYPE_KEY_ORGANIZATION,
1297	                API_KEY_STANDARD, API_KEY_EPHEMERAL => ACTOR_TYPE_KEY_PROJECT,
1298	                default => ACTOR_TYPE_KEY_PROJECT,
1299	            }

$byMethod is read from the project document at line 1288 and merged outside the tryWithKey lock acquired at line 1329, so the lock does not cover the read-modify-write cycle. Two concurrent requests completing different stages each read the same stale snapshot and the last writer overwrites the other's stage; when they do collide, tryWithKey with skipOnContention: true returns null silently, so the loser skips its write instead of re-reading and retrying. The user's completed onboarding stage is permanently lost and the console keeps showing it as incomplete.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Assert key body and console-project stage untouched (StagesBase.php:218) — The new test asserts only HTTP 201 and eventual stage completion on the path project, but never checks the response body (name, scopes) or that the console project's own organization.createProjectKey stage remained untouched (tests/e2e/Services/Project/StagesBase.php:218-225).

This PR makes the api shutdown hook inject the router params resource and read projectId from it, so the onboarding stage for key creation is attributed to the path-named project when the request runs against the console project. It adds an e2e test asserting that creating a project key via the organization route completes the organization.createProjectKey stage on that project.

Files Change
app/controllers/shared/api.php Injects params into the onboarding shutdown hook and resolves projectId from the router match instead of $route->getParamsValues().
tests/e2e/Services/Project/StagesBase.php Adds testCreateProjectKeyFromConsoleCompletesStageOnPathProject covering key creation via the organization route and eventual stage completion.

Note: the correctness, security, and api-data scans confirmed the injection wiring is behavior-preserving — params matches the previous param source for the org-keys routes.

Reviewed commit: 6629b26

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

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The onboarding shutdown hook now resolves the project ID from dispatch-local request params instead of mutable shared Route state. An E2E test exercises project-key creation through the console against a path project, verifies the returned key name and scopes, and waits for that project's onboarding stage to complete.

Latest changes: The latest commit adds assertions that the created key response contains the requested name and scopes.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
app/controllers/shared/api.php Uses request-local params to resolve the onboarding project for organization routes.
tests/e2e/Services/Project/StagesBase.php Covers console project-key creation and verifies the response and onboarding stage for the path project.

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

@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

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Thanks. The lost-update finding is about lines this PR leaves as they were: the read-modify-write of onboarding with tryWithKey(skipOnContention) already existed, and the comment there documents the last-write trade-off. Fixing it means re-reading the document inside the lock (or merging keys atomically), which changes how the onboarding write behaves. That belongs in its own PR, not this hardening fix. For the nitpick, the test now also asserts the created key's name and scopes. A console-project stage check doesn't apply, because /projects/console/stages isn't a project the test can read.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/onboarding-project-from-request (after).

Metric Before After Change
🚀 Requests/sec 180.94 176.82 ⚪ -2.3%
⏱️ Latency P50 94.31 ms 98.06 ms ⚪ +4%
⏱️ Latency P95 230.66 ms 229.34 ms ⚪ -0.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 98.06 229.34 11,400 176.82 -1.32
Account 183.05 340.57 600 10.06 +16.55
TablesDB 94.05 179.38 6,200 100 +10.52
Storage 92.78 208.06 3,000 49.63 -3.17
Functions 140.13 263.82 1,600 27.09 -33.29

Top API waits (after)

API request Max wait (ms)
account.name.update 513.49
functions.create 472.7
account.prefs.update 439.61
storage.buckets.create 410.79
functions.variables.update 408.35

@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.

@ChiragAgg5k
ChiragAgg5k merged commit bd8936e into main Oct 22, 2026
66 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/onboarding-project-from-request branch October 22, 2026 18:03
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…t-from-request

fix(api): read the onboarding project from the request params

(cherry picked from commit bd8936e)
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.

1 participant