diff --git a/app/config.py b/app/config.py index 92387c6..0d6ebb0 100644 --- a/app/config.py +++ b/app/config.py @@ -25,8 +25,10 @@ class Settings(BaseSettings): DB_PASS: str = Field('', env='AE_DB_PASSWORD') # Connection tuning - DB_CONNECT_TIMEOUT: int = Field(20, env='AE_DB_CONNECTION_TIMEOUT') - DB_POOL_RECYCLE: int = Field(1800, env='AE_DB_POOL_RECYCLE') + DB_CONNECT_TIMEOUT: int = Field(20, env='AE_DB_CONNECTION_TIMEOUT') + DB_POOL_RECYCLE: int = Field(1800, env='AE_DB_POOL_RECYCLE') + DB_POOL_SIZE: int = Field(10, env='AE_DB_POOL_SIZE') + DB_POOL_MAX_OVERFLOW: int = Field(20, env='AE_DB_POOL_MAX_OVERFLOW') # --- Logging --- LOG_PATH_APP: str = Field('/logs/aether_api.log', env='AE_API_LOG_PATH') @@ -73,8 +75,10 @@ class Settings(BaseSettings): 'name': self.DB_NAME, 'username': self.DB_USER, 'password': self.DB_PASS, - 'connect_timeout': self.DB_CONNECT_TIMEOUT, - 'pool_recycle': self.DB_POOL_RECYCLE, + 'connect_timeout': self.DB_CONNECT_TIMEOUT, + 'pool_recycle': self.DB_POOL_RECYCLE, + 'pool_size': self.DB_POOL_SIZE, + 'max_overflow': self.DB_POOL_MAX_OVERFLOW, } @property diff --git a/documentation/TODO__Agents.md b/documentation/TODO__Agents.md index 57a8f7b..6ecb77a 100644 --- a/documentation/TODO__Agents.md +++ b/documentation/TODO__Agents.md @@ -19,7 +19,7 @@ - [x] **[P1] Fix retry mechanism in `sql_update` / `run_sql_select`** — On `OperationalError`, both call `sql_connect()` → `reconnect_db()` which calls `engine.dispose()`, nuking the entire connection pool mid-flight. Under concurrent requests this kills other in-flight connections. Fix: remove the `sql_connect()` retry call; SQLAlchemy's `pool_pre_ping=True` already handles stale connections — just open a fresh `engine.connect()` for the retry without disposing the pool. - [ ] **[P2] Add retry logic to `sql_insert` and `sql_select`** — Both are missing the `OperationalError` retry that `sql_update` and `run_sql_select` have. A DB blip during an INSERT (scan record, badge log, etc.) fails silently and returns `False` with no recovery attempt. - [ ] **[P3] Guard `db = engine.connect()` in `lib_sql_core.py` with try/except** — Line 48 is a bare connect at module load time with no error handling. If MariaDB isn't ready (Docker race), this throws unhandled and crashes the worker. Wrap in try/except like `db_connection.py` already does. -- [ ] **[P4] Expose `pool_size` / `max_overflow` as env vars** — `create_ae_engine()` calls `settings.DB.get('pool_size', 10)` but `settings.DB` property doesn't include those keys, so they're always hardcoded 10/20. Add `AE_DB_POOL_SIZE` / `AE_DB_POOL_MAX_OVERFLOW` to `config.py`. +- [x] **[P4] Expose `pool_size` / `max_overflow` as env vars** — `create_ae_engine()` calls `settings.DB.get('pool_size', 10)` but `settings.DB` property doesn't include those keys, so they're always hardcoded 10/20. Add `AE_DB_POOL_SIZE` / `AE_DB_POOL_MAX_OVERFLOW` to `config.py`. ## 📋 Feature Tasks - [x] **Core Isolation:** Harden `apply_forced_account_filter` to Fail-Closed.