SEP-1843: The first request or Celery task after a database restart fails on a stale pooled connection - #1378
SEP-1843: The first request or Celery task after a database restart fails on a stale pooled connection#1378peter-o-addo wants to merge 12 commits into
Conversation
1. Default pre-ping on all four enginesInspected Result Pass: all four engines report 2. Opt-outBuilt a Result Pass: 3. Database restart (core fix)Against a Docker Postgres instance, warmed a pooled connection, restarted the database, then checked out twice with pre-ping on and once as a control with it off. Result Pass: with pre-ping, the first checkout after restart succeeds. Without it, the first fails and the second recovers — the original bug. |
There was a problem hiding this comment.
Pull request overview
Enables SQLAlchemy pool pre-ping by default for API and Celery database engines, replacing stale pooled connections after database restarts.
Changes:
- Adds configurable pre-ping defaults and engine forwarding.
- Adds unit coverage for defaults, opt-out, and NullPool behavior.
- Documents the configuration and reliability change.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
app/core/db/config.py |
Adds API database pre-ping configuration. |
app/core/db/utils.py |
Updates engine-factory documentation. |
app/core/celery/config.py |
Adds Celery engine pre-ping configuration. |
tests/app/core/db/test_config.py |
Tests database option serialization. |
tests/app/core/db/test_utils.py |
Tests async engine pre-ping wiring. |
tests/app/core/celery/test_config.py |
Tests Celery configuration behavior. |
tests/app/core/celery/test_db.py |
Tests worker engine forwarding. |
tests/app/core/celery/test_beat_engine_pool.py |
Tests scheduler pool paths. |
changelog.d/SEP-1843.fixed.md |
Records the stale-connection fix. |
changelog.d/SEP-1843.config.md |
Documents the new configuration keys. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Summary
Enable pool pre-ping by default so stale connections after a database restart are replaced on checkout instead of failing the first request or Celery task.
app/core/db/config.py,app/core/celery/config.py: addPOOL_PRE_PING/pool_pre_pingdefaulting toTrueand always emit it into engine kwargs (API pools and Celery worker).app/core/db/utils.py: updatecreate_app_async_enginedocstring to match the always-forwarded key.changelog.d/SEP-1843.fixed.md,changelog.d/SEP-1843.config.md: record the fix and the new config keys.tests/app/core/db/…,tests/app/core/celery/…: update exact-dict assertions and cover default-on, opt-out, and NullPool strip behaviour.Tested
_pre_ping=Trueby default with sizing keys omitted when unset.POOL_PRE_PING=Falseemitspool_pre_ping: Falseso an operator can restore the previous checkout behaviour.Checklist
make test)make run-pre-commit)make makemigrations)changelog.d/if the change is user-facing (make changelog-add), or confirmed N/A (internal-only change, or a same-release-cycle fix for an unreleased sibling ticket)