From 1ec525599bfd23f15c9322d01fa4b028c3508f4c Mon Sep 17 00:00:00 2001 From: CoreRasurae Date: Thu, 12 Mar 2026 12:33:10 +0000 Subject: [PATCH] fix(test): skip redundant Alembic migration check for existing test databases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a test database already exists and is non-empty (created by a prior step like `I have initialized a project`), _fast_init_or_upgrade in features/environment.py was falling through to _original_init_or_upgrade, running a full Alembic migration version check every time. This created redundant SQLAlchemy engines, caused SQLite lock contention under parallel execution, and triggered cumulative overhead from @database_retry decorators (wait_fixed(0.5) × 3 attempts on ~100 repository methods), leading to intermittent hangs and CI timeouts. The fix changes the existing-non-empty-database branch to return immediately instead of delegating to the original migration runner. This is safe because test databases are either template-copied (already at Alembic HEAD) or created by a prior step that already ran the full migration. The _SCENARIO_DB_PREFIXES guard ensures non-scenario databases (migration-runner unit tests) remain unaffected. Verified: 15/15 scenarios pass with both --processes 1 and --processes 16. ISSUES CLOSED: #726 --- features/environment.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/features/environment.py b/features/environment.py index 7d06891c7..b65b880c3 100644 --- a/features/environment.py +++ b/features/environment.py @@ -213,8 +213,13 @@ def _install_template_db_patch() -> None: # Only copy template for databases that don't exist yet or are empty # (SQLite auto-creates a 0-byte file on first engine open). + # If the DB already exists and is non-empty, it was either copied from + # the template or created by a prior step — either way it is already + # fully migrated. Skipping the Alembic check avoids redundant engine + # creation, SQLite lock contention, and the cumulative overhead that + # causes intermittent hangs in parallel test runs. if db_path.exists() and db_path.stat().st_size > 0: - return _original_init_or_upgrade(self, **kwargs) + return # Copy the template — creates a fully-migrated DB in ~1ms db_path.parent.mkdir(parents=True, exist_ok=True) -- 2.52.0