Skip to content

fix(devtools): report active pytest node during verify - #2100

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/verify-pytest-observability
Jun 18, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/verify-pytest-observability

Conversation

@Sinity

@Sinity Sinity commented Jun 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Make devtools verify expose the active pytest node while long testmon runs are in flight. The pytest progress plugin now writes start/finish events for each node, and verify heartbeats/progress JSON include the latest event/current node when available.

Problem

A default devtools verify run for a two-file metadata/docstring branch selected a very broad testmon set, ran for over 35 minutes, wrote roughly 40 GB according to /proc/<pid>/io, and reported only percentage/process state. The live progress artifact did not name the active test node, and the advertised events ledger was missing because the plugin did not emit runtime events under real pytest.

Solution

  • Mark the pytest progress hooks explicitly and add node start/finish event writes.
  • Keep completed-test report events, but route all writes through one helper.
  • Read the latest JSONL event into current-pytest-progress.json and heartbeat output.
  • Align the child events path with the verify working directory so progress/event artifacts refer to the same ledger.
  • Add direct plugin tests and verify heartbeat coverage for current-node reporting.

Verification

  • nix develop --command devtools test tests/unit/devtools/test_pytest_progress_plugin.py tests/unit/devtools/test_verify.py -k 'pytest_progress_plugin or heartbeat_reports_latest_test_node or emits_heartbeat_for_long_silent_child or writes_live_progress_artifact or forces_subprocesses' -> 7 passed, 42 deselected.
  • Runtime smoke: POLYLOGUE_PYTEST_EVENTS_PATH=/tmp/polylogue-pytest-events-smoke.jsonl nix develop --command pytest -q -p devtools.pytest_progress_plugin tests/unit/core/test_query_descriptor_parity.py -> 5 passed and emitted 10 start/finish events.
  • nix develop --command devtools verify --quick -> exit_code 0.

Summary by CodeRabbit

  • New Features

    • Enhanced test progress tracking to capture test start and finish events during pytest execution.
    • Added real-time visibility of the currently running test within progress reports during long test runs.
  • Improvements

    • Refined progress reporting to display the latest test execution information in stderr output while tests are running.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6f8c2256-f565-4b67-bb09-daa87a72084d

📥 Commits

Reviewing files that changed from the base of the PR and between 371657a and 9ac5778.

📒 Files selected for processing (4)
  • devtools/pytest_progress_plugin.py
  • devtools/verify.py
  • tests/unit/devtools/test_pytest_progress_plugin.py
  • tests/unit/devtools/test_verify.py

📝 Walkthrough

Walkthrough

The pytest progress plugin gains a _write_event() helper that appends timestamped JSON lines to a JSONL ledger at POLYLOGUE_PYTEST_EVENTS_PATH. Two new hooks (pytest_runtest_logstart, pytest_runtest_logfinish) emit test_started/test_finished events. verify.py adds _read_latest_pytest_event to tail that ledger and surfaces it in both the heartbeat stderr line and the progress payload. The events path is also changed to be relative to Path.cwd().

Changes

Live pytest event ledger and heartbeat surfacing

Layer / File(s) Summary
_write_event helper and new plugin hooks
devtools/pytest_progress_plugin.py
Adds _write_event(payload) which reads the output path from POLYLOGUE_PYTEST_EVENTS_PATH, attaches updated_at, and appends a JSON line. Two new hooks pytest_runtest_logstart and pytest_runtest_logfinish use it to emit test_started/test_finished events with nodeid and location. pytest_runtest_logreport is refactored to build its payload and delegate writing to _write_event.
Event reader, progress payload, heartbeat, and path fix
devtools/verify.py
Adds _read_latest_pytest_event to scan the JSONL ledger tail for the last valid JSON object. _write_pytest_progress is extended to include latest_test_event and current_test_nodeid in the payload. The heartbeat "still running" stderr line gains latest=<event>:<nodeid>. _subprocess_env changes POLYLOGUE_PYTEST_EVENTS_PATH to be relative to Path.cwd().
Tests for hooks, heartbeat, and events path
tests/unit/devtools/test_pytest_progress_plugin.py, tests/unit/devtools/test_verify.py
Adds test_progress_plugin_records_node_start_and_finish verifying emitted event types and location. Updates test_run_forces_subprocesses_to_current_checkout for the Path.cwd() path. Adds test_pytest_run_heartbeat_reports_latest_test_node asserting both heartbeat stderr and progress JSON reflect the latest test_started nodeid.

Sequence Diagram(s)

sequenceDiagram
  participant pytest
  participant pytest_progress_plugin
  participant _write_event
  participant JSONL_ledger as JSONL Ledger
  participant _read_latest_pytest_event
  participant verify_py as verify.py heartbeat

  pytest->>pytest_progress_plugin: pytest_runtest_logstart(nodeid, location)
  pytest_progress_plugin->>_write_event: {event: test_started, nodeid, location}
  _write_event->>JSONL_ledger: append line + updated_at

  pytest->>pytest_progress_plugin: pytest_runtest_logreport(report)
  pytest_progress_plugin->>_write_event: {event: test_report, ...}
  _write_event->>JSONL_ledger: append line + updated_at

  verify_py->>_read_latest_pytest_event: read tail of JSONL ledger
  _read_latest_pytest_event->>JSONL_ledger: scan backwards for last valid JSON
  JSONL_ledger-->>_read_latest_pytest_event: last event dict
  _read_latest_pytest_event-->>verify_py: {event, nodeid, ...}
  verify_py->>verify_py: emit stderr "latest=test_started:<nodeid>"
  verify_py->>verify_py: write progress JSON with latest_test_event + current_test_nodeid
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Sinity/polylogue#2074: Modifies the same _write_pytest_progress function in devtools/verify.py to include live pytest data in the progress output.
  • Sinity/polylogue#2078: Implements the same POLYLOGUE_PYTEST_EVENTS_PATH JSONL event ledger wiring between devtools/pytest_progress_plugin.py and devtools/verify.py for live heartbeat behavior.

Poem

🐇 Hop, hop, the tests begin to race,
A ledger of events keeping steady pace.
test_started and test_finished scrawled with care,
The heartbeat whispers "latest=" through the air.
No test shall hide while this rabbit is near! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.89% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: exposing the active pytest node during devtools verify runs through enhanced event reporting.
Description check ✅ Passed The description follows the template structure with all required sections: Summary, Problem, Solution, Verification, and Changelog (skipped appropriately). Content is detailed and comprehensive.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/verify-pytest-observability

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.

Sinity added a commit that referenced this pull request Jun 18, 2026
## Summary
Tighten the query descriptor parity tests around the now-shipped shared
query metadata and fix stale daemon route wording for terminal query
units.

## Problem
The #2006 metadata split and terminal query-unit work have already
landed, but the descriptor parity test still described itself as an
informational #621 placeholder and carried a stale allowlist of fields
that now have real MCP/API names. The daemon `/api/query-units` handler
docstring also still named only message/action/block rows even though
assertions are now part of the terminal query-unit surface.

## Solution
- Reword descriptor parity coverage as shared query-substrate coverage.
- Reduce the allowlist to true internal plan-only descriptors
(`parent_id`, lineage booleans, branch/predicate internals).
- Keep the test as positive metadata coverage: public selection filters
must expose a surface name unless they are genuinely plan-only.
- Update the daemon handler docstring to describe terminal query-unit
rows generically.

## Verification
- `nix develop --command devtools test
tests/unit/core/test_query_descriptor_parity.py
tests/unit/daemon/test_daemon_http.py -k 'descriptor or query_units'` ->
5 passed, 5 deselected.
- `nix develop --command devtools verify --quick` -> exit_code 0.

Default `devtools verify` selected a very broad testmon set for this
two-file metadata/docstring change and was stopped after ~35 minutes at
97%; the run had already written roughly 40 GB and did not expose the
active test node. PR #2100 fixes that harness observability gap so
future long default verifies report the current node instead of only
percentage/process state.

@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: 9ac5778c39

ℹ️ 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/verify.py
Comment on lines +370 to +371
if latest_event.get("event") == "test_started" and isinstance(latest_event.get("nodeid"), str):
payload["current_test_nodeid"] = latest_event["nodeid"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Track active pytest nodes across workers

In the seeded/full verify lanes, pytest runs with xdist (build_verify_steps() defaults those lanes to -n 16), so multiple tests can be active at once. If worker A starts a long or hung test and worker B later finishes another test, the latest ledger row becomes test_finished, this branch omits current_test_nodeid, and the live progress artifact no longer identifies the stuck test even though its unmatched test_started event is still in the ledger. Track active nodeids from unmatched start/finish events rather than deriving current state from only the latest event.

Useful? React with 👍 / 👎.

@Sinity
Sinity merged commit 28e95ab into master Jun 18, 2026
11 checks passed
@Sinity
Sinity deleted the feature/fix/verify-pytest-observability branch June 18, 2026 12:10
Sinity added a commit that referenced this pull request Jun 18, 2026
## Summary

Make the default `devtools verify` pytest-testmon path validate the seed
stamp before it starts pytest. The preflight now rejects missing,
unreadable, wrong-head, and fingerprint-drifted
`.cache/testmon/seed.json` state instead of accepting any old
`.testmondata` file.

## Problem

A diagnostic default verify run accepted a seed from `a1a4f9f` recorded
on 2026-06-06, while current master was `28e95ab` after 245 first-parent
commits. That stale seed selected a very broad pseudo-full run: the
bounded diagnostic reached 900s, emitted 1,406 test starts, and was
still progressing through MCP archive-surface tests. The harness was
observable after #2100, but the preflight still allowed stale
affected-test metadata to waste the gate.

## Solution

`_testmon_preflight` now reads `.cache/testmon/seed.json`, compares its
`git_head` to the current checkout, and compares its recorded
`.testmondata` fingerprint to the current file. If either check fails,
default verify exits immediately with reseed instructions.
`--seed-testmon`, `--all`, `--quick`, and commit/pre-push quick paths
remain unaffected.

## Verification

- `nix develop --command devtools test
tests/unit/devtools/test_verify.py -k 'testmon_preflight'` → 6 passed,
42 deselected
- `nix develop --command ruff check --fix devtools/verify.py
tests/unit/devtools/test_verify.py` → fixed import order, 0 remaining
- `nix develop --command ruff format --check devtools/verify.py
tests/unit/devtools/test_verify.py` → 2 files already formatted
- `nix develop --command devtools verify --quick` → exit_code 0
- `nix develop --command devtools verify` with stale local seed → exits
in ~1s with: `pytest-testmon seed was recorded for a different git head`
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