Skip to content

perf(verify): structured pytest reports and worker tuning evidence (#1026) - #1087

Merged
Sinity merged 3 commits into
masterfrom
feature/perf/verify-structured-reports
May 16, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/perf/verify-structured-reports

Conversation

@Sinity

@Sinity Sinity commented May 16, 2026

Copy link
Copy Markdown
Owner

Summary

Replace the verify pipeline's terminal-summary scraping with a structured pytest JSON report, raise the default xdist worker count from 8 to 16 after measurement, and fix a parallel-worktree basetemp collision that was producing 1000+ spurious test errors.

Problem

  • The verify step parsed pytest's stdout with regex (_parse_pytest_test_count) to extract counts. That blocked tracking: verifiability V7/V8 dashboard and traceability (resurrected from #806) #998 (verify dashboard) which needs structured fields, and was fragile against any change to pytest's terminal output.
  • The default xdist worker count (8) was unmeasured. The 13700K has 16 P-cores + 8 E-cores; n=8 was leaving half the P-cores idle.
  • Concurrent pytest runs from sibling worktrees collided on /dev/shm/pytest-polylogue. Pytest prunes old basetemps on startup, so one run would delete the other's xdist worker subdirectories mid-flight, raising FileNotFoundError: /dev/shm/pytest-polylogue/popen-gwN in pytest_asyncio setup. Observed 1121 errors in a single seed pass attributable to this.

Solution

  • pyproject.toml: add pytest-json-report>=1.5.0 to the dev extra.
  • devtools/verify.py: every pytest invocation now writes --json-report-file=.cache/verify/last-pytest.json. _run() reads the structured report and projects passed/failed/error/skipped/xfailed/xpassed/total plus pytest_duration_s into the step metadata stored in .cache/verify-history.jsonl. Terminal scraping remains as a fallback only when the report is missing (lab profile that strips plugins, or a pytest crash before the report is written). _clear_pytest_report() removes any stale report before each step so we never read someone else's data.
  • devtools/verify.py: default _pytest_worker_args(default=...) raised from 8 to 16, based on measurement of n=4/8/12/16/24 (winner: n=16 at 120s wall vs n=8 at 229s — see commit body).
  • tests/conftest.py: suffix the tmpfs basetemp and the seeded-corpus shared root with an 8-char hash of the worktree rootpath so concurrent worktrees do not collide.
  • tests/unit/devtools/test_verify.py: add test_pytest_step_requests_structured_json_report (every pytest variant must emit the report path), test_run_reads_structured_pytest_report (primary path), retain terminal-fallback test, and small unit tests around _read_pytest_report and _pytest_metadata_from_report.

Verification

$ nix develop -c pytest tests/unit/devtools/test_verify.py -v
============================== 28 passed in 9.12s ==============================

$ nix develop -c devtools verify --quick
... total_duration_s: 38.64, exit_code: 0

$ nix develop -c devtools verify --seed-testmon --skip-slow
... pytest seed-testmon  duration_s: 211.64
    report_path: .cache/verify/last-pytest.json
    count: 6704, passed: 6688, failed: 14, total: 6704
    pytest_duration_s: 202.89

The 14 failures are pre-existing on master@fc3c43f3 (proof-law completeness, scenario-projection mismatch, benchmark-campaign index drift, json-envelope contract). Confirmed by running the same set in the main checkout — all fail there too. Tracked as inherited baseline debt, not introduced by this PR.

Worker tuning evidence (i7-13700K, 16P+8E cores), each pass runs the same ~6700 unit tests:

-n wall notes
4 161s underutilized
8 229s previous default
12 172s coordination tax
16 120s winner — matches P-core
24 139s E-core oversubscription

Ref #1026
Ref #998

Sinity added 3 commits May 16, 2026 12:58
Replace fragile terminal-summary scraping with pytest-json-report.

The pytest step now writes .cache/verify/last-pytest.json with
summary counts and total duration. _run() reads that file to populate
step metadata, falling back to the existing regex only when the
report is missing (plugin disabled or pytest crash). The fallback
keeps lab profiles that strip plugins safe.

This unblocks the verify dashboard work in #998 and gives the verify
history a stable structured record rather than text parsing.

Ref #1026 Ref #998
When two pytest runs from different worktrees ran concurrently they
shared /dev/shm/pytest-polylogue as basetemp. Pytest prunes old
basetemp directories on startup, so the second run would delete the
first run's xdist worker subdirectories (popen-gw0, popen-gw1, ...)
mid-flight. Affected tests raised
`FileNotFoundError: /dev/shm/pytest-polylogue/popen-gwN`
in pytest_asyncio setup with 1000+ tests erroring per run.

Suffix the basetemp and the seeded-corpus shared root with a short
hash of the worktree path so each checkout gets its own tmpfs root.
Confirmed local seed pass dropped from 1121 errors to 0 errors
after the change.

Ref #1026
Measured wall-clock for the seed pytest pass at n=4/8/12/16/24 on the
13700K (16P+8E):

|  -n | wall  | notes                  |
|-----|-------|------------------------|
|   4 | 161s  | underutilized          |
|   8 | 229s  | previous default       |
|  12 | 172s  | coordination tax       |
|  16 | 120s  | winner - matches P-core|
|  24 | 139s  | E-core oversubscription|

Raise the default in `devtools/verify.py:_pytest_worker_args` from 8 to
16. `POLYLOGUE_PYTEST_WORKERS` env override still honored.

Ref #1026
@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 42 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c524b969-d7b8-4a06-a6dc-afb4485da8e8

📥 Commits

Reviewing files that changed from the base of the PR and between f263116 and 8a33259.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock, !**/*.lock
📒 Files selected for processing (4)
  • devtools/verify.py
  • pyproject.toml
  • tests/conftest.py
  • tests/unit/devtools/test_verify.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/perf/verify-structured-reports

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 and usage tips.

@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: 8a33259df0

ℹ️ 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 tests/conftest.py Resolved
Sinity added a commit that referenced this pull request May 16, 2026
## Summary

Six pre-existing test failures on master were blocking every newly
opened PR in the #1058 wave (#1081, #1086, #1087, #1088, #1089). All
trace to incomplete cleanup after earlier proof-runner retirement work.

## Problem

`pytest --ignore=tests/integration,benchmarks,fuzz` on
`origin/master@fc3c43f` exits with 6 failures:

-
`tests/unit/devtools/test_benchmark_campaign.py::test_compile_benchmark_campaigns_indexes_by_name`
-
`tests/unit/devtools/test_benchmark_campaign.py::test_benchmark_scenario_index_tracks_authored_catalog`
-
`tests/unit/devtools/test_scenario_projections.py::test_all_projection_operation_targets_are_declared`
-
`tests/proof/laws/completeness/test_every_command_has_help_claim.py::*`
-
`tests/proof/laws/completeness/test_every_json_command_has_envelope_claim.py::*`
-
`tests/proof/laws/anti_dead_code/test_every_subject_has_at_least_one_claim.py::test_every_subject_of_a_fully_bound_kind_is_selected[cli.command]`

Multiple parallel agents inherited and flagged these failures; they
cannot be cleared at PR scope because each PR is supposed to follow the
"no inherited debt" rule.

## Solution

1. **Benchmark catalog drift** — `BENCHMARK_SCENARIOS` grew to include
`reader-api` and `daemon-convergence` (real entries with pytest paths).
Two tests still asserted the old 3-element set, and the new
`operation_targets` (`benchmark.reader.api`,
`benchmark.daemon.convergence`) had no declared `OperationSpec`. Added
the two missing `OperationSpec` rows in `polylogue/operations/specs.py`
and updated the test assertions.

2. **Stale proof-law tests** —
`tests/proof/laws/completeness/test_every_command_has_help_claim.py` and
`test_every_json_command_has_envelope_claim.py` asserted the existence
of `cli.command.{help,no_traceback,plain_mode,json_envelope}` proof
claims. Those were intentionally retired in PRs #1069/#594 (proof-runner
cleanup) because the intent is now pinned by pytest contract evidence
tests under `tests/unit/cli/` (`test_json_envelope_contract.py`,
`test_plain_output_contract.py`, `test_help_contract.py`,
`test_cli_error_boundaries.py`). The law tests are stale debt — both
files deleted.

3. **\`_FULLY_BOUND_KINDS\` parametrize drift** — same retirement
removed all claims selecting `cli.command` / `cli.json_command`
subjects. Removed both kinds from `_FULLY_BOUND_KINDS` in
`test_every_subject_has_at_least_one_claim.py` — the CLI contract suites
cover the surface directly now.

4. **Generated docs** — `docs/test-quality-workflows.md` and
`docs/verification-catalog.md` regen as part of the new OperationSpec
rows.

## Verification

```
nix develop -c pytest --ignore=tests/integration --ignore=tests/benchmarks --ignore=tests/fuzz -q --no-header
# 6841 passed, 2 xfailed, 0 failed (was 6 failed before)
nix develop -c devtools verify --quick  # exit 0
```

Ref #1058 #594 #1069

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
@Sinity
Sinity merged commit b2f7490 into master May 16, 2026
4 checks passed
@Sinity
Sinity deleted the feature/perf/verify-structured-reports branch May 16, 2026 11:40
Sinity added a commit that referenced this pull request May 16, 2026
… (#1091)

## Summary

Adds `devtools evidence-dashboard` and `devtools evidence-dashboard
trace` as the V7/V8 surface for #998 — a pytest-first evidence dashboard
built over the real artifacts produced by PRs #1083/#1086/#1087/#1088,
plus a changed-path traceability view that links each change to its
committed contract evidence and required gates.

## Problem

The pytest-first evidence model is now real:
`.cache/verify/last-pytest.json` (#1087),
`.cache/verification/evidence/*.json` (100+ artifacts),
`.cache/last-verify-result.json`, the SLO catalog with tier/freshness
(#1086), and parsed CI workflow facts (#1088) all exist. What was
missing was the single surface that reads those artifacts and presents
the V7 dashboard / V8 traceability view from #998, without rebuilding a
proof-row aggregator.

`devtools evidence-report` overlaps in shape but is anchored to
verify-history + suppressions + witnesses. It is intentionally left in
place; the new dashboard is a sibling so existing consumers and tests
are not disturbed.

## Solution

New module `devtools/evidence_dashboard.py` with sections, each backed
by a real artifact (or reported as `available: false` with the reason —
no aspirational rows):

- pytest health from `.cache/verify/last-pytest.json` (status, counts,
duration, last-run, staleness)
- contract evidence inventory from
`.cache/verification/evidence/*.json`, grouped by surface, with
stale-artifact and dirty-tree detection
- coverage from `coverage.xml` (line %) or `.coverage` (presence only)
when present
- benchmark campaign freshness from `.local/benchmark-campaigns/`
- SLO catalog rows (required vs informational) parsed via the existing
`devtools.verify_slos._parse_slo_catalog`
- static gate status from `.cache/last-verify-result.json` (preferred)
falling back to `.cache/verify-history.jsonl`
- witness counts (`tests/witnesses/` + `.local/witnesses/`)
- mutation campaign freshness from `.local/mutation-campaigns/`

`evidence-dashboard trace --base <ref> --head <ref>` reuses
`build_verification_impact_report` and joins each change subject (by
`test_nodeid` → test source path) to the contract-evidence artifacts
emitted by that test, plus required PR gates and deployment gates.
Output is JSON by default and Markdown when `--markdown` is set; both
formats are combinable.

Registered in `devtools/command_catalog.py`, `docs/devtools.md`
regenerated.

## Verification

Local commands run:

- `nix develop -c pytest tests/unit/devtools/test_evidence_dashboard.py
-v` — 15 passed
- `nix develop -c pytest tests/unit/devtools/test_evidence_dashboard.py
tests/unit/devtools/test_evidence_report.py
tests/unit/devtools/test_command_catalog.py
tests/unit/devtools/test_render_devtools_reference.py -q` — 35 passed
- `nix develop -c mypy devtools/evidence_dashboard.py
tests/unit/devtools/test_evidence_dashboard.py` — Success: no issues
- `nix develop -c ruff check devtools/evidence_dashboard.py
tests/unit/devtools/test_evidence_dashboard.py` — clean
- `nix develop -c devtools render-all --check` — sync OK
- `nix develop -c devtools verify --quick` — exit_code 0
- `nix develop -c devtools evidence-dashboard --json` — emits dashboard
against this worktree, correctly reports missing
pytest/coverage/campaign artifacts on the clean fixture worktree,
surfaces real SLO catalog rows (3 required, 3 informational) and witness
counts
- `nix develop -c devtools evidence-dashboard trace --base origin/master
--head HEAD --json` — emits trace; 0 changes on the post-commit working
tree, required_gates and deployment_gates populated from the
verification-impact pipeline

## Artifact gaps observed

The dashboard reports these as `available: false` because the underlying
artifacts don't exist in this worktree:

- `.cache/verify/last-pytest.json` — only produced by `devtools verify`
runs that include the pytest step; a fresh worktree without a verify run
reports unavailable
- `coverage.xml` / `.coverage` — none committed; `devtools
coverage-gate` produces them
- `.local/benchmark-campaigns/` — populated only by `devtools
benchmark-campaign run <name>`
- `.local/mutation-campaigns/` — populated only by `devtools
mutmut-campaign run <name>`

These gaps are honest: the dashboard does not fabricate values, and each
section names the command needed to populate it. The main checkout at
`/realm/project/polylogue` is the same shape — the SLO catalog,
witnesses, and static-gate cache are present; coverage and pytest-report
artifacts depend on operator runs.

Ref #998
Ref #1058

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added `evidence-dashboard` developer command with a dashboard mode to
visualize verification artifacts, test health, coverage status, and
benchmark freshness.
* Includes a trace subcommand to map changed paths to verification
impacts and related evidence.
* Both modes support JSON and Markdown output formats with configurable
thresholds.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Sinity/polylogue/pull/1091?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Sonnet 4.7 <[email protected]>
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 76.F095 / P1: fixed-already at the checked revision: Shared archive templates now derive their run root from the parent of each xdist worker basetemp; workers do not key independent fixture builds on their private directories. See tests/conftest.py:993.

Only the rows listed above are dispositioned. Held findings remain open.

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