Orchestrata Ultimate › Gates › worktree-envs

Gate: worktree-envs

At a glance

Purpose Refuse a non-primary worktree whose .venv is a symlink into another checkout's virtualenv (the battery check); the standalone script checks three more conditions.
Where it runs The scripts/gates.py battery (registered as worktree-envs, root !always, never cached); scripts/health_check.py.
Trigger Every battery run; a health check.
Exact command Battery: python scripts/check_worktree_envs.py --checks venv-symlink. Standalone: python scripts/check_worktree_envs.py [--fix-wheels] [--json] [--repo-root PATH].
Blocks Exit 1 on any violation; exit 0 clean, or SKIP with a printed reason when the directory is not a git repository or has no worktrees.
Ruling / ADR RUL-021 — a worktree owns its env. No ADR names this gate.
Last recorded verdict ok: true in the primary checkout's .cache/gates.json (file last written 2026-09-22 10:01 local; the entry is written even though the gate is never reused from the cache). wt-MAP-PRECOMMIT has no .cache/gates.json.

What it refuses

In the battery: a non-primary worktree whose .venv is a symlink into another checkout's virtualenv — the one failure mode that poisons every other checkout too. The standalone script checks more (below).

Why it exists

Module docstring, quoting the ruling verbatim and the incident:

"Worktree-environment gate — RUL-021 ('every damn feature branch gets a full env until we merge then it gets deleted', verbatim, 2026-07-27).

See ~/workspace/knowledge-wiki/rulings/RUL-021-worktree-owns-its-env.md for the ruling text and the incident (wt-QWEN's .venv was a symlink to the main checkout's virtualenv, and its vendor/wheels/ was empty, so the relative [tool.uv.sources] grpcio pin resolved to nothing and uv fell back to a from-sdist build — one that re-enables the GIL process-wide on import, a SPEC-023 violation, in a virtualenv every other checkout used)."

Why it entered the battery at all (gates.py registry comment): "The detector existed but was wired into NOTHING, which is how the incident escaped: a gate nobody runs is not a gate."

How it runs

Typical failures and how to fix them

Wiring