Skip to content

fix(pause): make protocol pause Redis-backed and constant-time - #431

Open
tolulopedd26 wants to merge 2 commits into
Quantarq:mainfrom
tolulopedd26:fix/redis-backed-protocol-pause
Open

fix(pause): make protocol pause Redis-backed and constant-time#431
tolulopedd26 wants to merge 2 commits into
Quantarq:mainfrom
tolulopedd26:fix/redis-backed-protocol-pause

Conversation

@tolulopedd26

Copy link
Copy Markdown
Contributor

Description

Replace the in-process PauseController with a Redis-backed implementation that propagates pause state to all workers and survives restarts. Fix admin token comparison to use constant-time hmac.compare_digest.

Related Issue

Closes #416

Change Type

  • fix — bug fix
  • test — adding or updating tests

Testing Done

  • Pause/unpause state persisted in Redis key protocol:paused
  • Fail-closed on Redis outage (defaults to paused for incident safety)
  • 5s in-memory cache avoids Redis round-trip on every request
  • Constant-time token comparison via hmac.compare_digest
  • 23 tests covering Redis state, cache, fail-closed, exempt paths

Screenshots (if UI changes)

None

Environment Variables

None (uses existing REDIS_URL)

Checklist

  • make lint passes (pylint on changed .py files)
  • make test passes (pytest in quantara/web_app/tests/)
  • CI is green on this PR
  • Documentation updated (if applicable)
  • PR is linked to a related issue (Closes #416)

- PauseController now uses redis.asyncio for cross-worker state
- Pause survives worker restarts (Redis key protocol:paused)
- Fail-closed: defaults to paused on Redis outage for safety
- 5s in-memory cache to avoid Redis round-trip on every request
- verify_admin_token uses hmac.compare_digest for constant-time comparison
- Router endpoints use APIError envelope
- 23 tests covering Redis state, cache, fail-closed, exempt paths

Closes Quantarq#416

@github-advanced-security github-advanced-security AI 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.

Bandit found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.


from __future__ import annotations

import asyncio
from web_app.api.main import app
from web_app.api.pausable import pause_controller
from web_app.db.database import get_database
import asyncio
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.

Protocol pause switch is in-process: pausing one worker leaves others live

3 participants