Skip to content

perf(devtools): bound pytest harness memory pressure (#2170) - #2171

Merged
Sinity merged 1 commit into
masterfrom
feature/perf/memory-pressure-harness-daemon
Jun 19, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/perf/memory-pressure-harness-daemon

Conversation

@Sinity

@Sinity Sinity commented Jun 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Bounds the verification harness paths that were still capable of turning broad pytest-testmon selections into multi-GiB, single-process runs. Selection artifacts now preserve exact selected/deselected counts while sampling node IDs, default affected-test verification runs through a bounded xdist pool, run metadata records managed basetemp cleanup, and resource summary parsing streams the resource log instead of loading it wholesale.

Problem

Local verify evidence showed two distinct failure shapes:

  • devtools verify --seed-testmon --skip-slow selected about 11.5k tests with -n 4, peaked around 3.1 GiB PSS, and wrote about 3.0 GiB of pytest basetemp data.
  • A default devtools verify selected about 11.3k tests with -n 0, kept one Python process around 2.8 GiB PSS, and hit the 45-minute supervisor timeout.

Focused devtools test ... runs stayed around 100-140 MiB RSS, so the implicated surface was broad/default harness behavior, not the ordinary inner loop. A fresh ps sample of the installed polylogued during this work was about 216 MiB RSS after 6h25m, so this PR does not claim a daemon retention fix.

Solution

  • devtools.pytest_progress_plugin now samples selected/deselected node IDs (POLYLOGUE_PYTEST_SELECTION_NODEID_LIMIT, default 500) while retaining exact counts and omitted-count metadata.
  • devtools verify now defaults the affected pytest-testmon lane to -n 4, matching seed/full broad lanes, while focused devtools test remains single-process by default.
  • Pytest step metadata now records basetemp_cleanup, making post-run temp-tree reclamation visible in verify history.
  • Resource-summary projection streams resources.jsonl rather than materializing all samples in memory.
  • polylogue ops status facade-route catalog was updated for neighbor_candidate_payloads and session_correlation_payload; the broad verify run found this real drift after feat(daemon): stabilize evidence read API routes (#1847) #2169.
  • Testing docs and generated AGENTS.md describe the new worker and selection-artifact behavior.

Verification

  • devtools test tests/unit/cli/test_status.py::test_archive_facade_route_catalog_covers_public_async_facade tests/unit/cli/test_plain_cli_snapshots.py::test_json_status_snapshot tests/unit/devtools/test_pytest_progress_plugin.py tests/unit/devtools/test_verify.py tests/unit/devtools/test_run_tests.py -> 74 passed.
  • devtools verify --quick -> exit 0, run 20260619T162135Z-quick-1620666-9bbe9eae.
  • Initial broad-path proof: devtools verify selected 11,544 tests with -n 4, completed in 36:03 instead of timing out, recorded basetemp_cleanup, and peaked at 4.38 GiB PSS; it failed one status route-catalog test, which this PR fixes.
  • Final devtools verify after the catalog/snapshot fix -> exit 0, run 20260619T162202Z-testmon-1622183-8c640aa0; pytest step selected 10, ran 1 affected test, passed, and recorded basetemp_cleanup plus peak PSS 553.1 MiB.

Closes #2170

Summary by CodeRabbit

  • New Features

    • Configurable pytest worker pool for verification runs (default 4 workers via POLYLOGUE_PYTEST_WORKERS).
    • Node ID sampling in selection artifacts with configurable limit via POLYLOGUE_PYTEST_SELECTION_NODEID_LIMIT (default 500).
    • Added new routes to status command output: neighbor_candidate_payloads and session_correlation_payload.
  • Documentation

    • Updated verification documentation regarding pytest worker pool control and selection artifact behavior.

Problem: broad pytest-testmon runs could select nearly the whole suite, retain and write unbounded selection node lists, and then spend the full timeout in one multi-GiB Python process. Basetemp cleanup also had no metadata trail, making stale temp-tree pressure harder to diagnose.

What changed: bound pytest selection node-id artifacts while preserving exact counts, run the default affected-test lane with a bounded xdist pool, stream resource-summary parsing instead of loading the full resource log, record managed basetemp cleanup in verify metadata, and update the status route catalog drift found by the broad run.

Verification: devtools test tests/unit/cli/test_status.py::test_archive_facade_route_catalog_covers_public_async_facade tests/unit/devtools/test_pytest_progress_plugin.py tests/unit/devtools/test_verify.py tests/unit/devtools/test_run_tests.py; devtools verify --quick. Full devtools verify selected 11544 tests with -n 4 and proved the harness path, but failed before the catalog drift fix; targeted rerun covers that failure.

Ref #2170
github-actions Bot pushed a commit that referenced this pull request Jun 19, 2026
@Sinity
Sinity merged commit d150845 into master Jun 19, 2026
13 checks passed
@Sinity
Sinity deleted the feature/perf/memory-pressure-harness-daemon branch June 19, 2026 16:26

@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: 798bb9e0e8

ℹ️ 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 Resolved
@coderabbitai

coderabbitai Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 85fd0dbd-ebfa-4f27-ba43-9d348405bb84

📥 Commits

Reviewing files that changed from the base of the PR and between 69b6368 and 798bb9e.

📒 Files selected for processing (8)
  • AGENTS.md
  • TESTING.md
  • devtools/pytest_progress_plugin.py
  • devtools/verify.py
  • polylogue/cli/commands/status.py
  • tests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambr
  • tests/unit/devtools/test_pytest_progress_plugin.py
  • tests/unit/devtools/test_verify.py

📝 Walkthrough

Walkthrough

Bounded nodeid sampling is added to pytest_progress_plugin using counters and a configurable sample limit (POLYLOGUE_PYTEST_SELECTION_NODEID_LIMIT, default 500). devtools/verify.py changes the testmon default to -n 4 unconditionally, captures cleanup_managed_pytest_basetemp return in step metadata, and streams JSONL resource summary instead of building an in-memory list. Two new archive routes (neighbor_candidate_payloads, session_correlation_payload) are registered in status.py. Documentation in AGENTS.md and TESTING.md is updated to match.

Changes

Devtools verify harness improvements

Layer / File(s) Summary
Bounded nodeid sampling in pytest_progress_plugin
devtools/pytest_progress_plugin.py, tests/unit/devtools/test_pytest_progress_plugin.py
Adds _SELECTION_NODEID_LIMIT_ENV, deselected sampling counters, and _selection_nodeid_limit(); rewrites pytest_deselected for bounded accumulation; extends pytest_collection_modifyitems to truncate selected nodeids and record selected_nodeids_omitted/deselected_nodeids_omitted; updates pytest_sessionfinish to use total counters. Tests update teardown fixture, reset step, omitted-count assertions, and add a new bounding test.
verify.py: DEFAULT_TESTMON_WORKERS, basetemp cleanup metadata, streaming resource summary
devtools/verify.py, tests/unit/devtools/test_verify.py
Adds DEFAULT_TESTMON_WORKERS = "4" constant; unconditionally uses it as testmon -n default; captures cleanup_managed_pytest_basetemp() return into metadata["basetemp_cleanup"]; rewrites JSONL resource summary to stream-parse instead of building an in-memory list. Tests update expected worker count and add a _run test for basetemp cleanup metadata.
AGENTS.md and TESTING.md documentation updates
AGENTS.md, TESTING.md
Updates devtools verify run descriptions to specify -n 4 bounded worker pool with POLYLOGUE_PYTEST_WORKERS override; adds notes on POLYLOGUE_PYTEST_SELECTION_NODEID_LIMIT (default 500) governing nodeid sampling in selection artifacts.

Status route catalog additions

Layer / File(s) Summary
New archive route entries and snapshot updates
polylogue/cli/commands/status.py, tests/unit/cli/__snapshots__/test_plain_cli_snapshots.ambr
Adds neighbor_candidate_payloads to _ARCHIVE_FACADE_ROUTES and session_correlation_payload to _ARCHIVE_CLI_ROUTES. Updates test snapshots for aggregate routing counts, new route catalog entries, and facade_tier_route_counts.index.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Sinity/polylogue#2107: Both PRs modify devtools/pytest_progress_plugin.py to extend the selection artifact payload (selection-path wiring, collection_finished fields), making the bounded nodeid sampling here a direct continuation of that selection observability implementation.
  • Sinity/polylogue#2163: Both PRs modify devtools/verify.py at the cleanup_managed_pytest_basetemp(...) call site; this PR additionally captures and records its return value in step metadata.
  • Sinity/polylogue#2151: Both PRs add entries to the static archive route catalog in polylogue/cli/commands/status.py that drive CLI status output and tier-count diagnostics.

Poem

🐇 Hoppity-hop through the test node maze,
Too many IDs were causing a daze!
Now counters count what the samples can't hold,
And -n 4 keeps the workers bold.
Basetemp is cleaned, the metadata speaks,
A bounded rabbit runs all of the weeks! 🌿

✨ 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/perf/memory-pressure-harness-daemon

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 19, 2026
## Summary

Bound daemon-side SQLite cache pressure by separating long-running
daemon/ops writes from the batch-ingest write profile, and by moving
recurring daemon read probes onto the read-only profile.

## Problem

The live memory snapshot after #2171 showed a different pressure shape
from the pytest harness issue: `polylogued.service` was near 950 MiB
current cgroup memory with a 2.9 GiB peak, but the daemon process itself
was only about 235 MiB PSS. `memory.stat` attributed most current usage
to file cache rather than anonymous heap. Several daemon loops still
opened the full write profile for small ops/maintenance work, and
heartbeat counts opened a write-profile connection for read-only counts.

## Solution

Added an explicit daemon write profile in
`polylogue/storage/sqlite/connection_profile.py` with a 16 MiB SQLite
cache and 64 MiB mmap allowance, leaving the existing 128 MiB / 1 GiB
batch-ingest write profile untouched. Moved small daemon/ops writes
(`daemon_events`, cursor-lag samples, embedding catch-up rows, OTLP
telemetry, daily optimize) to `open_daemon_connection`, and moved
heartbeat plus two ops health probes to `open_readonly_connection`.

The existing status/metrics memory reporting already distinguishes RSS,
cgroup current/peak, cgroup file, and inactive file, so this change
relies on that live observability rather than adding another reporting
layer.

## Verification

- `devtools test
tests/unit/storage/test_wal_journal_size_limit.py::test_daemon_write_profile_uses_bounded_cache_and_mmap
tests/unit/storage/test_wal_journal_size_limit.py::test_open_daemon_connection_applies_bounded_cache_and_mmap
tests/unit/daemon/test_daemon_cli.py::test_daemon_cli_heartbeat_counts_uses_read_only_probe
tests/unit/daemon/test_daemon_cli.py::test_daemon_cli_heartbeat_counts_archive
tests/unit/daemon/test_cursor_lag_baseline.py
tests/unit/daemon/test_cursor_lag_integration.py
tests/unit/daemon/test_otlp_receiver.py
tests/unit/daemon/test_metrics_endpoint.py::TestFormatMetricsReadsArchiveState::test_fts_freshness_and_memory_state`
— 46 passed.
- `devtools verify --quick` — exit 0.
- `devtools verify` — run `20260619T163716Z-testmon-1662720-33dfc22a`;
505 passed in 256.73s, selected_count=1247, peak_tree_pss=2813.7 MiB,
diagnosis=`pytest_passed`.

Closes #2172
@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.

  • 55.F100 / P2: refuted at the checked revision: The current load_sensitive marker explicitly states that these tests share the corpus pool and failures are rerun alone (pyproject.toml:210). The claim that this marker requires the former separate serial default lane therefore contradicts its current definition; the verifier supplies the declared isolated rerun.

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.

perf(devtools): bound pytest memory pressure and daemon memory observability

1 participant