Skip to content

chore: absorb circuit-breaker into packages/circuit-breaker - #13869

Merged
loks0n merged 21 commits into
mainfrom
feat/absorb-circuit-breaker
Sep 23, 2026
Merged

loks0n merged 21 commits into
mainfrom
feat/absorb-circuit-breaker

Conversation

@loks0n

@loks0n loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member

Summary

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

  1. Add 'packages/circuit-breaker/' from commit '51c9b9b0…': subtree import from the mirror with full history. The mirror head is the 0.4.1 tag Appwrite already locks, and its tree matches packages/circuit-breaker in utopia-php/monorepo (34f0cca), so the dependency graph doesn't change.
  2. chore(circuit-breaker): mirror plumbing: mirror.yml now points here, the README banner is refreshed, and absorb removes the Dockerfile, since docker-compose.yml doesn't build from it.
  3. refactor: load circuit-breaker from packages/:
    • Adds the root autoload and replace entries and removes the package from the lock. Appwrite never required it directly; it came in through utopia-php/cache (^0.4), and replace now satisfies that.
    • Drops the local telemetry demo: docker-compose.telemetry.yml, the Grafana/Prometheus/OTel stack under docker/, examples/telemetry, the dashboard screenshot, the telemetry:* composer scripts and their README section, 1,797 lines in all. The demo built from the Dockerfile the monorepo tooling strips, so it would have broken anyway. Telemetry support in the library itself is unchanged and still documented.
    • Step A of the standard shape:
      • src/CircuitBreaker/* moves up to src/.
      • tests/unit/* moves up to tests/, and tests/e2e becomes tests/E2E, matching the root packages suite exclusion.
      • Tests move from the bare Utopia\Tests\{unit,e2e} namespace to Utopia\CircuitBreaker\Tests (and Tests\E2E), with a matching autoload-dev entry.
    • phpstan.neon used to include the monorepo root config, and validate rejects that, so it's now standalone at level max. Its two documented ignoreErrors are kept. A phpstan-baseline.neon holds 29 findings, since the monorepo analysed this package at level 5. They are casts from mixed in the Redis and Swoole Table adapters, plus loosely typed fixtures in the tests. The RFC's phase 8 burn-down list now includes them.
    • The README's test instructions pointed at a composer test:e2e:docker script that doesn't exist. They now say docker compose up -d --wait && composer test:e2e.
    • Pint formatting (braces_position, fn ( spacing).

There's nothing to hoist, since the package requires only PHP. utopia-php/telemetry stays in its require-dev for the unit tier.

Net: +216 / −1,974 across the three commits.

Validation

  • bin/monorepo validate: all packages valid
  • bin/monorepo check circuit-breaker: Pint and PHPStan level max (with baseline) pass
  • bin/monorepo test circuit-breaker: unit 36 tests / 117 assertions; e2e 6 tests / 30 assertions against Redis from docker-compose.yml, plus Swoole Table
  • vendor/bin/phpunit --testsuite packages --filter 'Utopia\\CircuitBreaker\\Tests': 36 tests pass under the root autoloader, with E2E excluded
  • Utopia\CircuitBreaker\CircuitBreaker resolves to packages/circuit-breaker/src from the root autoloader (used by utopia-php/cache's CircuitBreaker adapter)
  • bin/monorepo split circuit-breaker --dry-run: f40e0130, which fast-forwards from the mirror head 51c9b9b0
  • git diff --check

Merge and follow-up

Merge with a merge commit.

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

After merge: confirm Split pushes to utopia-php/circuit-breaker. Then remove packages/circuit-breaker from utopia-php/monorepo. cache there still requires utopia-php/circuit-breaker: ^0.4 from Packagist, and the mirror keeps serving that. The mirror has no open PRs, and neither does the monorepo for circuit-breaker.

🤖 Generated with Claude Code

ChiragAgg5k and others added 21 commits April 22, 2026 11:50
Bring the full base circuit-breaker library in under the Utopia
namespace and house it to match the shape of other utopia-php
packages (cache, pools, telemetry).

Namespaces
- ChiragAgg5k\CircuitBreaker -> Utopia\CircuitBreaker
- ChiragAgg5k\Tests -> Utopia\Tests
- Sources moved under src/CircuitBreaker/ (matches "src/<Foo>/<Foo>.php"
  PSR-4 layout used by the rest of utopia-php)

composer.json
- Name, description, authors, keywords, PSR-4 roots, suggest keys
- Utopia script names (lint / format / check / test, test:unit,
  test:e2e, test:e2e:docker, telemetry:up/scenario/down)

Docs & branding
- README rewritten with utopia banner, badges, marketing paragraph,
  section ordering, and API reference
- LICENSE copyright changed to "Utopia"

Tooling
- phpunit.xml.dist -> phpunit.xml, phpstan.neon.dist -> phpstan.neon
- docker-composer.yml / docker-composer.telemetry.yml renamed to the
  standard docker-compose.* spelling
- CI split into .github/workflows/linter.yml (pint + phpstan) and
  .github/workflows/tests.yml (unit tests on PHP 8.2/8.3/8.4 plus a
  Docker-based e2e job)

The public API, adapter surface, telemetry wiring, cache semantics,
and test coverage all behave exactly as before; this change is purely
structural + cosmetic. Unit tests, phpstan level 5, and pint all pass
locally.
- tests.yml: drop opentelemetry/protobuf host extensions from the E2E
  job. The E2E step only shells out to `composer test:e2e:docker`; all
  PHP execution happens inside the Dockerfile container where those
  extensions are installed already.
- phpstan.neon: add `tests` to analysed paths so test helpers,
  anonymous-class cache adapters, and the custom telemetry subclass
  are covered. Paired with a narrow ignoreErrors block for two
  patterns the upstream type system can't express: the $values
  property on anonymous Counter/Gauge subclasses emitted by
  Utopia\Telemetry\Adapter\Test, and the defensive
  method_exists(Redis, 'getLastError') guard.
Useful for tests that need to exercise breaker-open behaviour without
driving N failures through call(), and for operational manual breaks
(e.g. an admin endpoint disabling a backend). Idempotent: calling on
an already-open breaker refreshes openedAt without recording a transition.
feat: add trip() to force breaker into open state
Defer rare telemetry instrument creation
docs: enforce documentation style with Vale
fix(telemetry): register instruments on first write
refactor(pools,circuit-breaker,storage): drop the deprecated Instrument::lazy() helpers
circuit-breaker: judge health by failure rate, not a consecutive count
perf(telemetry, circuit-breaker): record less per call on the cache path
…a0f3a5d7e940ef2c'

git-subtree-dir: packages/circuit-breaker
git-subtree-mainline: f70a10a
git-subtree-split: 51c9b9b
@loks0n loks0n added the absorb History-preserving package absorption; merge commit required label Sep 23, 2026
@loks0n loks0n self-assigned this Sep 23, 2026
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The package integration appears technically sound, but the implementation-coupled tests violate an explicit repository requirement and should be corrected before merging.

Fix All in Claude CodeFindings

  1. P2 Tests Mirror Implementation Details ▶
Fix with agent prompt
### Issue 1
packages/circuit-breaker/tests/CircuitBreakerTest.php:167
This assertion hard-codes the exact cache key and write order. Other tests in this file also require zero adapter writes and inspect the telemetry callback registry. These checks test internal storage and registration details rather than observable circuit-breaker behavior, so harmless refactors can break the suite without changing the public contract. The repository requires tests to assert observable behavior instead of mirroring source code or configuration, and that requirement must 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!

---

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

Summary

This PR absorbs utopia-php/circuit-breaker into the monorepo while preserving the locked package implementation and switching Composer resolution to the local source.

  • Adds root production and test autoload mappings plus the Composer replacement entry.
  • Imports the circuit-breaker source, adapters, package metadata, documentation, tests, and mirror workflow.
  • Reshapes package namespaces and test directories to the monorepo standard.
  • Removes obsolete local telemetry-demo infrastructure and records inherited PHPStan findings.
  • The implementation wiring appears consistent, but several imported tests violate the repository's explicit observable-behavior testing rule.
flowchart LR
  Cache[utopia-php/cache] -->|requires ^0.4| Replace[Root Composer replace]
  Replace --> Local[packages/circuit-breaker]
  Local --> Memory[In-memory state]
  Local --> Redis[Redis adapter]
  Local --> Swoole[Swoole Table adapter]
  Local --> Telemetry[Optional telemetry]
Loading

Reviews (1) · Last reviewed commit: "refactor: load circuit-breaker from pack..."

static fn (array $write): bool => $write[0] === 'set',
));

$this->assertSame(['set', 'users-api:state', CircuitState::OPEN->value], $setWrites[array_key_last($setWrites)]);

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 implementation details

This assertion hard-codes the exact cache key and write order. Other tests in this file also require zero adapter writes and inspect the telemetry callback registry. These checks test internal storage and registration details rather than observable circuit-breaker behavior, so harmless refactors can break the suite without changing the public contract. The repository requires tests to assert observable behavior instead of mirroring source code or configuration, and that requirement must 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/circuit-breaker/tests/CircuitBreakerTest.php
Line: 167

Comment:
**Tests mirror implementation details**

This assertion hard-codes the exact cache key and write order. Other tests in this file also require zero adapter writes and inspect the telemetry callback registry. These checks test internal storage and registration details rather than observable circuit-breaker behavior, so harmless refactors can break the suite without changing the public contract. The repository requires tests to assert observable behavior instead of mirroring source code or configuration, and that requirement must 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

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

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

Metric Before After Change
🚀 Requests/sec 161.07 171.05 🟢 +6.2%
⏱️ Latency P50 105.2 ms 100.44 ms ⚪ -4.5%
⏱️ Latency P95 248.64 ms 233.52 ms 🟢 -6.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.44 233.52 11,058 171.05 -15.12
Account 197.06 350.31 582 9.64 -22.32
TablesDB 95.85 175.46 6,014 96.34 -28.88
Storage 93.9 195.91 2,910 47.66 -14.67
Functions 150.75 288.14 1,552 26.04 -13.79

Top API waits (after)

API request Max wait (ms)
account.name.update 575.55
storage.buckets.create 491.8
functions.delete 433.63
functions.variables.update 431.68
account.prefs.update 402.85

@loks0n
loks0n merged commit 0713bdd into main Sep 23, 2026
65 checks passed
@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Split run pushed utopia-php/circuit-breaker main to ae07170, a fast-forward on 51c9b9b, with a tree matching packages/circuit-breaker. Remaining: utopia-php/monorepo#343 retires the package there.

@loks0n

loks0n commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Retired from the monorepo in utopia-php/monorepo#343. Its Split run no longer includes circuit-breaker, and the mirror stays at ae07170. 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.

3 participants