Repository navigation
chore: absorb balancer into packages/balancer - #13886
Conversation
Feat: Implement library
Feat: Readme badges
Feat: getAlgo method
Feat: getStates
Feat: Rename to balancer + group class
Fix round robin index
Feat: getOptions()
feat: add telemetry
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
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]>
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]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
|
|
|
||
| jobs: | ||
| redirect: | ||
| uses: appwrite/appwrite/.github/workflows/mirror-redirect.yml@main |
There was a problem hiding this 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.
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.| > [!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. | ||
|
|
||
| [](https://github.com/utopia-php/balancer/actions/workflows/tester.yml) |
There was a problem hiding this 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.
| [](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!
|
|
||
| **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: |
There was a problem hiding this 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.
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.| $balancer = new Balancer(new Random()); | ||
| $this->assertInstanceOf(Random::class, $balancer->getAlgo()); |
There was a problem hiding this 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)
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!
| $key = \array_key_first($options); | ||
|
|
||
| return $key === null ? null : $options[$key]; |
There was a problem hiding this 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.
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.# Conflicts: # composer.lock
# Conflicts: # composer.lock
# Conflicts: # composer.json # composer.lock
# Conflicts: # composer.lock
# Conflicts: # composer.lock
Summary
This moves
utopia-php/balancerintopackages/balancer, so Appwrite loads it directly. It's wave 1 of #13828 and follows the playbook inrfc/monorepo.md. Balancer was a standalone repository and was never inutopia-php/monorepo, so it gets the full absorb: newmirror.yml, README banner, and a mirror ruleset. It comes in four commits:Add 'packages/balancer/' from commit '7fc8922d…': subtree import fromutopia-php/balancerwith full history. The mirror head is the0.4.1tag Appwrite already locks, so the dependency graph doesn't change.chore(balancer): mirror plumbing:absorboutput. It removes the mirror'stester,linterandcodeql-analysisworkflows and addsmirror.yml. It also adds the README banner, drops.gitpod.ymland the committedcomposer.lock(now in.gitignore), and strips Pint, PHPStan and PHPUnit fromrequire-dev.refactor: load balancer from packages/:replaceentries, drops theutopia-php/balancerrequire line, and removes the package from the lock.utopia-php/cdn(still vendored) requiresutopia-php/balancer, andreplacenow satisfies that.src/Balancer/*moves up tosrc/.tests/Balancer/BalancerTest.phpmoves up totests/. It declared the bareUtopia\Testsnamespace, so it becomesUtopia\Balancer\Testswith a matchingautoload-deventry..devcontainer/is removed (tooling for the old standalone repo, like.gitpod.yml).phpunit.xmlmoves to the PHPUnit 12 shape the other packages use.phpstan.neon(level max,src+tests) and arector.php(PHP sets + type declarations, the same asopenapi). No baseline is needed. Level max found 10 issues and this commit fixes them instead of baselining them:FirstandLastindexed$optionswith theint|string|nullresult ofarray_key_first/array_key_last. They now returnnullexplicitly for an empty list. Behavior is the same.Optionparameter, and a redundantassertIsArrayon anarray-typed return is gone.: boolreturn types on the test closures.refactor(balancer): keep the released public surface: restores the property declarations Rector had promoted and madereadonly.rector.phpnow skipsClassPropertyAssignToConstructorPromotionRectorandReadOnlyPropertyRector, so the library's API is exactly as released. Apart from theFirst/Lastfix,src/is byte-identical to0.4.1.There's nothing to hoist. The package requires only PHP and
utopia-php/telemetry, which is already inpackages/. 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 validbin/monorepo check balancer: Rector, Pint and PHPStan level max pass, with no baselinebin/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 autoloaderUtopia\Balancer\Balancerresolves topackages/balancer/src/Balancer.phpfrom the root autoloadersrc/Appwrite/Platform/Modules/Avatars/Http/Photo/Get.php: no errorscomposer validate --no-check-publish: valid (only the existingutopia-php/platformexact-constraint warning)composer update --lock: the lock diff removes onlyutopia-php/balancer(plus the content hash)bin/monorepo split balancer --dry-run:e3e48b11, which fast-forwards from the mirror head7fc8922d, and its tree is identical topackages/balancergit diff --checkMerge 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,absorbcreated the canonicalmainruleset (id23943498), 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/balancerneeds to deal with its classic branch protection onmain. It requires 1 approving review, enforces it for admins (enforce_admins: true), and restricts pushes to theownersteam, with no apps allowed. Classic protection is separate from rulesets, so the split app's ruleset bypass doesn't cover it, and the firstSplitpush would be rejected. The fix is to delete the classic protection, since the new ruleset replaces it (utopia-php/agents,telemetryandcompressionhave none). The alternative is to matchutopia-php/image: add the split app to the push restrictions and turn offenforce_admins.After merge: confirm
Splitpushes toutopia-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