Skip to content

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

Merged
ChiragAgg5k merged 116 commits into
mainfrom
feat/absorb-client-and-span
Sep 23, 2026
Merged

ChiragAgg5k merged 116 commits into
mainfrom
feat/absorb-client-and-span

Conversation

@ChiragAgg5k

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.

This replaces #13850. client's namespace rename shipped first as client/0.5.0 from utopia-php/monorepo#331. So here client already has the standard Utopia\Client\ shape, and bin/monorepo needs no special case for it.

Commits after the two history-preserving imports and their mirror plumbing commits:

  1. fix(monorepo): claim a release line when installing a package in a cycle. span and client require each other, so 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. Registry-mode installs in check and test now do the same.
  2. 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, which client's alias shim needs.
  3. fix(client): register each old-name alias only once. A package's test run here loads two Composer autoloaders, the root one PHPUnit starts from and the package's own, and both include compat.php. The second class_alias warned, and CompatTest's fresh-process case failed. Each alias is now registered only if the name is not already defined.
  4. refactor(client): build the buffered body without a ternary. PHPStan 2.2.14, which Appwrite runs, misreads $responseBody = $streaming ? '' : $client->body followed by an is_string guard. It concludes the streaming path is impossible, then flags the redirect-body replay as dead code. The old monorepo's 2.2.5 did not. Assigning the body only when not streaming behaves the same and passes level 10 without a baseline.
  5. refactor(agents): use client 0.5's names. agents requires ^0.5 and imports Utopia\Client\Client and Utopia\Client\Psr18\StreamingClientInterface.
  6. refactor: load client and span from packages/.
    • The root gets autoload, files and replace entries. Both packages leave require, and the lock drops only them.
    • client moves from 0.4.4 to 0.5.0 (the rename plus 0.4.5's Swoole connection fixes). span's head matches 4.2.0 in effect.
    • Appwrite's three call sites use Utopia\Client\Client. span moves to ^0.5 and the new names, and its src/Span is flattened.
    • Both packages' phpstan.neon and rector.php stand alone. client keeps level 10 on src and tests.

The vendored messaging, storage, domains, cdn, usage and open-runtimes/sdk-for-php still use the old names through the shim. The RFC now lists removing the shim at client's next major, once they move.

Validation

  • bin/monorepo validate: all packages valid
  • bin/monorepo check span client agents: Rector, Pint and PHPStan pass, with no baselines
  • bin/monorepo test span client agents: span 108 tests, client 188, agents 139 with 4 skipped. client's tests start their own loopback server.
  • Under the root autoloader with --testsuite packages: span 108, client 188 and agents 102 tests pass.
  • Root PHPStan is clean on every Appwrite file that uses Utopia\Client, Utopia\Span or Utopia\Agents.
  • Old names still resolve to the moved classes. The vendored storage S3 device, whose property is typed against the old interface, builds with the moved client. That case failed CI on refactor(client)!: move Client and the streaming interface under Utopia\Client utopia-php/monorepo#331 before the aliases became eager.
  • 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 551263e, span bfd35c8, agents 2c887cc.

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 the client, span and agents mirrors.
  • Retire packages/client and packages/span from utopia-php/monorepo in one PR.

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
loks0n and others added 17 commits August 28, 2026 16:53
…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
refactor(client)!: move Client and the streaming interface under Utopia\Client
…2fd39'

git-subtree-dir: packages/span
git-subtree-mainline: e01ecac
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.
…042fbd6'

git-subtree-dir: packages/client
git-subtree-mainline: fb66c49
git-subtree-split: ef5bb38
Point mirror.yml and the README banner at appwrite/appwrite so PRs and issues opened on the mirror are redirected here.
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 client's alias shim for its renamed
classes needs.
A package's test run in this repository loads two Composer autoloaders,
the root one PHPUnit starts from and the package's own, and both list
compat.php, so the second class_alias warned and failed CompatTest's
fresh-process case. Each alias is now registered only if the name is
not already defined.
PHPStan 2.2.14 misreads $responseBody = $streaming ? '' : $client->body
followed by an is_string guard as ruling out the streaming path, then
reports the redirect-body replay as dead code. Assigning the body only
when not streaming says the same thing in a form it follows, so the
package passes level 10 without a baseline.
utopia-php/client 0.5.0 moved Utopia\Client and
Utopia\Psr18\StreamingClientInterface under Utopia\Client. agents now
requires ^0.5 and imports the new names instead of relying on the
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.
client moves from 0.4.4 to 0.5.0: its classes now live under
Utopia\Client, and 0.4.5's Swoole fixes keep streamed and buffered
requests on separate connections. span's mirror head matches 4.2.0
(a batching change landed and was reverted). Neither needs a
third-party requirement hoisted.

Appwrite's three call sites use Utopia\Client\Client, and span moves
to ^0.5 and the new names. span's src/Span is flattened; both packages'
phpstan.neon and rector.php stand alone, client at level 10 on src and
tests as before. The vendored messaging, storage, domains, cdn, usage
and sdk-for-php packages keep the old names through the shim.
@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 PR should not merge until the explicit repository testing and regular-expression requirements are satisfied.

Fix All in Claude CodeFindings

  1. P2 Tests Mirror Adapter Internals ▶
  2. P2 Tests Depend On Aliases ▶
  3. P2 Tests Reach Private Internals ▶
  4. P2 Regular Expressions Violate Guidance ▶
Fix with agent prompt
### Issue 1
packages/client/tests/ClientTest.php:23-36
These tests encode timeout settings into synthetic `X-*` response headers and then assert those headers. The TLS checks on lines 39–55 and the connection-reuse and redirect checks on lines 58–77 follow the same pattern. This mirrors how configuration is forwarded rather than testing observable client behavior: the tests can fail after a harmless adapter refactor, yet still pass when an adapter accepts an option but applies it incorrectly. The repository requires tests to verify observable behavior rather than implementation details, so this must be replaced with transport-level timeout, TLS, connection-reuse, and redirect coverage 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/client/tests/CompatTest.php:undefined-22
These reflection assertions hard-code that compatibility uses aliases targeting these exact symbols. The type-declaration test below already verifies the observable requirement by passing the moved implementations through the old type declarations. The repository requires tests to cover observable behavior rather than mirror implementation details, so these identity checks must be removed before merging. The same issue occurs for the legacy interface assertion on line 32.

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/span/tests/Exporter/SentryTest.php:undefined-33
This test invokes the private `buildEnvelope` method through reflection instead of exercising Sentry export through its public contract. Line 57 similarly reads the private `client` property. The repository explicitly prohibits reflection-based tests of private members because routine internal refactors can break them without changing observable behavior. This requirement must be satisfied before merging.

### Issue 4
packages/client/src/Adapter/Curl/Client.php:undefined-234
The imported client uses a regular expression to detect the HTTP header terminator. The same pattern appears in `parseHeaderBlock` on lines 525–537 and in the new test helpers at `packages/client/tests/server.php:161` and `packages/client/tests/Server/Http.php:137`. Repository guidance explicitly requires string functions or an existing parser unless the PR explains why neither works, so these expressions must be replaced or justified 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

This PR absorbs the client and span libraries into packages/, updates consumers to the new client namespace, wires package autoload files and cyclic package installation into the monorepo tooling, and preserves legacy names through a compatibility shim.

  • Adds root autoload and replacement metadata for the client and span packages.
  • Updates agents and Appwrite call sites to the namespaced client API.
  • Extends monorepo tooling for package autoload.files and cyclic dependency release lines.
  • Includes package-local implementations, documentation, and tests for client and span.
  • Subsequent changes also add storage format normalization and propagation of custom mail headers.

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

$this->fail($old . ' does not resolve');
}

$this->assertSame(Client::class, new \ReflectionClass($old)->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 Tests Depend On Aliases

These reflection assertions hard-code that compatibility uses aliases targeting these exact symbols. The type-declaration test below already verifies the observable requirement by passing the moved implementations through the old type declarations. The repository requires tests to cover observable behavior rather than mirror implementation details, so these identity checks must be removed before merging. The same issue occurs for the legacy interface assertion on line 32.

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: 22

Comment:
**Tests Depend On Aliases**

These reflection assertions hard-code that compatibility uses aliases targeting these exact symbols. The type-declaration test below already verifies the observable requirement by passing the moved implementations through the old type declarations. The repository requires tests to cover observable behavior rather than mirror implementation details, so these identity checks must be removed before merging. The same issue occurs for the legacy interface assertion on line 32.

**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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pre-existing in the imported library (client at the 0.5.0 release, span at c935f78). An absorb PR relocates the package with its history. The only library changes here are the two scoped client commits described in the PR, so this is left for its own change against the package, now that it lives here.

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.

That’s fair. Since these assertions are pre-existing in client 0.5.0 and this PR only relocates the package (apart from the two scoped compatibility changes), removing them here would expand the absorb PR’s scope and alter imported package history. I’m withdrawing this comment; the identity checks can be addressed in a follow-up change against packages/client if desired.

{
$exporter = new Sentry(dsn: 'https://[email protected]/123');

$method = new \ReflectionMethod(Sentry::class, 'buildEnvelope');

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 Reach Private Internals

This test invokes the private buildEnvelope method through reflection instead of exercising Sentry export through its public contract. Line 57 similarly reads the private client property. The repository explicitly prohibits reflection-based tests of private members because routine internal refactors can break them without changing observable behavior. This requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/span/tests/Exporter/SentryTest.php
Line: 33

Comment:
**Tests Reach Private Internals**

This test invokes the private `buildEnvelope` method through reflection instead of exercising Sentry export through its public contract. Line 57 similarly reads the private `client` property. The repository explicitly prohibits reflection-based tests of private members because routine internal refactors can break them without changing observable behavior. This requirement must be satisfied before merging.

**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))

---

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pre-existing in the imported library (client at the 0.5.0 release, span at c935f78). An absorb PR relocates the package with its history. The only library changes here are the two scoped client commits described in the PR, so this is left for its own change against the package, now that it lives here.

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.

That context is reasonable. Since SentryTest.php is imported from the existing span package and this PR only relocates it (apart from the scoped client changes), the reflection-based coverage is pre-existing and outside this absorb PR’s scope. I’m withdrawing this as a merge blocker; it can be addressed in a follow-up change against packages/span.

throw $this->networkException($request, $message === '' ? 'Curl request failed.' : $message, $code);
}

if (!preg_match("/\r\n\r\n|\n\n|\r\r/", $headers)) {

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 Regular Expressions Violate Guidance

The imported client uses a regular expression to detect the HTTP header terminator. The same pattern appears in parseHeaderBlock on lines 525–537 and in the new test helpers at packages/client/tests/server.php:161 and packages/client/tests/Server/Http.php:137. Repository guidance explicitly requires string functions or an existing parser unless the PR explains why neither works, so these expressions must be replaced or justified before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/client/src/Adapter/Curl/Client.php
Line: 234

Comment:
**Regular Expressions Violate Guidance**

The imported client uses a regular expression to detect the HTTP header terminator. The same pattern appears in `parseHeaderBlock` on lines 525–537 and in the new test helpers at `packages/client/tests/server.php:161` and `packages/client/tests/Server/Http.php:137`. Repository guidance explicitly requires string functions or an existing parser unless the PR explains why neither works, so these expressions must be replaced or justified before merging.

**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))

---

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pre-existing in the imported library (client at the 0.5.0 release, span at c935f78). An absorb PR relocates the package with its history. The only library changes here are the two scoped client commits described in the PR, so this is left for its own change against the package, now that it lives here.

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.

That’s fair. Since these regexes are unchanged from the imported client 0.5.0 implementation and this PR’s client edits are limited to the scoped follow-up commits, they’re not actionable for this absorb/relocation change. I’ll withdraw this finding and leave the replacement or justification for a dedicated client change.

Comment on lines +23 to +36
public function testItDecoratesConfigurableAdapters(): void
{
$request = new Request\Factory()->createRequest('GET', 'https://example.com');
$adapter = new RecordingAdapter();
$client = new Client($adapter);
$configured = $client
->withTimeout(5.5)
->withConnectTimeout(1.25);

$response = $configured->sendRequest($request);

$this->assertSame('', $client->sendRequest($request)->getHeaderLine('X-Timeout'));
$this->assertSame('5.5', $response->getHeaderLine('X-Timeout'));
$this->assertSame('1.25', $response->getHeaderLine('X-Connect-Timeout'));

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 Mirror Adapter Internals

These tests encode timeout settings into synthetic X-* response headers and then assert those headers. The TLS checks on lines 39–55 and the connection-reuse and redirect checks on lines 58–77 follow the same pattern. This mirrors how configuration is forwarded rather than testing observable client behavior: the tests can fail after a harmless adapter refactor, yet still pass when an adapter accepts an option but applies it incorrectly. The repository requires tests to verify observable behavior rather than implementation details, so this must be replaced with transport-level timeout, TLS, connection-reuse, and redirect coverage 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/ClientTest.php
Line: 23-36

Comment:
**Tests Mirror Adapter Internals**

These tests encode timeout settings into synthetic `X-*` response headers and then assert those headers. The TLS checks on lines 39–55 and the connection-reuse and redirect checks on lines 58–77 follow the same pattern. This mirrors how configuration is forwarded rather than testing observable client behavior: the tests can fail after a harmless adapter refactor, yet still pass when an adapter accepts an option but applies it incorrectly. The repository requires tests to verify observable behavior rather than implementation details, so this must be replaced with transport-level timeout, TLS, connection-reuse, and redirect coverage 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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pre-existing in the imported library (client at the 0.5.0 release, span at c935f78). An absorb PR relocates the package with its history. The only library changes here are the two scoped client commits described in the PR, so this is left for its own change against the package, now that it lives here.

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.

That’s fair. Since these tests are carried over from the released client package and the absorb PR only changes the two scoped client commits, this is pre-existing library coverage rather than a regression introduced here. I’m withdrawing this finding; the transport-level coverage can be addressed in a follow-up change against packages/client.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

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

Metric Before After Change
🚀 Requests/sec 180.29 172.65 ⚪ -4.2%
⏱️ Latency P50 94.54 ms 100.06 ms 🔴 +5.8%
⏱️ Latency P95 228.62 ms 230.99 ms ⚪ +1%
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 100.06 230.99 11,343 172.65 +2.37
Account 189.58 353.26 597 9.92 -18.13
TablesDB 95.64 182.1 6,169 98.35 +2.23
Storage 93.36 190.75 2,985 48.48 -7.27
Functions 149.75 285.28 1,592 26.23 -3.83

Top API waits (after)

API request Max wait (ms)
account.name.update 579.83
tablesdb.rows.delete 540.51
functions.delete 493.42
functions.variables.update 445.71
tablesdb.rows.increment 441.2

@ChiragAgg5k
ChiragAgg5k merged commit 008b5f9 into main Sep 23, 2026
78 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the feat/absorb-client-and-span branch September 23, 2026 14:10
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