Repository navigation
fix(tests): fail loudly on a starved pytest basetemp instead of ENOSPC - #3449
Conversation
Problem: /tmp on the workstation is a 6 GiB tmpfs, and under ~8 concurrent agent lanes it filled to 100% (3.8 GiB in /tmp/polylogue-pytest). Nothing checked free space before committing to a basetemp location, so the failure surfaced three layers away as a bare `OSError: [Errno 28]` from an unrelated command (`devtools/pages_builder.py` writing a rendered doc page), which then cascaded through `devtools verify --quick` and the pre-push hook. Root cause: `.claude/settings.json` pins `POLYLOGUE_PYTEST_BASETEMP_ROOT=/tmp/polylogue-pytest` for cloud sandboxes, but that setting is not scoped away from workstation agent shells; `devtools.verify_runs` already stripped the known cloud sentinel before subprocess env prep, but `tests/conftest.py` had its own, independent basetemp-selection logic that never applied that strip and never checked free space at all — two placement policies that could silently disagree, exactly as CLAUDE.md's stale "/realm/tmp, not /dev/shm" claim disagreed with the code's actual (and correct) tmpfs-first default. What changed: - `devtools/verify_runs.py`: added `resolve_pytest_basetemp_root()`, the one placement policy (tmpfs -> NVMe scratch -> cloud-only disk fallback), headroom-checked at every candidate against a configurable requirement (`POLYLOGUE_PYTEST_BASETEMP_MIN_FREE_MB`, default 1 GiB), refusing with a `PytestResourceError` naming every candidate and its free space when nothing fits. Wired into `apply_managed_pytest_runtime_policy()` so `devtools test`/`devtools verify` refuse before spawning pytest at all. - `tests/conftest.py`: delegates basetemp placement to the shared resolver (removing the second, drifted implementation) and converts a refusal into a clean `pytest.UsageError` at `pytest_configure` time. The stale-basetemp sweep now sweeps every known root (not just the currently-chosen one) and never deletes a basetemp whose owning process is confirmed alive (a new `.owner-pid` marker) — age alone was not a safe liveness proxy for a long-running scale/lab test, and an unconfirmable owner gets a multi-hour grace period instead of the normal ~30-minute one. - `devtools/pages_builder.py`: wraps the page-output filesystem writes (`write_text`, output-dir/page-dir `mkdir`) with the failing page path and a "check free space" hint, so a future ENOSPC (from any cause) names its surface instead of a bare traceback. - `CLAUDE.md`/`TESTING.md`: documented the single resolution order and the override env var, replacing the doc/actual mismatch. Verification: - `devtools test tests/unit/test_pytest_temp_policy.py tests/unit/devtools/test_verify.py tests/unit/devtools/test_run_tests.py tests/unit/site/test_renderer_behavior.py` -> 129 passed. - Demonstrated the low-space refusal against a real filesystem: mounted a 50 MiB tmpfs, pointed `POLYLOGUE_PYTEST_BASETEMP_ROOT` at it, and both `devtools test` and a raw `pytest` invocation refused instantly (0.0s) with `no pytest basetemp location has enough free space ... 50 MiB free, need >= 1024 MiB` instead of proceeding. - `devtools verify --quick` -> exit 0 (18 static/generated gates). - Confirmed 3 unrelated pre-existing failures (`test_pytest_supervisor.py` process-kill-timing tests, and 13 unrelated failures under `tests/unit/core`) reproduce identically against unmodified `origin/master` in a throwaway worktree under the same host load, so they are not regressions from this change. - Not run: the full suite (explicitly out of scope per host-load constraints) and `devtools verify --all`. Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 10 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…kout (#3475) ## Summary A shared linked-worktree venv can silently resolve `import polylogue` to a *different* checkout than the one invoking it. This PR adds a structural guard that refuses (loudly, naming both paths) instead of running, wires it into every entry point that can plausibly hit the hazard, and prints the resolved package path as part of `devtools verify`/`devtools test` receipts. ## Problem A linked git worktree without its own `.venv` reuses the main checkout's shared venv on PATH. That venv's editable install (a `.pth` in site-packages) points at the main checkout, so a plain `import polylogue` with nothing else on `sys.path` silently resolves there instead of the worktree's own source — no `ImportError`, just wrong code answering every question while looking exactly like a genuine result. This corrupted four separate lanes in one day (2026-07-30/31): 1. A performance lane's entire "after" measurement set measured `master` instead of its own branch; caught mid-session, had to retract and redo. 2. Another lane got false "still timing out" CLI readings, resolved only by pinning `sys.path` explicitly. 3. `devtools lab policy schema-versioning` reported an impossible contradiction — comparing the MAIN checkout's `INDEX_SCHEMA_VERSION` against the WORKTREE's delta declarations. 4. A benchmark run needed per-run `module.__file__` printing as a manual guard. Reproduced directly: a standalone script run via `python3 /realm/tmp/x.py` from inside a worktree resolves `polylogue.__file__` to the main checkout, even with the worktree as `cwd`, because the script's own directory (not `cwd`) becomes `sys.path[0]` and nothing else on the path favors the worktree over the shared venv's editable `.pth`. ## Solution `devtools/checkout_guard.py` is a single shared resolver (same shape as `devtools.verify_runs.resolve_pytest_basetemp_root`, which PR #3449 used to fix a structurally identical two-implementations-disagreeing bug): it asserts `polylogue.__file__` resolves inside a given checkout root, and raises `CheckoutImportMismatchError` naming both paths plus remediation otherwise. Wired into every entry point that can plausibly hit the hazard: - `devtools/click_dispatch.py:main()` — the CLI entry point refuses (exit 125) before dispatching any command. - `devtools/verify.py:main()` / `devtools/run_tests.py:main()` — refuse before running any step, and print the resolved `polylogue` path as part of the run receipt (new `VerifyRun.polylogue_import_path` field, surfaced in `.cache/verify/current-run.json`). - `tests/conftest.py:pytest_configure` — refuses via `pytest.UsageError`, so even a bare `pytest`/`python -m pytest` invocation that skips `devtools` entirely still catches it (`tests/conftest.py` is always collected for any pytest run rooted at this repo). **Environmental layer, costed honestly**: the flake devShell already gives every checkout its own `.venv` (`uv venv` + `uv sync`, keyed off `$PWD`) via `direnv allow` — that's the fully correct fix and is already correct-by-construction per worktree. Its cost is a multi-minute sync plus a few hundred MB of disk per worktree, which is presumably why short-lived agent worktrees reuse the shared venv instead of paying that cost per spin-up. Changing that bootstrap behavior is outside this repo (it's harness/operator infra, not `polylogue` code), so this PR does not attempt it; the tradeoff is documented in CLAUDE.md instead. **Residual gap**: a standalone ad hoc script that never imports `devtools` or `pytest` has no hook to run the check from. Documented in CLAUDE.md; such a script can call `devtools.checkout_guard.assert_polylogue_matches_checkout` itself in one line for the same guarantee. CLAUDE.md's Gotchas section is updated with the hazard writeup, what's now guarded, and the residual gap — the guard is the fix, the doc explains it. ## Verification - `devtools verify --quick` — all 18 steps green, including `lab policy schema-versioning` (the exact check that produced an "impossible" contradiction in the incident), now printing `verify: polylogue package → .../worktrees/.../polylogue/__init__.py`. - `devtools test tests/unit/devtools/test_checkout_guard.py` — 7/7 passed: match case, mismatch case (both paths named in the message), a sibling-directory near-miss (guards against a weaker string-prefix regression of the `Path.relative_to` check), and each of the three wired entry points refusing with exit 125 on a monkeypatched mismatch. - `devtools test tests/unit/devtools/test_run_tests.py tests/unit/devtools/test_devtools_main.py tests/unit/devtools/test_cli_wrapper.py` — 26/26 passed, no regressions in the wired entry points' existing tests. - **Manual demonstration of a genuine refusal**: loaded `devtools/checkout_guard.py` by file path with no worktree entry on `sys.path` (reproducing the real hazard against the shared venv's ambient main-checkout resolution) and confirmed `CheckoutImportMismatchError` fires, naming both the worktree checkout and the resolved main-checkout package path, with the remediation text. - `ruff format --check` / `ruff check` / `mypy --strict` — clean on all touched files. - `devtools render topology-projection` — regenerated `docs/plans/topology-target.yaml` for the new `devtools/checkout_guard.py` module; `devtools render all --check` reports no drift. **Not run**: the full test suite (per-PR CI skips it). A directory-wide `devtools test tests/unit/devtools/` sweep (run once, against the repo's own anti-pattern guidance, to sanity-check breadth) surfaced 5 pre-existing failures in `test_lineage_validation.py`, `test_render_quality_reference.py`, and `test_verify_demo_tour_freshness.py` — none in files this change touches, reproducing identically at `-n 0` (not an xdist artifact), unrelated to the import-guard change. Co-authored-by: Claude <[email protected]>
Summary
Pytest temp-file placement now goes through one shared, headroom-checked
policy instead of two independent (and drifted) implementations, and refuses
loudly before pytest starts when nothing has enough free space — instead of
letting an unrelated command crash later with a bare
OSError: [Errno 28].Problem
/tmpon the workstation is a 6 GiB tmpfs. Under ~8 concurrent agent lanes itfilled to 100% (3.8 GiB in
/tmp/polylogue-pytest). Nothing checked freespace before committing to a basetemp location, so the visible symptom was
not a test failure — it was
devtools/pages_builder.pycrashing onout_path.write_text(html)withErrno 28, which then faileddevtools verify --quick, which then blocked the pre-push hook. Hours werelost diagnosing this as a code problem.
Root cause:
.claude/settings.jsonsetsPOLYLOGUE_PYTEST_BASETEMP_ROOT=/tmp/polylogue-pytestfor cloud sandboxes,but that env leaks into workstation agent shells too (the file has no
cloud/workstation scoping).
devtools/verify_runs.pyalready stripped thatknown cloud sentinel before preparing a pytest subprocess's env — but
tests/conftest.pyhad its own, independent basetemp-selection function thatnever applied that strip and never checked free space at all. Two placement
policies, silently disagreeing — and CLAUDE.md's stale "defaults to
/realm/tmp/polylogue-pytest, not/dev/shm" claim disagreed with thecode's actual (and correct) tmpfs-first default too.
Solution
devtools/verify_runs.py: newresolve_pytest_basetemp_root()is thesingle placement policy — configured override (still headroom-checked) →
/dev/shmtmpfs →/realm/tmp/polylogue-pytestNVMe scratch →/tmp/polylogue-pytestonly when/realm/tmpgenuinely isn't mounted(real cloud sandbox). Every candidate is checked against
POLYLOGUE_PYTEST_BASETEMP_MIN_FREE_MB(default 1024 MiB); if nothingfits, raises
PytestResourceErrornaming every candidate and its freespace. Wired into
apply_managed_pytest_runtime_policy(), sodevtools test/devtools verifyrefuse before ever spawning pytest.tests/conftest.py: delegates entirely to the shared resolver(deleting the second, drifted implementation) and converts a refusal into
a clean
pytest.UsageErrorinpytest_configure. The stale-basetempsweep now sweeps every known root (not just the one this run picked) and
adds a safety invariant the old age-only sweep lacked: each managed
basetemp now carries a
.owner-pidmarker, and a directory whose ownerprocess is confirmed alive is never deleted regardless of age (age alone
was not a safe liveness proxy — a long-running scale/lab test can outlive
the stale-age threshold); an owner that can't be confirmed dead gets a
6-hour grace period instead of the normal ~30-minute one.
devtools/pages_builder.py: wraps the page-output filesystem writes(
write_text, output/page directorymkdir) with the failing page pathand a "check free space" hint, so a future ENOSPC (from any cause) names
its surface instead of a bare traceback three frames deep.
CLAUDE.md/TESTING.md: document the single resolution order and theoverride env var, replacing the stale claim.
Verification
devtools test tests/unit/test_pytest_temp_policy.py tests/unit/devtools/test_verify.py tests/unit/devtools/test_run_tests.py tests/unit/site/test_renderer_behavior.py→ 129 passed.mocked probe): mounted a 50 MiB tmpfs, pointed
POLYLOGUE_PYTEST_BASETEMP_ROOTat it, and both
devtools testand a rawpytestinvocation refusedinstantly (0.0s) with:
devtools verify --quick→ exit 0 (18 static/generated gates), bothlocally and again at push time via the pre-push hook.
test_pytest_supervisor.pyprocess-kill-timingfailures and 13 unrelated
tests/unit/corefailures reproduce identicallyagainst unmodified
origin/masterin a throwaway worktree under the samehost load — not regressions from this change (worktree removed after
comparison).
constraints) and
devtools verify --all.🤖 Generated with Claude Code