feat(agent): add circuit breaker (#345) - #416
Merged
Abidoyesimze merged 2 commits intoSep 2, 2026
Merged
Conversation
Add an agent circuit breaker that halts agent-initiated rebalancing when the market, a protocol, or a user shows risk. Withdrawals are untouched. - Pure trip rules (breakerRules.ts): abnormal-loss drawdown, stablecoin de-peg (fails safe on a missing feed), rebalance oscillation, stale APY. - Pure CLOSED/OPEN/HALF_OPEN state machine (breakerState.ts) with cooldown backoff and manual trip/reset. - Integration (breakerService.ts): measurement loads, per-tick evaluation, fail-closed halting, operator alerts, user events, status surfaces. - Loop wiring: GLOBAL > PROTOCOL > USER blocking, BLOCKED decisions, blockedProtocols target exclusion, agent status + per-user status route. - Admin endpoints: list/trip/reset breakers with audit logging. - Prometheus gauge + counters and alert rules; RUNBOOK + OBSERVABILITY docs. - Tests: 5 new suites (rules, state machine, service status/privacy, loop blocking, target exclusion) + harness update. De-peg is a pure rule consuming a price input; no live feed exists yet so getStablecoinPrice() returns null (fails safe) and the rule stays off by default (BREAKER_DEPEG_ENABLED=false).
|
@BernardOnuh Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the Agent Circuit Breaker (#345): halts agent-initiated rebalancing when the market, a protocol, or a user shows risk. Withdrawals are untouched (acceptance criterion).
Changes
src/agent/breakerRules.ts): abnormal-loss drawdown, stablecoin de-peg, rebalance oscillation, stale APY — all deterministic, DB/clock-free.src/agent/breakerState.ts):CLOSED → OPEN → HALF_OPEN → CLOSEDwith cooldown backoff and manual trip/reset.src/agent/breakerService.ts): measurement loads, per-tick evaluation, fail-closed halting, operator alerts, user events, sync status surfaces.GLOBAL > PROTOCOL > USERblocking precedent,BLOCKEDdecision records,blockedProtocolstarget exclusion,GET /agent/status+ per-user breaker status.requireAdminScope('agent')).agent_breaker_stategauge +agent_breaker_trips_totalcounter, Prometheus alert rules, RUNBOOK + OBSERVABILITY docs.De-peg feed gap (documented, see RUNBOOK §9)
The de-peg rule is a pure consumer of a stablecoin spot price. No live feed exists in this codebase yet (the fee oracle publishes fees only;
routing.tsis a stub), sogetStablecoinPrice()returnsnull(fails safe — never trips) and the rule is off by default (BREAKER_DEPEG_ENABLED=false).getStablecoinPrice()is the single integration point to wire a feed later.Verification
pnpm/npm:typecheck,lint,prettierall pass1695tests pass, incl. 5 new suites: rules, state machine, service status/privacy, loop blocking, target exclusionCloses #345