Stage 12 runs exhaust the database session pooler's 15-client limit
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
Research direction
Start at create_stage12_engine, which sets SQLAlchemy's QueuePool with pool_size=5 and max_overflow=5, and at runtime_store(), which builds a new engine per coordinator and worker call. Pull request #789 is already open against this work, so read it and its diff before starting anything. Done means a connection is held only for each short operation, refused connections are retried with bounded backoff, and a failed failure-record write no longer replaces the original error.
Written by the indexing model from the issue text.
Description
Problem
Stage 12 coordinators and workers run out of database sessions. From 6 to 13 October 2026, 106 of the 153 production Stage 12 failures recorded:
FATAL: (EMAXCONNSESSION) max clients reached in session mode - max clients are limited to pool_size: 15
These were 100 US nationwide, 5 UK nationwide and 1 US state report. In 66 of them the coordinator failed at its initial claim, before any simulation started.
When the database is full, the failure handler's own write can also fail. The original error is then lost, and the comparison or simulation record stays running.
Cause
create_stage12_engineused SQLAlchemy's defaultQueuePoolwithpool_size=5andmax_overflow=5.runtime_store()builds a new engine for every coordinator and worker invocation.- A connection returned to
QueuePoolkeeps its physical session open. Each process therefore holds a pooler session while it calculates or waits, for up to 50 minutes. pool_recycle=300doesn't help, because recycling is only checked when a connection is checked out.- The coordinator and both country workers each allow 10 containers. Up to 30 processes can therefore each hold a session against a limit of 15.
Expected
- A database session is held only for each short operation.
- A connection refused before any statement is sent is retried, with a bounded backoff.
- A failure to write the failure record never replaces the original error.
Follow-ups (not in scope)
- Mark comparison and simulation rows that stay
runningpast the coordinator's 4,500 s timeout as failed. This needs a scheduled function. It would readSTAGE12_DATABASE_URL, which comes from Google Secret Manager and reaches Modal through thestage12-evaluation-runtimesecret. No workflow currently runs.github/scripts/stage12-sync-modal-secrets.sh, so how that Modal secret is populated is unconfirmed. - Consider the transaction-mode pooler if concurrent database operations still approach 15 after this change.
- Dominant language
- Python
- Stars
- 1
- Forks
- 1
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 40
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PolicyEngine/policyengine-sim-api
-
Integration tests fail due to missing UV virtual environment setupPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
PolicyEngine/policyengine-sim-api#314 ·
Maintainers usually reply within 1 day
-
Update policyengine to 6.4.3Possibly taken @policyengine claimed this today. Open
Difficulty 1/5 1-3 hours Newbie friendliness 35/100
PolicyEngine/policyengine-sim-api#812 ·
Maintainers usually reply within 1 day
-
Update policyengine to 6.4.2Possibly taken @policyengine claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 40/100
PolicyEngine/policyengine-sim-api#810 ·
Maintainers usually reply within 1 day
-
Register weighted-microdata rules: weights aren't valuesPossibly taken @anth-volk claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 30/100
PolicyEngine/policyengine-sim-api#806 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
PolicyEngine/policyengine-sim-api#805 ·
Maintainers usually reply within 1 day
All issues in PolicyEngine/policyengine-sim-api
Similar issues
-
Path subtraction removes repeated suffix characters instead of one suffixPossibly taken @Gwerdonatus claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
joke2k/django-environ#671 ·
-
good first issue help wanted windows
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
-
test_pgbouncer deploys the server under test from Charmhub instead of the local build (track/1.31)Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
canonical/temporal-k8s-operator#195 · 1 comment ·
Maintainers usually reply within 4 days
-
`burr` fails to start when the Python path has a space in itPossibly taken @enekoreto claimed this today. Openstatus/needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 5 days
-
device support request
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
zigpy/zha-device-handlers#5461 ·
Maintainers usually reply within 4 days