Skip to content

Enforce the self-hosted organization limit per instance - #13585

Merged
ChiragAgg5k merged 4 commits into
mainfrom
fix/self-hosted-instance-organization-limit
Sep 10, 2026
Merged

ChiragAgg5k merged 4 commits into
mainfrom
fix/self-hosted-instance-organization-limit

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Enforce one console organization per self-hosted instance, rather than relying on the frontend restriction or an account-scoped limit that can be bypassed by signing up again.

  • Allow creation only while the console teams collection is empty, checked without caller permission filtering.
  • Serialize the check and creation transaction with an instance-wide distributed lock. Lock contention returns 409 general_resource_locked; it never falls back to unlocked creation.
  • Return 403 organization_creation_prohibited with invitation guidance once an organization exists.
  • Preserve existing multi-org installations, invitations, project ownership/access, and application-project teams. No consolidation migration.
  • No production toggle or test bypass. The policy remains enforced when _APP_LOCKING_ENABLED=disabled.

Frontend guidance, retry suppression, and corrected self-hosting docs: https://github.com/appwrite/vibes/pull/326. This intentionally tightens the API policy beyond the console behavior discussed in vibes #251.

Tests and fixtures

The focused policy regression stays in the existing TeamsConsoleClientTest.php; no new backend test file.

Console organizations needed as prerequisites by existing tests are now seeded as pre-existing database fixtures, with a confirmed owner membership and user-cache invalidation. The fixture response is a real authorized GET /teams/{id} (200), not a fabricated successful create response. Application teams still use the real create API (201). Existing permission, membership, project, and failure assertions remain; fixture setup no longer expects a prohibited console create to succeed.

CI runs the fresh-instance policy method before parallel Teams tests seed legacy organizations. _APP_E2E_FRESH_INSTANCE only selects that test in the test runner; production code does not read it.

Verification

Passing

Platform database Fresh-instance policy regression Teams, four parallel processes
PostgreSQL Passed 47 passed; fresh-instance method skipped here
MariaDB 10.11 Passed 47 passed; fresh-instance method skipped here
MongoDB 8 Passed, with _APP_LOCKING_ENABLED=disabled 47 passed; fresh-instance method skipped here

The separately run policy test covers four concurrent requests across two accounts, exactly one created organization, owner rejection, and rejection for a newly registered account that sees zero organizations.

docker compose exec -T -e _APP_E2E_FRESH_INSTANCE=enabled appwrite \
  test tests/e2e/Services/Teams/TeamsConsoleClientTest.php --filter=testCreateOrganization

docker compose exec -T appwrite vendor/bin/paratest \
  --processes 4 --functional tests/e2e/Services/Teams

Additional PostgreSQL checks:

  • Projects projectsCRUD group: 5 tests, 241 assertions passed (creation, transfer, listing, select queries, mock numbers).
  • Project schedules: 4 tests, 78 assertions passed.
  • Account deletion with organization membership: 1 test, 7 assertions passed.
  • Users: 54 tests passed both in four-process functional mode (753 assertions) and sequentially (701 assertions). CI exposed shared-project contamination in the cursor test; that test now gets a fresh project, with every cursor assertion retained.
  • Pint and PHPStan on changed PHP files, plus git diff --check: passed.
  • Legacy-state verification: created two organizations/projects through the pre-change API, switched to the patched action without resetting data, and verified both remained accessible/writable with original project ownership while a third organization was rejected.

Real self-hosted UI and API

Ran Playwright against a fresh isolated PostgreSQL instance, the companion frontend, a real mail worker, and a local mail catcher:

  1. First signup provisioned one Personal Projects organization and My first project.
  2. A second signup made exactly one denied organization-create request and landed on /account with persistent invitation guidance, including after reload. Authenticated API reads returned zero visible organizations/projects.
  3. The owner sent an invitation through the real API. The recipient opened the delivered email link and accepted through the UI.
  4. The recipient saw the original project ID; the owner's project count stayed one. Invitation guidance disappeared after access was granted.

First account:

First account with the instance organization and initial project

Uninvited account after reload:

Persistent invitation guidance

After accepting the email invitation:

Invited account accessing the original project

Synthetic accounts only. These are application screenshots, not generated evidence pages. Usage collection was disabled in the isolated stack, hence “Usage unavailable.”

Known baseline failures / scope of verification

  • The separate Services/Organization suite still has 7 failures. Reproduced failures using the pre-policy Teams handler and original test setup: it requests console teams in project-admin mode, which returns 400 Admin mode is not allowed for console project. The suite also contains duplicated /v1 URL prefixes. Its contract assertions were not removed or weakened to turn it green.
  • The companion frontend's global typecheck fails on the base revision too; comparison against unchanged HEAD found zero additional diagnostics.
  • The entire Appwrite E2E matrix was not run locally; Git-provider integration and other unrelated service suites are not claimed as passing. The affected shared fixture and the targeted suites above were verified.

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/self-hosted-instance-organization-limit (after).

Metric Before After Change
🚀 Requests/sec 203.46 205.27 ⚪ +0.9%
⏱️ Latency P50 85.01 ms 84.71 ms ⚪ -0.4%
⏱️ Latency P95 201.84 ms 199.25 ms ⚪ -1.3%
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 84.71 199.25 12,711 205.27 -2.58
Account 173.25 307.52 669 11.11 -27.28
TablesDB 81.6 151.02 6,913 113.44 -0.37
Storage 78.6 168.53 3,345 57.18 +2.25
Functions 125.34 236.94 1,784 31.26 -10.75

Top API waits (after)

API request Max wait (ms)
account.name.update 587.59
functions.variables.update 446.67
functions.delete 445.54
account.prefs.update 441.35
tablesdb.rows.list 359.02

@ChiragAgg5k
ChiragAgg5k marked this pull request as ready for review September 9, 2026 23:23
@greptile-apps

greptile-apps Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with no outstanding blocking findings.

Summary

  • Serializes console organization creation while preserving application-project team creation.
  • Returns explicit prohibition and lock-contention responses.
  • Adds fresh-instance race coverage before parallel tests seed legacy organizations.
  • Updates dependent E2E setup and the bundled console image.

Reviews (4) · Last reviewed commit: "chore: use console 1.1.72 for organizati..."

Comment thread tests/e2e/Scopes/Scope.php Resolved
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

Please reassess the two findings in light of the thread replies and the explicit PR constraints: no edition/environment bypass; database seeding is deliberate Arrange setup for legacy multi-organization state, with observable API assertions and separate fresh-instance creation coverage retained. No source changes have been made for these findings.

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Release sequencing: release the companion console PR https://github.com/appwrite/vibes/pull/326 first, then pin its published console image version in Docker Compose before shipping this backend restriction. The console image bump is pending the actual release tag; no unreleased version has been substituted.

@ChiragAgg5k
ChiragAgg5k merged commit 1ded023 into main Sep 10, 2026
84 of 87 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/self-hosted-instance-organization-limit branch September 10, 2026 11:21
ChiragAgg5k added a commit that referenced this pull request Sep 10, 2026
Cloud sets _APP_EDITION=cloud and governs organizations through billing plans, so the per-instance limit introduced in #13585 broke every cloud E2E flow that creates a console team through POST /teams. The limit and its distributed lock now apply only when the edition is self-hosted, and the console team fixture uses the public create API under any other edition instead of seeding rows through the self-hosted registry.
ChiragAgg5k added a commit that referenced this pull request Sep 10, 2026
The console organization limit from #13585 is right for self-hosted but Appwrite Cloud governs organizations through billing plans and runs the same action. The decision now lives in a protected method the cloud subclass overrides, so it cannot be switched off by configuration on a self-hosted instance. The console team fixture creates through the public API first and seeds rows only when the instance refuses, so CE suites also run inside the cloud pod.
ChiragAgg5k added a commit that referenced this pull request Sep 10, 2026
The console organization limit from #13585 is right for self-hosted but Appwrite Cloud governs organizations through billing plans and runs the same action. The decision now lives in a protected method the cloud subclass overrides, so it cannot be switched off by configuration on a self-hosted instance. The console team fixture creates through the public API first and seeds rows only when the instance refuses, so CE suites also run inside the cloud pod.
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 tasks
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.

2 participants