Skip to content

fix(devtools): give each test run its own basetemp and say why nothing collected - #4343

Merged
Sinity merged 1 commit into
masterfrom
fix/test-empty-selection-diagnosis
Aug 27, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/test-empty-selection-diagnosis

Conversation

@Sinity

@Sinity Sinity commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes a regression from #4333 plus the diagnosis gap that has repeatedly misled integration.

Problem

Colliding basetemp. #4333 pointed --basetemp at a fixed path. pytest creates that directory itself and fails when it exists, so two runs in one checkout collide:

INTERNALERROR> FileExistsError: [Errno 17] File exists: '.cache/verify/tmp'

Lanes, batches and the coordinator all run concurrently in the same checkout here, so this fires routinely — and an INTERNALERROR mid-run is a plausible source of the empty collections that were being written off as flakes.

Cleanup that silently failed. Tests seal archive generations read-only, so rmtree(ignore_errors=True) could not unlink them and left the tree behind — exactly the accumulation #4333 set out to stop.

Indistinguishable exit 5. pytest exits 5 both when a selection genuinely matches nothing and when a path in it does not exist. A selection derived from git diff --name-only contains files the branch deleted, so the run collects nothing and reads as "no work to do". That has already produced false conclusions during integration, including a report that multi-path selections were broken.

Solution

The basetemp is unique per invocation. Cleanup clears permissions before removing. On exit 5 the runner names the absent paths, or states that every path existed so the caller looks at the -k/-m expression or contention instead.

Verification

devtools verify --quick → exit 0.
devtools test tests/unit/devtools/test_run_tests.py → exit 0.
A selection naming a deleted file prints collected nothing because these paths do not exist: tests/unit/gone.py.
Repeated green runs leave no .cache/verify/tmp-* behind; a failed run keeps its own for inspection.

Residual risk

A failed collection still keeps an empty temp directory, which is litter rather than a leak. Callers deriving selections from a diff should still filter to files that exist — this makes the failure legible rather than preventing it.

🤖 Generated with Claude Code

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

…g collected

#4333 pointed --basetemp at a fixed path. pytest creates that directory itself
and fails if it exists, so two runs in one checkout collide:

  INTERNALERROR> FileExistsError: '.cache/verify/tmp'

Lanes, batches and the coordinator all run in the same checkout concurrently
here, so this fires routinely, and an INTERNALERROR mid-run is a plausible
source of the empty collections that were being read as flakes. The basetemp
is now unique per invocation.

Its cleanup also could not remove the read-only trees tests seal for archive
generations, so it silently left them behind — the permissions are cleared
before the tree is removed.

Separately, pytest exits 5 both when a selection genuinely matches nothing and
when a path in it does not exist, and the two are indistinguishable to a
caller. A selection derived from `git diff --name-only` contains files the
branch deleted, so the whole run collects nothing and reads as "no work to
do"; that has already produced false conclusions during integration. The
runner now names the absent paths, or says every path existed.

Verification: `devtools verify --quick` → exit 0;
`devtools test tests/unit/devtools/test_run_tests.py` → exit 0;
a selection naming a deleted file now prints `collected nothing because these
paths do not exist: tests/unit/gone.py`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA
@Sinity
Sinity enabled auto-merge (squash) August 27, 2026 15:35
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 703cbe4b-83ed-4a6e-ad36-cb6e1514f310


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity merged commit 2d8f99a into master Aug 27, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the fix/test-empty-selection-diagnosis branch August 27, 2026 15:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 919704019c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread devtools/run_tests.py Resolved
Comment thread devtools/run_tests.py Resolved
Comment thread devtools/run_tests.py Resolved
Comment thread devtools/run_tests.py Resolved
Sinity added a commit that referenced this pull request Aug 27, 2026
…g collected (#4343)

## Summary
Fixes a regression from #4333 plus the diagnosis gap that has repeatedly
misled integration.

## Problem
**Colliding basetemp.** #4333 pointed `--basetemp` at a fixed path.
pytest creates that directory itself and fails when it exists, so two
runs in one checkout collide:

```
INTERNALERROR> FileExistsError: [Errno 17] File exists: '.cache/verify/tmp'
```

Lanes, batches and the coordinator all run concurrently in the same
checkout here, so this fires routinely — and an INTERNALERROR mid-run is
a plausible source of the empty collections that were being written off
as flakes.

**Cleanup that silently failed.** Tests seal archive generations
read-only, so `rmtree(ignore_errors=True)` could not unlink them and
left the tree behind — exactly the accumulation #4333 set out to stop.

**Indistinguishable exit 5.** pytest exits 5 both when a selection
genuinely matches nothing and when a path in it does not exist. A
selection derived from `git diff --name-only` contains files the branch
deleted, so the run collects nothing and reads as "no work to do". That
has already produced false conclusions during integration, including a
report that multi-path selections were broken.

## Solution
The basetemp is unique per invocation. Cleanup clears permissions before
removing. On exit 5 the runner names the absent paths, or states that
every path existed so the caller looks at the `-k`/`-m` expression or
contention instead.

## Verification
`devtools verify --quick` → exit 0.
`devtools test tests/unit/devtools/test_run_tests.py` → exit 0.
A selection naming a deleted file prints `collected nothing because
these paths do not exist: tests/unit/gone.py`.
Repeated green runs leave no `.cache/verify/tmp-*` behind; a failed run
keeps its own for inspection.

## Residual risk
A failed collection still keeps an empty temp directory, which is litter
rather than a leak. Callers deriving selections from a diff should still
filter to files that exist — this makes the failure legible rather than
preventing it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 28, 2026
…g collected (#4343)

## Summary
Fixes a regression from #4333 plus the diagnosis gap that has repeatedly
misled integration.

## Problem
**Colliding basetemp.** #4333 pointed `--basetemp` at a fixed path.
pytest creates that directory itself and fails when it exists, so two
runs in one checkout collide:

```
INTERNALERROR> FileExistsError: [Errno 17] File exists: '.cache/verify/tmp'
```

Lanes, batches and the coordinator all run concurrently in the same
checkout here, so this fires routinely — and an INTERNALERROR mid-run is
a plausible source of the empty collections that were being written off
as flakes.

**Cleanup that silently failed.** Tests seal archive generations
read-only, so `rmtree(ignore_errors=True)` could not unlink them and
left the tree behind — exactly the accumulation #4333 set out to stop.

**Indistinguishable exit 5.** pytest exits 5 both when a selection
genuinely matches nothing and when a path in it does not exist. A
selection derived from `git diff --name-only` contains files the branch
deleted, so the run collects nothing and reads as "no work to do". That
has already produced false conclusions during integration, including a
report that multi-path selections were broken.

## Solution
The basetemp is unique per invocation. Cleanup clears permissions before
removing. On exit 5 the runner names the absent paths, or states that
every path existed so the caller looks at the `-k`/`-m` expression or
contention instead.

## Verification
`devtools verify --quick` → exit 0.
`devtools test tests/unit/devtools/test_run_tests.py` → exit 0.
A selection naming a deleted file prints `collected nothing because
these paths do not exist: tests/unit/gone.py`.
Repeated green runs leave no `.cache/verify/tmp-*` behind; a failed run
keeps its own for inspection.

## Residual risk
A failed collection still keeps an empty temp directory, which is litter
rather than a leak. Callers deriving selections from a diff should still
filter to files that exist — this makes the failure legible rather than
preventing it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 1, 2026
…g collected (#4343)

## Summary
Fixes a regression from #4333 plus the diagnosis gap that has repeatedly
misled integration.

## Problem
**Colliding basetemp.** #4333 pointed `--basetemp` at a fixed path.
pytest creates that directory itself and fails when it exists, so two
runs in one checkout collide:

```
INTERNALERROR> FileExistsError: [Errno 17] File exists: '.cache/verify/tmp'
```

Lanes, batches and the coordinator all run concurrently in the same
checkout here, so this fires routinely — and an INTERNALERROR mid-run is
a plausible source of the empty collections that were being written off
as flakes.

**Cleanup that silently failed.** Tests seal archive generations
read-only, so `rmtree(ignore_errors=True)` could not unlink them and
left the tree behind — exactly the accumulation #4333 set out to stop.

**Indistinguishable exit 5.** pytest exits 5 both when a selection
genuinely matches nothing and when a path in it does not exist. A
selection derived from `git diff --name-only` contains files the branch
deleted, so the run collects nothing and reads as "no work to do". That
has already produced false conclusions during integration, including a
report that multi-path selections were broken.

## Solution
The basetemp is unique per invocation. Cleanup clears permissions before
removing. On exit 5 the runner names the absent paths, or states that
every path existed so the caller looks at the `-k`/`-m` expression or
contention instead.

## Verification
`devtools verify --quick` → exit 0.
`devtools test tests/unit/devtools/test_run_tests.py` → exit 0.
A selection naming a deleted file prints `collected nothing because
these paths do not exist: tests/unit/gone.py`.
Repeated green runs leave no `.cache/verify/tmp-*` behind; a failed run
keeps its own for inspection.

## Residual risk
A failed collection still keeps an empty temp directory, which is litter
rather than a leak. Callers deriving selections from a diff should still
filter to files that exist — this makes the failure legible rather than
preventing it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 29, 2026
…#5802)

## Summary

Salvages ChatGPT fleet worker 15 (Codex review debt, beads
polylogue-1tyq5.45, .47, .48, .51, .52: devtools parts 4/6/7, docs,
nix). Of 79 findings: 13 fixed here, 56 already fixed on master, 4
stale, 6 not reached. The worker's patch was built on snapshot
`e1510b53ea`, not master. It was ported hunk by hunk onto current
master, keeping the newer OOM attribution and trusted-parent work in
`verify.py`, `verify_runs.py`, `run_tests.py` and `pytest_slot.py`.

## Problem

- `devtools test --outliers` globbed `last-pytest-*.json` shards. No
verifier writes these any more: each pytest step's report is rebound
into its run step directory, and only `last-pytest.json` is projected.
The command therefore read nothing or stale files (45.01, 45.02).
- A focused `devtools test` that got SIGTERM died in `subprocess.run`.
It wrote no terminal receipt, history or evidence (45.06).
- Queued slot interruptions dropped the start-time worktree provenance
(45.08).
- When a selected directory was missing, pytest exited 4 (usage error).
The missing-path diagnostic only ran on exit 5 (45.10).
- The focused verdict printed a checkout-relative receipt path. `main()`
has `chdir`ed to ROOT, so the path did not resolve from the caller's
directory (45.12).
- `canonical_verification_receipt` preferred `final_git_head`. It
attributed passing tests to a head that moved under the run and was
never executed (45.14).
- The verifier's interruption handlers did not cover selection,
admission or verdict assembly. A signal there left the run `running`
(47.03).
- A refused affected plan returned before any static gate ran (47.21).
- The Home Manager readiness lane required the removed role-ladder
expressions. It rejected the intact module and could not detect a
dropped capability switch (47.22).
- Pattern help and docs advertised `path:sha1[:count]`, but the parser
requires `path:sha1:context_sha1[:count]` (48.01). The SHA-1 anchors
used the security-default constructor (48.03).
- Reconciliation retried publication only for abandoned runs adopted as
failure. A run adopted as success whose first publication was
interrupted never reached history (48.20).

## Solution

- `print_outliers` selects every pytest lane of the newest completed
`--all` receipt (tier `all`, status `success`,
`complete_corpus_covered`). It refuses when a lane report is missing.
The shard glob, its constant and the verifier's `_clear_full_run_shards`
are removed.
- `devtools test` installs a SIGTERM handler around the launch. The
slot's own handler chains into it after it stops the child. The run
finishes with exit 143 and `termination_reason=sigterm`, and the prior
handler is restored.
- Both slot interruption writers pass the captured
`worktree_provenance`.
- The missing-path diagnostic runs on exit 4 and exit 5. The "every path
exists" hint stays exit-5 only.
- Receipt and artifact paths print absolute.
- `source_revision` is set only when the ending head equals the executed
head. It is also unset when the tree is unknown or dirty.
- `_main` runs selection, admission, steps and verdict assembly inside
the interruption handlers. Publication
(`_finish_and_record_verification`) stays outside so a signal cannot
finish a run twice. A refused plan now runs the quick gates through the
same path, keeps the first failing gate's exit and diagnosis, and
otherwise returns exit 2 with `affected_admission_refused`.
- The HM lane checks the three `cfg.mcpEnable*` mappings.
- The pattern gate hashes with `usedforsecurity=False`. The help,
catalog, regenerated `docs/devtools.md` and `docs/structured-logging.md`
name the context-anchor format.
- Reconciliation retries publication for abandoned runs adopted as
success too. The existing per-run dedup keeps it idempotent.

Diverges from the worker: its 47.03 change put publication inside the
handler. That could append a second history row for a run already
finished. Publication is kept outside, and crash-consistent publication
stays with 47.12 (not reached). Its 47.25 change is dropped because
master already rejects malformed registries more strictly.

## Verification

All through AgentCTL on the pushed head's tree or its immediate
predecessor:

- `agentctl job start polylogue verify_quick --workspace
/realm/worktrees/salvage-w15 --wait`: job 2319 on `75059a9ddc` (rebased
head): `verify: PASSED exit=0`.
- `agentctl job start polylogue pytest_focused --workspace
/realm/worktrees/salvage-w15 --wait --
tests/unit/devtools/test_verification_terminal_receipts.py
tests/unit/devtools/test_verify.py tests/unit/devtools/test_run_tests.py
tests/unit/devtools/test_verify_patterns.py
tests/unit/devtools/test_agent_integration_module.py
tests/unit/devtools/test_verify_runs.py
tests/unit/devtools/test_verification_evidence_lane.py
tests/unit/devtools/test_pytest_slot.py`: job 2300 on `4e72110e57`: `2
failed`, both inherited (see residuals); everything else passed.
- After the mypy typing commit: job 2312, `pytest_focused --
tests/unit/devtools/test_verification_terminal_receipts.py
tests/unit/devtools/test_verify_patterns.py
tests/unit/devtools/test_run_tests.py`: `devtools test: PASSED exit=0`.
- Red on master: job 2242 ran the new and changed tests in a detached
master worktree (`e14b47662d`) with production code unchanged. Every new
regression failed: 13 in `test_verification_terminal_receipts.py`, the
sha1 pattern test, the HM lane pass case, both
`test_affected_admission_refuses_without_launching_pytest` params and
the adapted outliers test. The `ending == executed head` canonical
parameter passed there as expected. The same job reproduced the two
inherited failures.
- Derived-identity closure: scratch job 2202 ran `python -m devtools
schema closure` on all 8 changed production files, and every one
reported `out`. The same job regenerated `docs/devtools.md` with
`devtools render devtools-reference`.

## Self-review

- **Sibling sites.** The artifacts line got the same absolute-path fix
as the receipt (45.12). `docs/structured-logging.md` carried the same
stale anchor spelling (48.01). Both slot interruption writers are fixed
(45.08). The verifier's shard clearing was the other half of the dead
shard protocol and is removed with the reader.
- **Cancellation and shutdown.** The focused SIGTERM handler is
installed after the temp-tree guard and restored in `finally`. The held
slot's handler restores it and re-signals, so the two chain. Verifier
publication is outside the handler, which avoids double finishing.
- **Unbounded reads.** The outliers reader globs `runs/*/run.json`,
which retention already bounds (8 successful runs).
- **Fail-open fallbacks.** Outliers refuse on a missing or malformed
lane rather than fall back to older reports. An unknown ending head
yields no `source_revision`.
- **Compatibility shims.** None. The shard constant and clearing are
deleted, not kept alongside.
- **Removed symbols.** `PYTEST_PARALLEL_REPORT_PATTERN` and
`_clear_full_run_shards` have no remaining references in code, tests or
docs.
- **Production route.** The tests drive `run_tests.main`, `verify.main`,
`pytest_slot._run_launch`, `reconcile_and_record_abandoned_verify_runs`,
`verify_patterns.main` and the real lane function. Only host
observations (Git, processes, signals) are replaced.

## Findings

| key | disposition | evidence | test |
|---|---|---|---|
| 45.01 #4162 run_tests.py:116 | fixed | shards unwritten since per-step
report binding (`verify._bind_pytest_reports_to_step`) |
test_verification_terminal_receipts.py::test_outliers_read_all_lanes_of_one_completed_receipt,
::test_outliers_refuse_a_missing_lane_instead_of_falling_back_to_older_reports
|
| 45.02 #4162 run_tests.py:116 | fixed (same change; worker had
fixed-already via shard clearing, which cleared names nobody writes) |
receipt-bound selection |
::test_outliers_read_all_lanes_of_one_completed_receipt |
| 45.06 #4267 run_tests.py:352 | fixed | no SIGTERM handling on master |
::test_focused_sigterm_finishes_receipt_and_publications |
| 45.08 #5544 run_tests.py:427 | fixed | `_write_interrupted_result`
lacked provenance |
::test_queued_interruption_keeps_start_time_worktree_provenance |
| 45.10 #4343 run_tests.py:485 | fixed | `if rc == 5` only |
::test_focused_missing_directory_has_a_path_specific_usage_diagnostic |
| 45.12 #4726 run_tests.py:626 | fixed | `run.relative_run_dir` printed
| ::test_focused_verdict_receipt_is_absolute_from_a_nested_invocation |
| 45.14 #5544 run_tests.py:649 | fixed | `final_git_head or git_head` |
::test_canonical_receipt_never_attributes_an_untested_ending_head |
| 47.03 #4109 verify.py:505 | fixed (publication kept outside; see
47.12) | selection/tail outside `try` |
::test_verifier_finalizes_interruptions_outside_the_step_loop |
| 47.21 #4898 verify.py:1019 | fixed | early `return 2` before
`build_verify_steps` |
::test_refused_affected_admission_still_executes_static_gates;
test_verify.py::test_affected_admission_refuses_without_launching_pytest
|
| 47.22 #4266 verify_agent_integration.py:472 | fixed | role-ladder
tokens absent from module |
test_agent_integration_module.py::test_home_manager_lane_checks_independent_capability_switches
|
| 47.25 #4161 verify_patterns.py:37 | fixed-already (worker claimed
fixed) | `_rules` raises on every malformed shape,
verify_patterns.py:36-63;
test_verify_patterns.py::test_malformed_pattern_registry_fails_closed |
none |
| 48.01 #4199 verify_patterns.py:59 | fixed | help said
`path:sha1[:count]` | generated reference refreshed |
| 48.03 #4199 verify_patterns.py:113 | fixed | default-security
`hashlib.sha1` |
test_verify_patterns.py::test_pattern_entrypoint_marks_sha1_as_non_security_use
|
| 48.20 #5299 verify_runs.py:1282 | fixed | retry branch matched `status
== "failed"` only |
::test_successful_abandoned_adoption_retries_an_interrupted_publication
|
| 45.22, 45.25, 47.12, 48.05, 48.06, 48.17 | not reached | still open;
need design (receipt-bound config, resumable GC, crash-consistent
publication, stale-baseline policy, located violations, unknown
duration) | none |
| 47.08, 47.10, 47.15, 47.20 | stale | code paths removed
(`--recompute`/`--commit`, bootstrap selection, parent-root refusal,
graph publication) | none |
| remaining 55 | fixed-already | worker's line evidence, spot-checked on
current master | none |

## Derived-identity closure

None. All 8 changed production files are outside the closure (`devtools
schema closure`, job 2202).

## Residuals

- These two failures reproduce on master `e14b47662d` (job 2242) and are
unrelated to this change:
-
`tests/unit/devtools/test_verification_evidence_lane.py::test_reconciled_abandoned_run_joins_the_durable_lane`:
the relocated-cache evidence target conflicts with the test's
durable-lane expectation.
-
`tests/unit/devtools/test_verify.py::test_zero_exit_without_a_report_is_a_failed_pytest_step`:
pytest-benchmark options are unrecognized in the free-threaded venv.
- A signal that arrives during publication itself still escapes. That is
47.12.
- Abandoned runs with no recorded ending head now publish no
`source_revision`. This is intended: the head was never observed at the
end.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_015pdKaZWyGe6Ngvsz468dzg

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 64a9bd0):

  • P1 devtools/run_tests.py:392: Fixed on master (checked at 64a9bd0): remove_temp_tree lstats each entry and chmods only real directories (stat.S_ISDIR on the lstat mode), so a symlink is never followed (devtools/pytest_slot.py:236-246).
  • P1 devtools/run_tests.py:439: Fixed on master (checked at 64a9bd0): Each focused run writes its JSON report inside its own run directory (devtools/run_tests.py:1314-1318), and the shared last-pytest copy is a convenience that is never read to decide a result (devtools/run_tests.py:1134-1145).

Resolving every thread listed; confirmed defects are fixed under the named bead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant