Skip to content

chore: absorb balancer into packages/balancer - #13886

Merged
ChiragAgg5k merged 51 commits into
mainfrom
chore/absorb-balancer
Sep 25, 2026
Merged

ChiragAgg5k merged 51 commits into
mainfrom
chore/absorb-balancer

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

This moves utopia-php/balancer into packages/balancer, so Appwrite loads it directly. It's wave 1 of #13828 and follows the playbook in rfc/monorepo.md. Balancer was a standalone repository and was never in utopia-php/monorepo, so it gets the full absorb: new mirror.yml, README banner, and a mirror ruleset. It comes in four commits:

  1. Add 'packages/balancer/' from commit '7fc8922d…': subtree import from utopia-php/balancer with full history. The mirror head is the 0.4.1 tag Appwrite already locks, so the dependency graph doesn't change.
  2. chore(balancer): mirror plumbing: absorb output. It removes the mirror's tester, linter and codeql-analysis workflows and adds mirror.yml. It also adds the README banner, drops .gitpod.yml and the committed composer.lock (now in .gitignore), and strips Pint, PHPStan and PHPUnit from require-dev.
  3. refactor: load balancer from packages/:
    • Adds the root autoload and replace entries, drops the utopia-php/balancer require line, and removes the package from the lock. utopia-php/cdn (still vendored) requires utopia-php/balancer, and replace now satisfies that.
    • Step A of the standard shape:
      • src/Balancer/* moves up to src/.
      • tests/Balancer/BalancerTest.php moves up to tests/. It declared the bare Utopia\Tests namespace, so it becomes Utopia\Balancer\Tests with a matching autoload-dev entry.
      • .devcontainer/ is removed (tooling for the old standalone repo, like .gitpod.yml).
      • phpunit.xml moves to the PHPUnit 12 shape the other packages use.
    • Adds a standalone phpstan.neon (level max, src + tests) and a rector.php (PHP sets + type declarations, the same as openapi). No baseline is needed. Level max found 10 issues and this commit fixes them instead of baselining them:
      • First and Last indexed $options with the int|string|null result of array_key_first/array_key_last. They now return null explicitly for an empty list. Behavior is the same.
      • The tests' filter closures take a typed Option parameter, and a redundant assertIsArray on an array-typed return is gone.
    • Rector's only change is : bool return types on the test closures.
  4. refactor(balancer): keep the released public surface: restores the property declarations Rector had promoted and made readonly. rector.php now skips ClassPropertyAssignToConstructorPromotionRector and ReadOnlyPropertyRector, so the library's API is exactly as released. Apart from the First/Last fix, src/ is byte-identical to 0.4.1.

There's nothing to hoist. The package requires only PHP and utopia-php/telemetry, which is already in packages/. Appwrite uses it in one file, Avatars/Http/Photo/Get.php, and root PHPStan passes on it.

Net: +101 / −3,905 after the import (most of that is the mirror's committed composer.lock).

Validation

  • bin/monorepo validate: all packages valid
  • bin/monorepo check balancer: Rector, Pint and PHPStan level max pass, with no baseline
  • bin/monorepo test balancer: 6 tests / 68 assertions (resolved against Packagist, utopia-php/telemetry ^0.4.0)
  • vendor/bin/phpunit --testsuite packages --filter 'Utopia\\Balancer': 6 tests / 68 assertions under the root autoloader
  • Utopia\Balancer\Balancer resolves to packages/balancer/src/Balancer.php from the root autoloader
  • Root PHPStan on src/Appwrite/Platform/Modules/Avatars/Http/Photo/Get.php: no errors
  • composer validate --no-check-publish: valid (only the existing utopia-php/platform exact-constraint warning)
  • composer update --lock: the lock diff removes only utopia-php/balancer (plus the content hash)
  • bin/monorepo split balancer --dry-run: e3e48b11, which fast-forwards from the mirror head 7fc8922d, and its tree is identical to packages/balancer
  • git diff --check

Merge and follow-up

Merge with a merge commit. A squash drops the git-subtree-* annotation and orphans the package from its mirror.

On utopia-php/balancer, absorb created the canonical main ruleset (id 23943498), with the split app (4016286) as an always-bypass actor. The mirror had no ruleset before.

Warning

Before merging, a human with admin on utopia-php/balancer needs to deal with its classic branch protection on main. It requires 1 approving review, enforces it for admins (enforce_admins: true), and restricts pushes to the owners team, with no apps allowed. Classic protection is separate from rulesets, so the split app's ruleset bypass doesn't cover it, and the first Split push would be rejected. The fix is to delete the classic protection, since the new ruleset replaces it (utopia-php/agents, telemetry and compression have none). The alternative is to match utopia-php/image: add the split app to the push restrictions and turn off enforce_admins.

After merge: confirm Split pushes to utopia-php/balancer. The mirror has no open PRs or issues to triage. It does have stale branches (dev, feat-*, fix-qa, telemetry), all left over from merged PRs.

🤖 Generated with Claude Code

Meldiron and others added 13 commits March 16, 2023 12:17
run() answers "which one option should I use", and the filtered set it
picks from was unreachable: $filters is private, so a caller that has to
act on every qualifying option — fanning a request out rather than
balancing between them — had to re-implement filtering outside the class,
or subclass to record filters as they were registered.

getFilteredOptions() is that set, extracted from run() unchanged. run()
now calls it and behaves exactly as before.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Group's telemetry pin at 0.1.* makes this library uninstallable next to
anything on the current utopia telemetry line: utopia-php/pools requires
^0.4.6, so any consumer pulling in pools — through utopia-php/client, for
one — cannot also require balancer.

The whole surface Group touches is unchanged between the two lines. The
Adapter::createHistogram and Histogram::record signatures are identical,
and Adapter\None exists in both, so the constraint is widened rather than
the code changed.

Verified against 0.4.6: tests, PHPStan --level max and PSR-12 all pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review preferred caret syntax. ^0.1.0 on its own cannot work: below 1.0.0
Composer's caret is patch-only, so it resolves 0.1.0 or 0.1.1 and still
conflicts with utopia-php/pools at ^0.4.6. Both series have to be named.

Same resolution as 0.1.*|0.4.*, in the requested style.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Drops the 0.1 series rather than supporting both. 0.1 was already
unreachable for any consumer that also pulls in utopia-php/pools, which
requires ^0.4.6, so keeping it alive supported a combination nothing could
install.

Requirements narrow rather than widen: telemetry 0.1.1 needed ext-protobuf
and ext-opentelemetry, 0.4.6 needs only ext-protobuf.

Breaking for a consumer pinning telemetry to 0.1.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Expose the options that passed the filters
…7040c6ee1'

git-subtree-dir: packages/balancer
git-subtree-mainline: b866958
git-subtree-split: 7fc8922
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Autoload Utopia\Balancer from packages/balancer and replace
utopia-php/balancer, so Appwrite and the still-vendored cdn resolve it
from this repository instead of Packagist.

Step A of the standard shape: flatten src/Balancer into src/, move the
unit test to tests/ under Utopia\Balancer\Tests, and drop the
devcontainer. Add a standalone phpstan.neon at level max and a
rector.php; the few level-max findings are fixed rather than baselined.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ChiragAgg5k ChiragAgg5k added the absorb History-preserving package absorption; merge commit required label Sep 24, 2026
Absorbs move code without rewriting library APIs, so restore the
property declarations Rector promoted and made readonly, and skip those
two rules in the package's rector.php.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → chore/absorb-balancer (after).

Metric Before After Change
🚀 Requests/sec 175.77 199.04 🟢 +13.2%
⏱️ Latency P50 96.41 ms 87.85 ms 🟢 -8.9%
⏱️ Latency P95 235.84 ms 202.84 ms 🟢 -14%
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 87.85 202.84 12,483 199.04 -33
Account 169.51 302.23 657 11.09 -56.36
TablesDB 85.3 163.61 6,789 109.9 -9.23
Storage 80.27 172.11 3,285 55.26 -44.14
Functions 125.87 234.07 1,752 30.14 -71.74

Top API waits (after)

API request Max wait (ms)
account.name.update 484.06
functions.variables.create 429.78
account.prefs.update 394.6
functions.create 368.09
tablesdb.rows.decrement 335.72

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High risk] Moves a load-balancing library from external dependency to monorepo package.

The PR does not appear ready to merge until the balancer mirror’s classic branch protection permits Split pushes.

Fix All in Claude CodeFindings

  1. P1 Mirror push remains blocked. ▶
  2. P2 Build badge targets removed workflow. ▶
  3. P2 Contributions directed to wrong repository. ▶
  4. P2 Tests repeat constructor details. ▶
  5. P2 Empty-input branches lack tests. ▶
Fix with agent prompt
### Issue 1
packages/balancer/.github/workflows/mirror.yml:undefined-15
If the balancer mirror still has the classic `main` branch protection described in the PR, the new ruleset bypass will not let the Split app push through its review and push restrictions. The first Split push will fail, leaving the mirror behind the in-tree package. Update the classic protection before merging.

### Issue 2
packages/balancer/README.md:undefined-6
This badge points to `tester.yml`, which the mirror conversion removes. The mirror retains only the redirect workflow, so its README can no longer show current test status through this badge. Remove it or point readers to a check that still runs.

```suggestion

```

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 3
packages/balancer/CONTRIBUTING.md:undefined-35
These instructions tell readers to fork this repository and open a PR, but the new README calls it a read-only mirror and the new workflow closes PRs opened here. Update or remove the instructions so contributors are directed to appwrite/appwrite.

### Issue 4
packages/balancer/tests/BalancerTest.php:60-61
This assertion checks only the concrete class passed to the constructor; it never runs the `Random` balancer. The earlier `RoundRobin` assertion follows the same pattern. The repository requires tests of observable behavior rather than assertions that repeat implementation choices. Test the resulting selections instead; if `getAlgo()` identity is the contract, compare it with the supplied instance. This requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 5
packages/balancer/src/Algorithm/First.php:20-22
This PR makes `First::run([])` and `Last::run([])` return `null` explicitly, but the tests call those algorithms directly only with populated arrays. `Balancer::run()` handles empty lists before either algorithm runs, so its tests cannot cover these new branches. Add direct empty-input tests to protect that behavior from regression.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR absorbs the balancer package into packages/balancer, switches root Composer autoloading to the in-tree copy, and adds mirror plumbing.

  • The balancer files are unchanged since the previous review.
  • The previously identified mirror-push prerequisite, stale documentation, and test gaps remain to be addressed.

Reviews (6) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."


jobs:
redirect:
uses: appwrite/appwrite/.github/workflows/mirror-redirect.yml@main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Mirror push remains blocked. If the balancer mirror still has the classic main branch protection described in the PR, the new ruleset bypass will not let the Split app push through its review and push restrictions. The first Split push will fail, leaving the mirror behind the in-tree package. Update the classic protection before merging.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/balancer/.github/workflows/mirror.yml
Line: 15

Comment:
**Mirror push remains blocked.** If the balancer mirror still has the classic `main` branch protection described in the PR, the new ruleset bypass will not let the Split app push through its review and push restrictions. The first Split push will fail, leaving the mirror behind the in-tree package. Update the classic protection before merging.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

> [!IMPORTANT]
> This repository is a read-only mirror of [`packages/balancer`](https://github.com/appwrite/appwrite/tree/main/packages/balancer) in [appwrite/appwrite](https://github.com/appwrite/appwrite). Development happens there — please open issues and pull requests against appwrite/appwrite.

[![Build Status](https://github.com/utopia-php/balancer/actions/workflows/tester.yml/badge.svg)](https://github.com/utopia-php/balancer/actions/workflows/tester.yml)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Build badge targets removed workflow. This badge points to tester.yml, which the mirror conversion removes. The mirror retains only the redirect workflow, so its README can no longer show current test status through this badge. Remove it or point readers to a check that still runs.

Suggested change
[![Build Status](https://github.com/utopia-php/balancer/actions/workflows/tester.yml/badge.svg)](https://github.com/utopia-php/balancer/actions/workflows/tester.yml)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/balancer/README.md
Line: 6

Comment:
**Build badge targets removed workflow.** This badge points to `tester.yml`, which the mirror conversion removes. The mirror retains only the redirect workflow, so its README can no longer show current test status through this badge. Remove it or point readers to a check that still runs.

```suggestion

```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex


**All PRs must include a commit message with the changes description!**

For the initial start, fork the project and use git clone command to download the repository to your computer. A standard procedure for working on an issue would be to:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Contributions directed to wrong repository. These instructions tell readers to fork this repository and open a PR, but the new README calls it a read-only mirror and the new workflow closes PRs opened here. Update or remove the instructions so contributors are directed to appwrite/appwrite.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/balancer/CONTRIBUTING.md
Line: 35

Comment:
**Contributions directed to wrong repository.** These instructions tell readers to fork this repository and open a PR, but the new README calls it a read-only mirror and the new workflow closes PRs opened here. Update or remove the instructions so contributors are directed to appwrite/appwrite.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Comment on lines +60 to +61
$balancer = new Balancer(new Random());
$this->assertInstanceOf(Random::class, $balancer->getAlgo());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests repeat constructor details. This assertion checks only the concrete class passed to the constructor; it never runs the Random balancer. The earlier RoundRobin assertion follows the same pattern. The repository requires tests of observable behavior rather than assertions that repeat implementation choices. Test the resulting selections instead; if getAlgo() identity is the contract, compare it with the supplied instance. This requirement must be satisfied before merging.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/balancer/tests/BalancerTest.php
Line: 60-61

Comment:
**Tests repeat constructor details.** This assertion checks only the concrete class passed to the constructor; it never runs the `Random` balancer. The earlier `RoundRobin` assertion follows the same pattern. The repository requires tests of observable behavior rather than assertions that repeat implementation choices. Test the resulting selections instead; if `getAlgo()` identity is the contract, compare it with the supplied instance. This requirement must be satisfied before merging.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

Comment on lines +20 to +22
$key = \array_key_first($options);

return $key === null ? null : $options[$key];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Empty-input branches lack tests. This PR makes First::run([]) and Last::run([]) return null explicitly, but the tests call those algorithms directly only with populated arrays. Balancer::run() handles empty lists before either algorithm runs, so its tests cannot cover these new branches. Add direct empty-input tests to protect that behavior from regression.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/balancer/src/Algorithm/First.php
Line: 20-22

Comment:
**Empty-input branches lack tests.** This PR makes `First::run([])` and `Last::run([])` return `null` explicitly, but the tests call those algorithms directly only with populated arrays. `Balancer::run()` handles empty lists before either algorithm runs, so its tests cannot cover these new branches. Add direct empty-input tests to protect that behavior from regression.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

@ChiragAgg5k
ChiragAgg5k merged commit 1f644d8 into main Sep 25, 2026
49 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the chore/absorb-balancer branch September 25, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

absorb History-preserving package absorption; merge commit required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants