Skip to content

debug_utils: async buffer sanity inspector + --inspect-buffers-on-shutdown#683

Draft
DLWoodruff wants to merge 2 commits into
Pyomo:mainfrom
DLWoodruff:async-buffer-sanity-design
Draft

debug_utils: async buffer sanity inspector + --inspect-buffers-on-shutdown#683
DLWoodruff wants to merge 2 commits into
Pyomo:mainfrom
DLWoodruff:async-buffer-sanity-design

Conversation

@DLWoodruff
Copy link
Copy Markdown
Collaborator

Summary

Adds a new package mpisppy.debug_utils containing a passive content-check utility for the MPI-RMA send and receive buffers used by the hub-and-spoke system, plus an opt-in CLI flag that runs the check at cylinder shutdown.

Motivation. An xhat spoke was observed receiving a SHUTDOWN signal that Hub.send_terminate had not produced — suggesting that the SHUTDOWN buffer region was being written to from somewhere unexpected. mpi-sppy had no runtime sanity check on buffer contents; _validate_recv_field only checks layout at registration time. This PR adds the missing layer.

What's in it

  • mpisppy/debug_utils/buffer_inspect.py — the inspector. Single entry point inspect_buffer(buf, fld, ctx, *, send, verbose). InspectContext is duck-typed (accepts SPBase via getattr); explicit fields take precedence.
  • Generic checks (every field): trailing write_id slot is finite / non-negative / integer-valued; send-side id matches buf.id(); recv-side id does not regress below buf.id() or optional ctx.last_write_id; no inf in data; no NaN once write_id >= 1; padding region (between logical_len and padded_len) stays NaN.
  • Per-Field checks: SHUTDOWN, NONANT, NONANT_LOWER_BOUNDS, NONANT_UPPER_BOUNDS, OBJECTIVE_INNER_BOUND, OBJECTIVE_OUTER_BOUND, BEST_XHAT. Adding a new checker is one function and one dict entry.
  • --inspect-buffers-on-shutdown CLI flag in popular_args, propagated through cfg_vanilla.shared_options. _BoundSpoke.got_kill_signal reads it and runs the inspector only when shutdown is detected (the diagnostic moment). Off by default; no overhead when unset.
  • Producers are NOT touched. The inspector is purely a consumer concern.

Tests (34 new)

mpisppy/tests/test_buffer_inspect.py covers: every generic check, every per-field check, SPBase fallback for nonant length, verbose dump, severity ladder, and the config-flag wiring (default false, propagation through shared_options). Wired into the existing unit-tests CI job so codecov picks it up.

Documentation

  • doc/src/debug_utils.rst — user-facing page under For Developers and Contributors.
  • doc/designs/async_buffer_sanity_design.md — internal design doc with invariants, check tables, and explicit non-goals (cross-cylinder consensus, module-level history state).

Draft because

Opened as a draft so the design can be reviewed before any further hot-path integrations (e.g., wiring the inspector into update_nonants or sync_bounds) are added. The current scope is intentionally narrow: prove out the SHUTDOWN check, then expand.

Test plan

  • python -m pytest mpisppy/tests/test_config.py mpisppy/tests/test_buffer_inspect.py — 112 passed
  • ruff check clean on all touched files
  • Manual smoke: stomped recv buffer (data=1.0, write_id=0) produces the expected SHUTDOWN-specific finding
  • Manual smoke: padding-region overrun produces a padding finding
  • Manual smoke: --inspect-buffers-on-shutdown propagates through shared_options for hub and spoke; unset default propagates as False
  • Real reproduction of the motivating spurious-SHUTDOWN incident with the flag enabled

🤖 Generated with Claude Code

DLWoodruff and others added 2 commits May 11, 2026 16:25
mpisppy/debug_utils/buffer_inspect.py is a passive content checker for
SendArray / RecvArray that detects the SHUTDOWN-stomp signature plus a
small set of per-Field invariants. Producers are not touched; callers
pass an optional InspectContext (or an SPBase via duck-typing).

_BoundSpoke.got_kill_signal gets an env-gated hook
(MPISPPY_INSPECT_BUFFERS=1) that runs the inspector on each shutdown
poll and prints findings only when the report is non-OK.

See doc/designs/async_buffer_sanity_design.md for invariants leaned on
(NaN-padding init from communicator_array, buf.id() as recv baseline),
the check tables, and the wiring rationale.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the prior MPISPPY_INSPECT_BUFFERS env-var gate with a Config
flag --inspect-buffers-on-shutdown (popular_args). The flag is
propagated through cfg_vanilla.shared_options into opt.options and
read by _BoundSpoke.got_kill_signal only when a shutdown is detected;
when the report is non-OK the spoke prints rank info plus the
verbose Report dump. The check fires at the moment of detection
because a spurious shutdown's buffer state has not yet been overwritten
by later activity.

Public surface: mpisppy.debug_utils now re-exports inspect_buffer,
InspectContext, and Report.

Adds mpisppy/tests/test_buffer_inspect.py (34 cases covering generic
checks, all per-field checkers, SPBase fallback, verbose dump, and
the config-flag wiring). Wired into the unit-tests CI job.

User-facing RST page (doc/src/debug_utils.rst) added under For
Developers and Contributors; design doc updated to reflect the
CLI-flag wiring.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 95.13514% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.26%. Comparing base (b58f561) to head (2d36a25).

Files with missing lines Patch % Lines
mpisppy/debug_utils/buffer_inspect.py 96.57% 6 Missing ⚠️
mpisppy/cylinders/spoke.py 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #683      +/-   ##
==========================================
+ Coverage   71.05%   71.26%   +0.21%     
==========================================
  Files         154      156       +2     
  Lines       19252    19436     +184     
==========================================
+ Hits        13679    13852     +173     
- Misses       5573     5584      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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