Skip to content

chore: absorb websocket into packages/websocket - #13870

Merged
loks0n merged 131 commits into
mainfrom
feat/absorb-websocket
Sep 23, 2026
Merged

loks0n merged 131 commits into
mainfrom
feat/absorb-websocket

Conversation

@loks0n

@loks0n loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member

Summary

This moves utopia-php/websocket into packages/websocket, so Appwrite loads it directly. It follows the playbook in rfc/monorepo.md and comes in three commits:

  1. Add 'packages/websocket/' from commit 'd5763527…': subtree import from the mirror with full history. The mirror head is the 2.0.2 tag Appwrite already pins, and its tree matches packages/websocket in utopia-php/monorepo (f25d177), so realtime runs the same code.
  2. chore(websocket): mirror plumbing: mirror.yml now points here, the README banner is refreshed, and the banned psalm.xml is removed.
  3. refactor: load websocket from packages/:
    • Adds the root autoload and replace entries, drops the utopia-php/websocket: 2.0.2 require line, and removes the package from the lock.
    • Step A of the standard shape:
      • src/WebSocket/* moves up to src/.
      • tests/Unit/ClientTest.php moves up to tests/. tests/E2E and tests/Fixtures stay.
      • tests/E2E/AdapterTest.php declared Utopia\WebSocket\Tests, which doesn't match its path, so it becomes Utopia\WebSocket\Tests\E2E.
      • phpunit.xml now runs tests with tests/E2E excluded for the unit suite.
    • Adds a new standalone phpstan.neon at level max over src and tests, with a phpstan-baseline.neon of 22 findings. The monorepo analysed this package at level 5. They are mixed handling in Client and the Workerman adapter, plus the Swoole fixture server and e2e helpers. The RFC's phase 8 burn-down list now includes them.
    • Pint formatting (empty constructor bodies).

There's nothing to hoist, since the package requires only PHP. Its require-dev (swoole/ide-helper, workerman/workerman) is only used by its own test tier. Appwrite uses it in app/realtime.php, src/Appwrite/Utopia/WebSocket/Adapter/Swoole.php (which subclasses the Swoole adapter) and src/Appwrite/Realtime/EventTailRegistry.php, and root PHPStan passes on all of them.

Open PRs, triaged

All three targeted Adapter/Swoole.php and are closed with a pointer here:

Validation

  • bin/monorepo validate: all packages valid
  • bin/monorepo check websocket: Pint and PHPStan level max (with baseline) pass
  • bin/monorepo test websocket: unit 9 tests / 22 assertions; e2e 5 tests / 996 assertions against real Swoole and Workerman fixture servers (tests/e2e.sh)
  • vendor/bin/phpunit --testsuite packages --filter 'Utopia\\WebSocket\\Tests': 9 tests pass under the root autoloader, with E2E excluded
  • vendor/bin/phpunit tests/unit/Realtime: 25 tests pass
  • bin/monorepo split websocket --dry-run: bed15def, which fast-forwards from the mirror head d5763527
  • git diff --check

Merge and follow-up

Merge with a merge commit.

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

After merge: confirm Split pushes to utopia-php/websocket. Then remove packages/websocket from utopia-php/monorepo.

🤖 Generated with Claude Code

ChiragAgg5k and others added 15 commits July 10, 2025 16:30
feat: add onRequest method to WebSocket adapters
The SWOOLE_WEBSOCKET_FLAG_COMPRESS flag was hardcoded in send(),
which could cause issues with Swoole 6.1.6 when clients don't
support permessage-deflate compression.

Now the COMPRESS flag is only included when websocket_compression
is explicitly enabled in the server config.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
fix: only use COMPRESS flag when compression is enabled
Drop getConnections() from Adapter, Server, Swoole, and Workerman, and
remove Swoole's private self::$connections mirror. Tracking the set of
live fds belongs to the calling layer, not the transport library.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01245mLhHWfmjZejiua8wvMP
The test servers now maintain their own $connections set in onOpen/onClose
and use it for broadcast and the /info count, replacing the removed
$server->getConnections().

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01245mLhHWfmjZejiua8wvMP
phpstan (level max) flagged the $server use as unused after the /info
count switched from $server->getConnections() to the local $connections set.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01245mLhHWfmjZejiua8wvMP
chore(websocket): absorb utopia-php/websocket
fix(websocket): time out stalled sends and reset failed connections
…eeebff5dfd'

git-subtree-dir: packages/websocket
git-subtree-mainline: 0713bdd
git-subtree-split: d576352
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The implementation appears behaviorally safe, but the explicit no-reflection testing requirement must be satisfied before merging; the README example should also be corrected.

Fix All in Claude CodeFindings

  1. P2 Tests Reach Private State ▶
  2. P2 Close Example Uses Undefined Variable ▶
Fix with agent prompt
### Issue 1
packages/websocket/tests/ClientTest.php:104-110
These tests use reflection to replace `Client`'s private `connected` and `client` properties. This violates the repository directive to never use reflection to reach private members and couples the tests to implementation details rather than observable behavior. The same pattern appears again at lines 143–149. Replace both cases with public API behavior or an explicit test seam 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/websocket/README.md:45-47
The close callback receives `$connection` but interpolates `$workerId`, which is undefined in this scope. Users copying the example will get an undefined-variable warning and will not see the closed connection's identifier.

```suggestion
$server->onClose(function (int $connection) {
    echo "Connection {$connection} closed!";
});
```

---

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

Summary

This PR absorbs the pinned WebSocket package into packages/websocket, switches the root Composer configuration to direct PSR-4 loading, and adds package-local QA and mirror configuration.

  • Imports the Swoole and Workerman adapters, client, server, fixtures, and tests.
  • Removes the external utopia-php/websocket lock entry and declares the local package as its replacement.
  • Normalizes source and test paths to the monorepo package shape.
  • Adds package PHPStan, PHPUnit, mirror, and E2E-runner configuration.
  • The source migration preserves the pinned implementation, but the imported unit tests violate the repository's testing rules and the README example contains an invalid variable reference.

Reviews (1) · Last reviewed commit: "refactor: load websocket from packages/"

Comment on lines +104 to +110
// Use reflection to set the private properties
$reflectionClass = new \ReflectionClass(Client::class);

$connectedProperty = $reflectionClass->getProperty('connected');
$connectedProperty->setValue($this->client, true);

$clientProperty = $reflectionClass->getProperty('client');

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 State

These tests use reflection to replace Client's private connected and client properties. This violates the repository directive to never use reflection to reach private members and couples the tests to implementation details rather than observable behavior. The same pattern appears again at lines 143–149. Replace both cases with public API behavior or an explicit test seam before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/websocket/tests/ClientTest.php
Line: 104-110

Comment:
**Tests Reach Private State**

These tests use reflection to replace `Client`'s private `connected` and `client` properties. This violates the repository directive to never use reflection to reach private members and couples the tests to implementation details rather than observable behavior. The same pattern appears again at lines 143–149. Replace both cases with public API behavior or an explicit test seam 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

Comment on lines +45 to +47
$server->onClose(function (int $connection) {
echo "Connection {$workerId} closed!";
});

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 Close Example Uses Undefined Variable

The close callback receives $connection but interpolates $workerId, which is undefined in this scope. Users copying the example will get an undefined-variable warning and will not see the closed connection's identifier.

Suggested change
$server->onClose(function (int $connection) {
echo "Connection {$workerId} closed!";
});
$server->onClose(function (int $connection) {
echo "Connection {$connection} closed!";
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/websocket/README.md
Line: 45-47

Comment:
**Close Example Uses Undefined Variable**

The close callback receives `$connection` but interpolates `$workerId`, which is undefined in this scope. Users copying the example will get an undefined-variable warning and will not see the closed connection's identifier.

```suggestion
$server->onClose(function (int $connection) {
    echo "Connection {$connection} closed!";
});
```

---

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

Copy link
Copy Markdown

✨ Benchmark results

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

Metric Before After Change
🚀 Requests/sec 204.19 209.25 ⚪ +2.5%
⏱️ Latency P50 84.76 ms 82.16 ms ⚪ -3.1%
⏱️ Latency P95 198.73 ms 195.36 ms ⚪ -1.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 82.16 195.36 13,167 209.25 -3.38
Account 159.33 307.1 693 11.47 -2.86
TablesDB 78.16 141.24 7,161 116.43 -11.02
Storage 78.23 166.66 3,465 58.18 +1.32
Functions 118.22 249.62 1,848 31.68 -4.15

Top API waits (after)

API request Max wait (ms)
account.name.update 633.99
account.prefs.update 445.17
functions.variables.update 420.37
functions.delete 406.15
functions.create 384.38

@loks0n
loks0n merged commit 62e9fdf into main Sep 23, 2026
67 checks passed
@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Split run pushed utopia-php/websocket main to b6dc574, a fast-forward on d576352, with a tree matching packages/websocket. Remaining: utopia-php/monorepo#344 retires the package there.

@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Retired from the monorepo in utopia-php/monorepo#344. Its Split run no longer includes websocket, and the mirror stays at b6dc574. The migration is complete.

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.