Skip to content

chore: absorb nats into packages/nats - #13969

Merged
ChiragAgg5k merged 22 commits into
mainfrom
chore/absorb-nats
Sep 29, 2026
Merged

ChiragAgg5k merged 22 commits into
mainfrom
chore/absorb-nats

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

Moves utopia-php/nats into packages/nats so Appwrite loads it directly. Part of #13828, following the playbook in rfc/monorepo.md.

The RFC planned to move nats to appwrite/cloud. It lives here instead: its real consumer is packages/queue, whose NATS JetStream broker (Utopia\Queue\Broker\Nats) needs utopia-php/nats ^1.4. Cloud is private and has no split tooling, and it only gets nats transitively. The RFC's non-goals and phase 7 now say so. replication is being archived separately, not moved.

Merge with a merge commit: a squash drops the git-subtree-* annotation and orphans the package from its mirror.

Commit What
Add 'packages/nats/' from commit '016f48bd…' Subtree import of the mirror's main with full history
chore(nats): mirror plumbing mirror.yml calls this repository's mirror-redirect.yml; README banner points here. No banned files to strip
refactor: load nats from packages/ Root autoload + replace, step A shape, standalone phpstan.neon / rector.php, baseline
docs(rfc): keep nats in packages/ and list its baseline for phase 8 Non-goals and phase 7 updated; one bullet in the phase 8 list

Version gap

None. Mirror head 016f48bd is the 1.4.0 tag, and utopia-php/monorepo's packages/nats is byte-identical to it. Appwrite did not install utopia-php/nats before this PR; queue only had it in require-dev / suggest.

Step A

Change Detail
src/ Already flat. Identical to 1.4.0 apart from Pint formatting (empty {} constructor and class bodies expanded in 51 files)
tests/Unit/* → tests/ Namespace Utopia\NATS\Tests\Unit → Utopia\NATS\Tests. FakeTransport and a loopback stream_socket_server on port 0 only; no NATS server, no Swoole
tests/E2E/ Unchanged: 19 suites against the package compose (plain, TLS and WebSocket NATS servers)
phpunit.xml PHPUnit 12 shape: unit = tests minus E2E, e2e = tests/E2E
docker-compose.yml name: utopia-nats, so it never shares a compose project
phpstan.neon Standalone, level max over src + tests (previously included ../../phpstan.neon, the monorepo's level 5)
rector.php PHP sets + type declarations, skipping ClassPropertyAssignToConstructorPromotionRector and ReadOnlyPropertyRector (same as balancer). No changes
phpstan-baseline.neon 445 findings: 292 in src (decoded mixed JSON in the JetStream/KeyValue/ObjectStore fromArray() builders, ServerInfo, Connection), 81 in the unit tests, 72 in e2e
README Testing section pointed at composer test / composer test:e2e (upstream named a non-existent integration suite). No badges or CONTRIBUTING to fix

Nothing to hoist: require is php and ext-json, already in the root require.

Lock

utopia-php/nats was never in composer.lock, so there is no line to drop. composer update --lock plus composer update --no-install --minimal-changes change only the content-hash.

Validation

Check Result
bin/monorepo validate all packages valid
bin/monorepo check nats Rector, Pint, PHPStan level max (with baseline) pass
bin/monorepo test nats unit 172 tests / 427 assertions; e2e 80 / 415 against the compose (project utopia-nats, torn down)
Queue unit tier (appwrite/appwrite:2.3.0), registry and --linked 152 / 340 both ways, including the 20 NATS broker tests
Queue e2e tier (appwrite/appwrite:2.3.0, compose project absorb-nats-queue, torn down), registry and --linked (utopia-php/nats 1.4.999 mirrored from packages/nats) 162 / 784 both ways, 2 skipped (KEDA not provisioned in the container)
Root phpunit --testsuite packages in appwrite/appwrite:2.3.0 completes in 2m05s: 9043 tests / 25822 assertions, 17 skipped (was 37: the 20 queue NATS tests now run). 5 errors are the known agents DiffCheckTest worktree .git issue
Root suite, --filter 'Utopia\\NATS' 172 / 427 pass
Root suite, NatsBrokerConfigTest + ServerJobsTest::testStartKeepsConcurrencyOnTheNatsBroker 20 / 24 pass. Service-free: the connection factory throws if called
composer validate --no-check-publish valid
bin/monorepo split nats --dry-run 5c9cfa64, fast-forwards from mirror head 016f48bd (2 commits), tree identical to packages/nats
git diff --check clean

The queue tiers crash under macOS host Swoole (unit segfault, e2e bus error), so they ran in the Linux image.

One PHP 8.4+ deprecation comes with the source: Connection::reconnect() calls lcg_value() for jitter. It shows as a deprecation in the root packages suite, which does not fail on deprecations. Left as is to keep this a pure move.

Mirror

utopia-php/nats had no ruleset and no classic protection. absorb created the canonical main ruleset (id 24166699: deletion, non-fast-forward, pull request) with the split app (4016286) as an always-bypass actor.

After merge

Step
Confirm Split pushes to utopia-php/nats
Retire remove packages/nats from utopia-php/monorepo
Cloud drop utopia-php/nats from appwrite-labs/cloud's composer.json; it now arrives through server-ce
Triage no open PRs or issues on the mirror; no open monorepo PRs touch packages/nats

🤖 Generated with Claude Code

levivannoort and others added 20 commits May 27, 2026 12:56
Rename the Composer package from nats/nats to utopia-php/nats and move
the root namespace from Nats to Utopia\NATS across src, tests, examples,
README, and PSR-4 autoload config.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
refactor: rename package to utopia-php/nats with Utopia\NATS namespace
chore(nats): absorb into the monorepo
build: hoist baseline rector + phpstan configs to the root
docs: enforce documentation style with Vale
nats: bring the client to broad + deep feature parity
…ge-dlq-ttl

feat(queue,nats): consumer backoff, stream storage choice, dead-letter TTL
…ection

fix(nats,pools,queue): stop losing work, dedupe enqueues, end duplicate delivery (CLO-4771/4772/4773)
…ming

test(nats): measure which deadline stopped requestMany, not the runner
…elay

fix(nats): three defects on the JetStream pull path
chore: stop committing package lock files
feat(nats,queue): batch JetStream publishes instead of one round trip per message
…-reconnect

fix(nats): replay a request once after a closing -ERR reconnects
Pipeline NATS requests with individual confirmations
…d5459'

git-subtree-dir: packages/nats
git-subtree-mainline: 1f88932
git-subtree-split: 016f48b
@ChiragAgg5k ChiragAgg5k added the absorb History-preserving package absorption; merge commit required label Sep 29, 2026
@ghost

ghost commented Sep 29, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new Rector exclusions do not introduce a concrete defect.

This PR imports the NATS client into packages/nats, wires its source and tests into Appwrite's root autoloader, and adds standalone testing, analysis, and mirror tooling. It also updates the monorepo RFC to place NATS alongside its queue consumer. The later commits align the package's PHP requirement with its source and keep Rector from rewriting additional imported declarations.

Latest changes: The newest commit adds three Rector skips to preserve imported readonly classes, class constants, and arrow-function return types.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 7
File Change
composer.json, composer.lock Load NATS from the package directory, declare the replacement, and update the lock hash.
packages/nats/src/ Import the NATS client implementation.
packages/nats/tests/, packages/nats/phpunit.xml Import unit and E2E tests with separate suites.
packages/nats/composer.json, packages/nats/phpstan.neon, packages/nats/phpstan-baseline.neon, packages/nats/rector.php, packages/nats/.gitignore Add standalone package metadata and checks, declare PHP 8.3 support, and exclude source-altering Rector rules.
packages/nats/docker-compose.yml, packages/nats/tests/fixtures/ Provide isolated NATS services and fixtures for E2E tests.
packages/nats/.github/workflows/mirror.yml, packages/nats/README.md, packages/nats/examples/ Add mirror redirection, documentation, and examples.
rfc/monorepo.md Document NATS's placement and baseline in the monorepo plan.

Reviewed the commits since 22a375f · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Tier B · 1 blocking finding to address. Summary

Comment thread packages/nats/composer.json Resolved
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High risk] Absorbs NATS messaging library into monorepo packages.

The PR should satisfy the repository’s test-parsing requirement before merging; no new runtime blocker was established.

Fix All in Claude CodeFindings

  1. P2 Regex in test frame parser ▶
Fix with agent prompt
### Issue 1
packages/nats/tests/ConsumerPullRequestTest.php:48-52
`pullRequest()` adds a `preg_match` pattern to parse a protocol frame. The repository instructs us not to add regular expressions unless the PR explains why string functions or an existing validator cannot work. Please satisfy that requirement before merging; the pattern also makes this test harder to review and maintain.

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 imports NATS into packages/nats, wires root autoloading and package replacement, and adds standalone test, analysis, and mirror configuration. Since the previous review, it has added Rector exclusions to keep the imported code unchanged.

  • One repository-rule violation remains in a test’s regular-expression frame parser.
  • The earlier findings have resolved threads and are not reposted.

Reviews (3) · Last reviewed commit: "chore(nats): keep Rector's PHP 8.2/8.3 r..."

Comment thread packages/nats/src/Connection.php Resolved
Comment thread packages/nats/src/Connection.php Resolved
Connection declares typed class constants, which PHP 8.1 and 8.2 cannot parse; the manifest allowed >=8.1, so Composer could install the mirror on a runtime that fails to load it.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

Raising the PHP floor to 8.3 enabled ReadOnlyClassRector and AddTypeToConstRector (and an arrow-function return-type rule), so Rector's dry run in CI wanted to rewrite 44 files. The absorb keeps the source as released.
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

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

Metric Before After Change
🚀 Requests/sec 173.26 168.4 ⚪ -2.8%
⏱️ Latency P50 99.9 ms 102.25 ms ⚪ +2.3%
⏱️ Latency P95 232.84 ms 240.19 ms ⚪ +3.2%
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 102.25 240.19 10,545 168.4 +7.35
Account 200.13 373.37 555 9.17 +11.67
TablesDB 97.85 183.47 5,735 93.5 +2.55
Storage 96.36 198.72 2,775 47.04 -4.82
Functions 148.46 294.37 1,480 25.79 +16.36

Top API waits (after)

API request Max wait (ms)
account.name.update 551.04
account.prefs.update 475.31
functions.delete 472.71
functions.variables.update 468.54
functions.create 427.19

Comment on lines +48 to +52
$matched = preg_match(
'#PUB \$JS\.API\.CONSUMER\.MSG\.NEXT\.STREAM\.durable \S+ \d+\r\n(\{.*?\})\r\n#s',
$fake->written,
$m,
);

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 Regex in test frame parser

pullRequest() adds a preg_match pattern to parse a protocol frame. The repository instructs us not to add regular expressions unless the PR explains why string functions or an existing validator cannot work. Please satisfy that requirement before merging; the pattern also makes this test harder to review and maintain.

Context Used: CLAUDE.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/nats/tests/ConsumerPullRequestTest.php
Line: 48-52

Comment:
**Regex in test frame parser**

`pullRequest()` adds a `preg_match` pattern to parse a protocol frame. The repository instructs us not to add regular expressions unless the PR explains why string functions or an existing validator cannot work. Please satisfy that requirement before merging; the pattern also makes this test harder to review and maintain.

**Context Used:** CLAUDE.md ([source](https://github.com/appwrite/appwrite/blob/main/CLAUDE.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

@ChiragAgg5k
ChiragAgg5k merged commit 8552460 into main Sep 29, 2026
54 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the chore/absorb-nats branch September 29, 2026 09:07
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