Skip to content

chore: absorb cache into packages/cache - #13899

Merged
ChiragAgg5k merged 359 commits into
mainfrom
chore/absorb-cache
Sep 24, 2026
Merged

ChiragAgg5k merged 359 commits into
mainfrom
chore/absorb-cache

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

This moves utopia-php/cache into packages/cache, so Appwrite loads it directly. It follows the playbook in rfc/monorepo.md (wave 1 of #13828) and comes in three commits, plus a merge of main:

  1. Add 'packages/cache/' from commit '35fee421…': subtree import from the mirror with full history. The mirror head is the 5.1.1 release Appwrite already locks, and its tree matches packages/cache in utopia-php/monorepo (e8d3f32), so Appwrite runs the same code.
  2. chore(cache): mirror plumbing: mirror.yml now points here and the README banner is refreshed. There were no banned files to remove.
  3. refactor: load cache from packages/:
    • Adds the root autoload and replace entries, drops the utopia-php/cache: ^5.1.0 require line, and removes the package from the lock. The still-vendored database, domains and vcs require utopia-php/cache: ^4.0 || ^5.0, and replace now satisfies them.
    • Step A of the standard shape:
      • src/Cache/* moves up to src/.
      • tests/Cache/Unit/*, Base.php and Services.php move up to tests/; tests/Cache/E2E and tests/Cache/Scope become tests/E2E and tests/Scope. tests/bench stays where it was, excluded from both tiers.
      • Tests move from the bare Utopia\Tests namespace (and Utopia\Tests\Unit, \E2E, \Scope) to Utopia\Cache\Tests, with a matching autoload-dev entry. Services::compose() now resolves docker-compose.yml one level up.
      • phpunit.xml runs tests with tests/E2E and tests/bench excluded for the unit suite.
    • phpstan.neon used to include the monorepo root config, and validate rejects that, so it's now standalone at level max over src and tests. A phpstan-baseline.neon holds 25 findings, since the monorepo analysed this package at level 5. They are mixed from the Memcached and Hazelcast server stats and the RedisCluster node addresses, values passed to Envelope::encode() untyped, and casts of Redis replies in four e2e tests. The RFC's phase 8 burn-down list now includes them.
    • A standalone rector.php with the monorepo root's sets. It skips ReadOnlyPropertyRector and RemoveDefaultValueFromAssignedPropertyRector, which would otherwise rewrite property declarations in Adapter/Redis.php and Adapter/Redis/Multiplexing.php. Absorbing only moves code, so those declarations stay exactly as they were released.
    • src/ is byte-for-byte the release apart from the path move and Pint formatting (empty {} bodies and fn ( spacing). Pint also reorders a few imports in the tests. git diff -w against the import shows only brace placement.
    • Strips one line of trailing whitespace from the README.

Nothing to hoist: the package's third-party requirement is ext-json, which the root already requires. circuit-breaker, pools and telemetry are already in packages/. swoole/ide-helper stays in its require-dev for PHPStan.

Net: +8,368 / −63 across the three commits, nearly all of it the imported package. The root side is +5 / −63 (composer.json, composer.lock, rfc/monorepo.md).

Open issues and PRs on the mirror, for triage after merge

mirror-redirect will close anything new; these predate the freeze:

There is also utopia-php/monorepo#279 (perf(cache): reuse the decoded envelope while the stored string is unchanged), open and not merged. If it's still wanted it has to be re-opened here against packages/cache.

Validation

  • bin/monorepo validate: all packages valid
  • bin/monorepo check cache: Rector, Pint and PHPStan level max (with baseline) pass
  • bin/monorepo test cache: on the macOS host the unit tier reaches 108 tests and 6 fail, because the host PHP has no igbinary and six tests exercise the Igbinary codec. So I ran the tiers separately:
    • Unit, root autoloader, inside appwrite/appwrite:2.3.0 (has igbinary, redis and swoole like the CI unit job): vendor/bin/phpunit --testsuite packages --filter 'Utopia\\Cache', 114 tests / 255 assertions, 2 skipped
    • E2E against the package docker-compose.yml (unique compose project, torn down afterwards): 116 tests / 448 assertions in all. The Redis, RedisCluster, Sharding, leasable and four multiplexing suites ran in the same image on the host network, because host Swoole 6 on macOS segfaults in the multiplexing suites (this is a host problem, not this change). Memcached and Hazelcast ran on the host, because the image has no memcached extension
  • Utopia\Cache\Cache resolves to packages/cache/src/Cache.php from the root autoloader
  • Root PHPStan (host, phpstan.neon) on Database/Factory.php, Auth/Validator/PasswordPwned{,/HIBP,/Appwrite}.php, Auth/OIDC/Jwks.php, Platform/Tasks/{Doctor,Specs}.php and Platform/Workers/Deletes.php: no errors
  • Appwrite unit tests that use cache (tests/unit/Auth, Vcs/FactoryTest, Autogravity/DetectorTest, the Notifications/Webhooks workers and the messaging adapters): 214 pass. Auth/KeyTest::testDecode needs _APP_OPENSSL_KEY_V1, which the container sets; it passes with the variable set
  • composer update --lock after merging main: the lock diff against main drops only utopia-php/cache 5.1.1
  • composer validate --no-check-publish: valid. The only warning was already there (utopia-php/platform pinned exactly)
  • bin/monorepo split cache --dry-run: b6f27f22, which fast-forwards from the mirror head 35fee421
  • 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.

The utopia-php/cache mirror already has the canonical main ruleset (id 20338832), with the split app as an always-bypass actor, so the absorb ran with --skip-ruleset.

After merge:

🤖 Generated with Claude Code

precious-void and others added 30 commits October 14, 2022 11:32
Added ping method to check cache connectivity
loks0n and others added 11 commits August 21, 2026 12:04
…eaker-0.4

cache: require circuit-breaker ^0.4
chore: stop committing package lock files
…ages

Normalize recently absorbed packages
…-reader

fix(cache): retire the multiplexing reader while nothing is outstanding
…-377726

feat(cache): store values through a Codec, with Json and Igbinary implementations
…h-idle

fix(cache): park the multiplexing reader through idle gaps instead of retiring per command
…1276c3'

git-subtree-dir: packages/cache
git-subtree-mainline: b866958
git-subtree-split: 35fee42
Appwrite now autoloads Utopia\Cache from packages/cache instead of vendor/, and the root replace entry satisfies the ^4 || ^5 constraint that the still-vendored database, domains and vcs packages declare.
@ChiragAgg5k ChiragAgg5k added the absorb History-preserving package absorption; merge commit required label Sep 24, 2026
@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge on the findings assessed here, though the two existing non-blocking test concerns remain.

Fix All in Claude CodeFindings

  1. P2 Tests pin JSON layout ▶
  2. P2 Optional extension breaks unit tests ▶
Fix with agent prompt
### Issue 1
packages/cache/tests/EnvelopeTest.php:undefined-24
These assertions require the exact JSON envelope string, including field order. A harmless serialization change would fail the tests even if cached values still round-trip and expire correctly. The assertion in `CodecTest.php` follows the same pattern. The repository requires tests to check observable behavior rather than mirror the implementation, so this requirement should 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 2
packages/cache/tests/CodecTest.php:undefined-21
If a standalone install lacks `ext-igbinary`, this data provider constructs `Igbinary` and throws before the cases can run. The package only suggests that extension, so `composer test` fails on an otherwise supported install. Skip those cases when the extension is absent, or declare it as a test requirement.

---

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

Summary

The PR absorbs the cache library into packages/cache, switches the root autoloader from the Composer dependency to the local package, and adds package tooling and tests.

  • The cache implementation and test files have not changed since the previous review.
  • The two earlier test findings remain outstanding.

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

public function testEncodeWrapsDataAndTime(): void
{
$encoded = $this->envelope->encode('hello', 1700000000);
$this->assertSame('{"time":1700000000,"data":"hello"}', $encoded);

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 pin JSON layout
These assertions require the exact JSON envelope string, including field order. A harmless serialization change would fail the tests even if cached values still round-trip and expire correctly. The assertion in CodecTest.php follows the same pattern. The repository requires tests to check observable behavior rather than mirror the implementation, so this requirement should 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/cache/tests/EnvelopeTest.php
Line: 24

Comment:
**Tests pin JSON layout**
These assertions require the exact JSON envelope string, including field order. A harmless serialization change would fail the tests even if cached values still round-trip and expire correctly. The assertion in `CodecTest.php` follows the same pattern. The repository requires tests to check observable behavior rather than mirror the implementation, so this requirement should 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

public static function codecs(): iterable
{
yield 'json' => [new Json()];
yield 'igbinary' => [new Igbinary()];

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 Optional extension breaks unit tests
If a standalone install lacks ext-igbinary, this data provider constructs Igbinary and throws before the cases can run. The package only suggests that extension, so composer test fails on an otherwise supported install. Skip those cases when the extension is absent, or declare it as a test requirement.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cache/tests/CodecTest.php
Line: 21

Comment:
**Optional extension breaks unit tests**
If a standalone install lacks `ext-igbinary`, this data provider constructs `Igbinary` and throws before the cases can run. The package only suggests that extension, so `composer test` fails on an otherwise supported install. Skip those cases when the extension is absent, or declare it as a test requirement.

---

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

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

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

Metric Before After Change
🚀 Requests/sec 170.38 161.22 🔴 -5.4%
⏱️ Latency P50 98.38 ms 108.25 ms 🔴 +10%
⏱️ Latency P95 244.02 ms 247.34 ms ⚪ +1.4%
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 108.25 247.34 10,260 161.22 +3.32
Account 208.05 381.35 540 9.15 +10.34
TablesDB 104.94 198.32 5,580 89.5 +13.78
Storage 100.03 204.89 2,700 44.93 +0.88
Functions 151.85 292.97 1,440 24.66 -12.34

Top API waits (after)

API request Max wait (ms)
account.name.update 526.08
functions.create 498.89
functions.variables.update 474.63
tablesdb.rows.increment 443.99
account.prefs.update 422.13

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.