Skip to content

feat: circuit breaker around /api/impersonate downstream calls - #716

Open
victorocheje wants to merge 1 commit into
Predictify-org:mainfrom
victorocheje:feat/impersonate-circuit-breaker
Open

feat: circuit breaker around /api/impersonate downstream calls#716
victorocheje wants to merge 1 commit into
Predictify-org:mainfrom
victorocheje:feat/impersonate-circuit-breaker

Conversation

@victorocheje

Copy link
Copy Markdown
Contributor
  • Add src/lib/circuitBreaker.ts: generic per-name CLOSED/OPEN/HALF_OPEN state machine with CircuitOpenError, getCircuitBreaker(), forceCircuitStateForTests(), and resetCircuitBreakersForTests()

  • Update src/routes/admin/users/impersonate.ts: wrap signAccessToken + audit DB writes inside breaker.execute(); CircuitOpenError maps to HTTP 503 with retryAfterMs in the response body

  • Add tests/circuitBreaker.test.ts: 36 unit tests covering all state transitions, error types, helpers, and snapshot accuracy

  • Add tests/impersonateCircuitBreaker.test.ts: focused integration tests covering CLOSED/OPEN/HALF_OPEN scenarios, threshold tripping, auth guard passthrough, and 503 response shape

  • Fix pre-existing corruptions: dead z.object() block in env.ts and duplicate/broken implementation in errorHandler.ts; fix wrong JWT secret fallback in adminImpersonate.test.ts

  • Add docs/impersonate-circuit-breaker.md: state machine diagram, default config, HTTP response reference, and runbook

closes #593

- Add src/lib/circuitBreaker.ts: generic per-name CLOSED/OPEN/HALF_OPEN
  state machine with CircuitOpenError, getCircuitBreaker(),
  forceCircuitStateForTests(), and resetCircuitBreakersForTests()

- Update src/routes/admin/users/impersonate.ts: wrap signAccessToken +
  audit DB writes inside breaker.execute(); CircuitOpenError maps to
  HTTP 503 with retryAfterMs in the response body

- Add tests/circuitBreaker.test.ts: 36 unit tests covering all state
  transitions, error types, helpers, and snapshot accuracy

- Add tests/impersonateCircuitBreaker.test.ts: focused integration tests
  covering CLOSED/OPEN/HALF_OPEN scenarios, threshold tripping, auth
  guard passthrough, and 503 response shape

- Fix pre-existing corruptions: dead z.object() block in env.ts and
  duplicate/broken implementation in errorHandler.ts; fix wrong JWT
  secret fallback in adminImpersonate.test.ts

- Add docs/impersonate-circuit-breaker.md: state machine diagram,
  default config, HTTP response reference, and runbook
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@victorocheje 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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add per-endpoint circuit breaker for downstream calls on /api/impersonate [b#019]

1 participant