Skip to content

fix: no benchmark warning when a process exits before it can be sampled - #4260

Merged
johanneskoester merged 3 commits into
snakemake:mainfrom
bkeepers:fix-benchmark-process-gone-warning
Jul 30, 2026
Merged

johanneskoester merged 3 commits into
snakemake:mainfrom
bkeepers:fix-benchmark-process-gone-warning

Conversation

@bkeepers

@bkeepers bkeepers commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

A job that finishes faster than the benchmark interval leaves the monitor with no sample, so BenchmarkRecord.data_collected stays False and get_benchmarks logs at warning level:

Benchmark: unable to collect cpu and memory benchmark statistics: process no longer exists (pid=...)

This is benign — the process simply completed too quickly to measure — but at scale it floods the log with warnings about healthy fast jobs.

Track that case (process_gone) separately from real collection errors: a psutil.NoSuchProcess during sampling now sets the flag instead of being recorded as an error, and get_benchmarks emits it at debug level. Genuine collection failures (permission errors, too many open files) still warn.

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The documentation (docs/) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake).
  • I, as a human being, have checked each line of code in this pull request

AI-assistance disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Summary by CodeRabbit

  • Bug Fixes
    • Improved benchmark collection for scenarios where the observed process ends before CPU/memory sampling begins, marking it appropriately and avoiding incorrect missing-stat warnings.
    • Reduced noise during mid-sampling: vanished child processes are skipped without being treated as full collection failures.
    • Preserved warning behavior when sampling fails for reasons other than early process termination.

A job that finishes faster than the benchmark interval leaves the monitor with
no sample, so BenchmarkRecord.data_collected stays False and get_benchmarks
logs "Benchmark: unable to collect cpu and memory benchmark statistics:
process no longer exists (pid=...)" at warning level. This is benign — the
process simply completed too quickly to measure — but at scale it floods the
log with warnings about healthy fast jobs.

Track that case (process_gone) separately from real collection errors: a
psutil.NoSuchProcess during sampling now sets the flag instead of being
recorded as an error, and get_benchmarks emits it at debug level. Genuine
collection failures (permission errors, too many open files) still warn.
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d3c934aa-29ee-432e-81b9-7c5c711372f2

📥 Commits

Reviewing files that changed from the base of the PR and between 8d24077 and 346e1c4.

📒 Files selected for processing (2)
  • src/snakemake/benchmark.py
  • tests/test_benchmark_process_gone.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/snakemake/benchmark.py

📝 Walkthrough

Walkthrough

Benchmark records now distinguish early process termination from collection errors. Sampling handles vanished main and child processes separately, while serialization adjusts missing-statistics logging. Tests cover benign disappearance, partial sampling, and actual collection failures.

Changes

Benchmark process disappearance handling

Layer / File(s) Summary
Track vanished processes
src/snakemake/benchmark.py, tests/test_benchmark_process_gone.py
BenchmarkRecord adds process_gone; _update_record() handles vanished main and child processes, resilient process-name lookup, and partial sampling scenarios.
Handle missing statistics and validate behavior
src/snakemake/benchmark.py, tests/test_benchmark_process_gone.py
get_benchmarks() logs process disappearance at debug level without errors and retains warnings for recorded failures; tests cover both logging paths.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: johanneskoester

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 describes the main change: suppressing benchmark warnings for processes that exit before sampling.
Description check ✅ Passed The description matches the template, includes the change summary, QC checklist, and AI-assistance disclosure, and notes the added test.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/snakemake/benchmark.py`:
- Around line 402-405: Update the process sampling logic surrounding the
NoSuchProcess handler so process_gone is set only when self.main disappears
before the first usable sample. Treat vanished child processes as skippable,
continue sampling the remaining process tree, and preserve any partial sample
and warning behavior when the benchmarked main process remains alive.

In `@tests/test_benchmark_process_gone.py`:
- Around line 39-69: Strengthen the tests around get_benchmarks(): in
test_get_benchmarks_does_not_warn_when_only_reason_is_process_gone, assert
logger.debug received the expected process-disappearance message rather than
merely being called. In
test_get_benchmarks_still_warns_on_real_collection_error, set process_gone=True
while retaining the real error and continue asserting that logger.warning is
called.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c643788-cd6a-453d-a1b1-d15dac4c25d9

📥 Commits

Reviewing files that changed from the base of the PR and between 1a27746 and cb8d3f6.

📒 Files selected for processing (2)
  • src/snakemake/benchmark.py
  • tests/test_benchmark_process_gone.py

Comment thread src/snakemake/benchmark.py Resolved
Comment thread tests/test_benchmark_process_gone.py Resolved
johanneskoester and others added 2 commits July 29, 2026 12:51
…n process

A vanished child raised NoSuchProcess out of the whole-tree try block,
discarding the tick's partial sample and setting process_gone while the
benchmarked process was still alive. The likeliest escape path was the
memory-info skip handler itself: proc.name() on the vanished child.

Each process now samples under its own handler: a child exiting between
enumeration and sampling is skipped and the partial sample kept (peaks
no longer bias low for fork-heavy jobs); process_gone is set only when
the observed main process is the one that disappeared.
@johanneskoester

Copy link
Copy Markdown
Contributor

Thanks a lot!

@johanneskoester
johanneskoester merged commit 6738359 into snakemake:main Jul 30, 2026
88 checks passed
johanneskoester pushed a commit that referenced this pull request Jul 30, 2026
🤖 I have created a release *beep* *boop*
---


##
[9.24.0](v9.23.1...v9.24.0)
(2026-07-30)


### Features

* allow to combine cases with otherwise in branch function
([#4262](#4262))
([000ff52](000ff52))


### Bug Fixes

* avoid config hash crash for non-serializable values
([#4241](#4241))
([1a27746](1a27746))
* compilation error when final line contains an f-string
([#4234](#4234))
([9c5e7fe](9c5e7fe))
* Group error log formatting
([#4256](#4256))
([bb6dcde](bb6dcde))
* leak of benchmark monitor threads
([#4259](#4259))
([d37852e](d37852e))
* no benchmark warning when a process exits before it can be sampled
([#4260](#4260))
([6738359](6738359))
* persistence starttime unset/defaults
([#4251](#4251))
([56395c0](56395c0))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants