Skip to content

chore: absorb client and span into packages/ - #13850

Closed
ChiragAgg5k wants to merge 113 commits into
mainfrom
feat/absorb-client-span
Closed

ChiragAgg5k wants to merge 113 commits into
mainfrom
feat/absorb-client-span

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Move utopia-php/client and utopia-php/span into packages/ so Appwrite loads them directly. This is step 4 of the messaging chain in #13828 (smtp → telemetry → pools → client + span → messaging). They require each other, so they move together, and client takes its RFC step B rename in the same PR instead of waiting for phase 6.

  1. Imports: Add 'packages/span/' from commit 'c935f78…' and Add 'packages/client/' from commit 'd1e0d25…', each followed by a chore(<name>): mirror plumbing commit. span's head matches 4.2.0 in effect (Sentry batching landed after the tag and was reverted). client's head is the 0.4.5 tag; Appwrite ran 0.4.4. 0.4.5 keeps streamed and buffered Swoole requests on separate connections and keeps a caller's write_func off buffered requests.
  2. fix(monorepo): claim a release line when installing a package in a cycle: installing span on its own made Composer reject client's utopia-php/span constraint against the unversioned root. Linked runs already set COMPOSER_ROOT_VERSION for this, and registry-mode installs in check and test now do the same.
  3. feat(monorepo): load a package's autoload files through the root: packages here are autoloaded by the root instead of being installed by Composer, so a package's autoload.files never ran. bin/monorepo autoload now copies them into the root autoload.files.
  4. refactor(client): move Client and the streaming interface under Utopia\Client: Utopia\Client becomes Utopia\Client\Client and Utopia\Psr18\StreamingClientInterface becomes Utopia\Client\Psr18\StreamingClientInterface. src/Client is flattened, so the package declares a single Utopia\Client\ prefix and no bare-prefix handling is needed. src/compat.php registers a lazy autoloader that aliases the old names. Nothing loads until an old name is used, and the aliases go away at client's next major. CompatTest pins both aliases and fails when the shim is empty.
  5. refactor: load client and span from packages/: adds the root autoload, files and replace entries. Both packages leave require and the lock, and nothing else in the lock moves. Appwrite's three call sites use Utopia\Client\Client. span's src/Span is flattened, client's tests move to Utopia\Client\Tests, and both phpstan.neon and rector.php stand alone. client keeps level 10 on src and tests, as in the old monorepo.

Old names still in use

The shim covers every consumer that still uses Utopia\Client or Utopia\Psr18\*. In Appwrite's lock those are the vendored messaging, storage, domains, cdn, usage and open-runtimes/sdk-for-php. agents and span here are covered too. They keep the old names for now because their mirrors resolve client from Packagist, where no release has the new names yet. After this merges, cutting client/0.5.0 publishes the rename to the mirror. Then agents and span can move to ^0.5 and the new names, and the shim is removed at the following major. The RFC now records both steps.

Client PHPStan baseline

PHPStan 2.2.14, which Appwrite runs, reports three findings on one line of the Swoole adapter's redirect-body replay. It no longer sees that $suppressedBody becomes a resource only when $sink is set. The old monorepo's 2.2.5 passes the same code, and the replay has test coverage. Per the RFC, the package ships a phpstan-baseline.neon, recorded in the phase 8 burn-down.

Validation

  • bin/monorepo validate: all packages valid
  • bin/monorepo check client span: Rector, Pint and PHPStan pass
  • bin/monorepo test client span: client 187 tests (185 plus the two compat tests), span 108. client's tests start their own loopback server and need no external services.
  • The same 187 and 108 tests pass under the root autoloader through --testsuite packages
  • Root PHPStan is clean on every Appwrite file that uses Utopia\Client or Utopia\Span
  • Resolution checked under the root autoloader: Utopia\Client and Utopia\Psr18\StreamingClientInterface alias the moved classes, span's Sentry exporter still builds through the old name, and Utopia\Http\Http still loads from vendor
  • composer dump-autoload shows no PSR-4 warnings. The Docker composer stage tolerates the files entry before packages/ is copied in.
  • Dry-run splits: client → e364829, span → 9e7675f

Merge and follow-up

Merge with a merge commit, not squash, to keep both subtree annotations the split continues from. Both mirror rulesets let the split app bypass them, and neither mirror has open PRs.

After merge:

  • Confirm the Split run pushes to both mirrors.
  • Retire packages/client and packages/span from utopia-php/monorepo in one PR.
  • Cut client/0.5.0 so the mirror publishes the rename.

Part of #13828.

loks0n and others added 30 commits December 30, 2025 21:18
Set level=error when setError() is called, level=info otherwise.
Explicit level via set('level', ...) is never overridden.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
feat: auto-set level attribute on spans
ChiragAgg5k and others added 12 commits August 26, 2026 19:13
fix(client): require utopia-php/psr7 ^0.2.1
…port

feat(span): send Sentry exports through PSR-18
…hing

revert(span): remove buffered Sentry export
chore: stop committing package lock files
fix(client): reconnect stale TLS sockets before sending
fix(client): enforce Swoole TLS peer identity verification
fix(client): keep streamed and buffered Swoole requests on separate connections
…2fd39'

git-subtree-dir: packages/span
git-subtree-mainline: 28b7197
git-subtree-split: c935f78
Point mirror.yml and the README banner at appwrite/appwrite so PRs and issues opened on the mirror are redirected here.
…29e37ce'

git-subtree-dir: packages/client
git-subtree-mainline: a5dcdfe
git-subtree-split: d1e0d25
Point mirror.yml and the README banner at appwrite/appwrite so PRs and issues opened on the mirror are redirected here.
@ChiragAgg5k ChiragAgg5k added the absorb History-preserving package absorption; merge commit required label Sep 23, 2026
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The implementation appears functionally sound, but the explicit repository testing requirement must be satisfied before merging by replacing the reflection-coupled compatibility assertions.

Fix All in Claude CodeFindings

  1. P2 Aliases tested through reflection ▶
Fix with agent prompt
### Issue 1
packages/client/tests/CompatTest.php:15-16
These assertions use reflection to pin the aliases to their canonical implementation names. The same issue appears for the legacy interface at lines 21–22. This couples the tests to the `class_alias` implementation instead of proving that consumers can use the legacy class and interface through their public contracts. The repository requires tests to verify observable behavior rather than mirror implementation details, so this must be corrected 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!

---

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

Summary

The PR absorbs the client and span libraries into packages/, updates root dependency and autoload wiring, and standardizes the client namespace while retaining legacy aliases.

  • Removes the packaged client and span releases from the root lockfile and replaces them with monorepo-owned packages.
  • Adds package-local manifests, tooling, documentation, implementations, and tests.
  • Moves the client API under Utopia\Client\ and introduces compatibility aliases for legacy consumers.
  • Extends monorepo tooling to hoist package autoload.files entries and handle cyclic package installation versions.
  • One newly added compatibility test remains coupled to the alias implementation rather than observable behavior.

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

Comment thread packages/client/src/Redirect.php Resolved
@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/absorb-client-span (after).

Metric Before After Change
🚀 Requests/sec 185.82 189.07 ⚪ +1.8%
⏱️ Latency P50 93.1 ms 91.65 ms ⚪ -1.6%
⏱️ Latency P95 218.43 ms 212.46 ms ⚪ -2.7%
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 91.65 212.46 11,799 189.07 -5.97
Account 173.91 316 621 10.29 -7.94
TablesDB 89.38 167.54 6,417 104.75 -5.85
Storage 83.22 188.32 3,105 52.55 +6.93
Functions 128.75 256.37 1,656 28.79 -4.04

Top API waits (after)

API request Max wait (ms)
account.name.update 533.18
tablesdb.rows.delete 485.18
functions.variables.create 462.39
functions.create 435
account.prefs.update 429.13

Comment thread bin/monorepo Resolved
span and client require each other, so installing span on its own made
Composer reject client's span constraint against the unversioned root.
Linked runs already set COMPOSER_ROOT_VERSION for this; registry-mode
installs in check and test now do the same.
Packages here are autoloaded by the root composer.json rather than
installed, so a package's own autoload.files never ran. autoload now
lists them in the root, which a class_alias shim for renamed classes
needs.
…a\Client

Utopia\Client and Utopia\Psr18\StreamingClientInterface sat outside the
package's own namespace, so client had to declare the bare Utopia\
prefix. They are now Utopia\Client\Client and
Utopia\Client\Psr18\StreamingClientInterface, src/Client is flattened,
and the package declares a single Utopia\Client\ prefix.

src/compat.php keeps the old names working through a lazy autoloader
until the next major, since the vendored messaging, storage, domains,
cdn, usage and sdk-for-php packages and the agents and span packages
still use them. CompatTest pins both aliases.
Appwrite now autoloads Utopia\Client and Utopia\Span from packages/,
loads client's alias shim through the root autoload files, and
replaces both packages so the vendored copies are no longer installed.
span's mirror head matches 4.2.0 (a batching change landed and was
reverted); client moves from 0.4.4 to 0.4.5, which keeps streamed and
buffered Swoole requests on separate connections. Neither needs a
third-party requirement hoisted.

Appwrite's three call sites use Utopia\Client\Client. span's src/Span
is flattened and its QA configs already stand alone; client ships a
baseline for three PHPStan 2.2.14 findings in its redirect-body replay,
recorded for the phase 8 burn-down with the shim's removal.
@ChiragAgg5k
ChiragAgg5k force-pushed the feat/absorb-client-span branch from 39f7ddf to 63848c1 Compare September 23, 2026 10:29
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

Closing in favour of releasing the client rename first. Utopia\Client\Client and Utopia\Client\Psr18\* will ship as client 0.5.0 from utopia-php/monorepo. The absorb then comes back as a clean PR: agents and span move to the new names against a published release, and no interim handling is needed here. The branch stays for reference.

Comment on lines +15 to +16
$this->assertTrue(class_exists('Utopia\Client'));
$this->assertSame(Client::class, new \ReflectionClass('Utopia\Client')->getName());

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 Aliases tested through reflection

These assertions use reflection to pin the aliases to their canonical implementation names. The same issue appears for the legacy interface at lines 21–22. This couples the tests to the class_alias implementation instead of proving that consumers can use the legacy class and interface through their public contracts. The repository requires tests to verify observable behavior rather than mirror implementation details, so this must be corrected 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/client/tests/CompatTest.php
Line: 15-16

Comment:
**Aliases tested through reflection**

These assertions use reflection to pin the aliases to their canonical implementation names. The same issue appears for the legacy interface at lines 21–22. This couples the tests to the `class_alias` implementation instead of proving that consumers can use the legacy class and interface through their public contracts. The repository requires tests to verify observable behavior rather than mirror implementation details, so this must be corrected 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

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.

3 participants