Skip to content

fix: resolve idempotency middleware and health check issues - #1

Open
MatanOga01 wants to merge 1 commit into
mainfrom
fix/issues-312-313-314-315
Open

fix: resolve idempotency middleware and health check issues#1
MatanOga01 wants to merge 1 commit into
mainfrom
fix/issues-312-313-314-315

Conversation

@MatanOga01

Copy link
Copy Markdown
Owner

Summary

This PR resolves all issues assigned to MatanOga01:

Closes

Changes

ApexChainx#312 — Idempotency middleware no longer caches error responses

  • Only 2xx responses are stored in Redis; 5xx responses evict the key so retries can re-execute
  • Prevents a failed first attempt from poisoning the key for the full TTL

ApexChainx#313 — Idempotency keys are now scoped per user

  • Cache key now includes a hash of the bearer token: idempotency:{actor_key}:{idempotency_key}
  • Prevents cross-user response replay when two users send the same Idempotency-Key

ApexChainx#314 — Idempotency middleware no longer 500s when Redis is down

  • Added try/except around all Redis operations with a circuit breaker (30-second trip)
  • Fails open: requests are processed without caching when Redis is unavailable
  • Logs a warning on each circuit trip

ApexChainx#315 — Health check now catches the correct exception type

  • Removed the dead check_database() / check_celery() helpers from app/main.py that incorrectly caught redis.ConnectionError around a Postgres probe
  • The live /health/readiness endpoint already uses build_readiness_report() in health_report.py which catches sqlalchemy.exc.OperationalError correctly

Files changed

  • app/middleware/idempotency.py
  • app/main.py

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