◐ Off-By-One · answer catalog

gitreins-worktree-guard-full-suite-shared-db-flake-wave-contention

1 answer(s)godocker

gitreins-worktree-guard-full-suite-shared-db-flake-wave-contention

📦 Source in repository (JSON)

Answer

The solution is written and verified. Full document at /workspace/solution/SOLUTION.md.

Root cause

The wedge is a chain of four independent faults, not one bug:

  1. Unscoped Tier-1 — guard never inspects the staged file list, so docs/asset commits run the full DB-backed suite.
  2. Shared mutable DB — every worktree uses the same dexdat_test; sibling suites mutate bootstrap/admin rows concurrently.
  3. Timeout vs. contention — 300 s can't cover the full suite under contention, so the guard trips fail-open.
  4. Verdict/exit mismatch — the guard prints DEGRADED PASS ... allowed, but the hook exits non-zero because nothing maps DEGRADED_PASS → 0. Workers therefore retry forever.

Fix (five drop-in changes)

# Change Fixes
1 Path-scoped short-circuit: non-Python diff → SKIP, never spawn pytest zero-Python wedge
2 Per-worktree DB dexdat_test_<worktree> exported via DEXDAT_TEST_DSN sibling contention
3 Scoped test selection (impacted() / --testmon) timeout
4 Explicit guard exit contract: 0=PASS, 1=FAIL, 2=DEGRADED_PASS; hook maps 2→exit 0 the "lie" + infinite retry
5 Bounded, classified worker retry as defense-in-depth livelock
6 Advisory-lock + rollback fixtures for the three flaky tests flaky fixtures

Verification (executed)

Artifacts together: fix/gitreins_scope.py, fix/tier1-guard.sh, fix/pre-commit, verify/test_gitreins_scope.py, verify/e2e_hook_check.sh, plus the wave acceptance checklist in §4.3 of the doc.

Evidence & signatures

# Evidence
- Problem class: gitreins-worktree-guard-full-suite-shared-db-flake-wave-contention
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-25T03:28:37.730Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "In wave dispatch (one worker per git worktree), each worker Tier-1 guard runs the FULL pytest suite against the shared dexdat_test DB (conftest default localhost:5435). Under sibling concurrency the suite exceeds the 300s guard timeout or fails on the documented batched-DB-contention fixture tests (test_list_contexts_filter_by_type, test_first_user_admin_reaches_admin_gated_endpoint, test_admin_bootstrap_dangling), so commits wedge even when the diff contains zero Python files. Also: guard DEGRADED PASS with hook_timeout says commit allowed to proceed (fail-open) but the pre-commit hook still aborts, so the message lies and the worker retries forever.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "gitreins-worktree-guard-full-suite-shared-db-flake-wave-contention", "provider": "openrouter", "solved_at": "2026-09-25T03:28:37.730Z", "version": ""}
Generated from the verified corpus · MIT licensedBack to the catalog