Skip to content

feat(infra): diagnostics utils, better terminal warnings#124

Merged
stanlrt merged 19 commits intomainfrom
123-create-the-errorwarning-tracking-logic
May 10, 2026
Merged

feat(infra): diagnostics utils, better terminal warnings#124
stanlrt merged 19 commits intomainfrom
123-create-the-errorwarning-tracking-logic

Conversation

@stanlrt
Copy link
Copy Markdown
Collaborator

@stanlrt stanlrt commented May 8, 2026

Summary

  • New src/raitap/utils/warnings.py module: WarningOrigin dataclass, resolve_warn_origin (frame walk for raitap subsystem + third-party lib detection), suppress_warning adapter helper, is_dev_install heuristic, docs_url mapper.
  • RaitapRichHandler._emit_panel now branches on is_dev_install() and the resolved origin: dev shows <Subsystem> · path:line, installed shows <Subsystem> linked to docs, third-party adds via <lib>. Frame-walk logic moved out of console.py.
  • Captum adapter now calls suppress_warning(...) at import to silence the Input Tensor … required_grads UserWarning that captum auto-fixes anyway.

Closes #123 (infra portion). Out of scope per plan: full error-message rewrap (issue #22) — this only ships the infrastructure that #22 will build on, plus one captum smoke-test.

Test plan

  • uv run pytest — 573 passed, 22 skipped (pre-existing failures gated on missing optional deps unaffected).
  • 13 new unit tests for resolve_warn_origin, is_dev_install (mocked __file__), docs_url, suppress_warning.
  • uv run ruff check . + uv run ruff format --check . clean.
  • uv run pyright on changed files: 0 errors.
  • uv run raitap smoke test: dev mode renders ▲ Warning · Metrics · <full path>; captum warning no longer appears.
  • Installed-mode rendering (post-merge wheel install) shows ▲ Warning · Metrics linked to docs (manual verification when wheel published).

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 8, 2026 16:21
@stanlrt stanlrt linked an issue May 8, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a centralized warning infrastructure to classify warning origins (raitap subsystem + known third-party libraries), render warning panels differently for dev vs installed users (paths vs docs links), and suppress a noisy Captum UserWarning at runtime.

Changes:

  • Added raitap.utils.warnings for origin resolution, docs-link mapping, dev-install detection, and a suppress_warning() helper.
  • Updated Rich warning panel rendering to use resolved origins and audience-aware headers (dev: path/line; installed: docs link; third-party: “via ”).
  • Suppressed Captum’s repetitive “required_grads” warning at import time and aligned pytest warning filters accordingly; added unit tests for the new warnings utilities.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/raitap/utils/warnings.py New warning infrastructure (origin classification, suppression helper, dev-install heuristic, docs URL mapping, origin stash queue).
src/raitap/utils/tests/test_warnings.py New unit tests covering origin resolution, suppression, dev-install detection, and docs URL generation.
src/raitap/utils/console.py Moves frame-walk logic out of console; warning panel header now uses resolved origin + dev/install branching.
src/raitap/utils/__init__.py Exposes WarningOrigin and suppress_warning from the utils package.
src/raitap/transparency/explainers/captum_explainer.py Silences Captum’s noisy UserWarning at import time via suppress_warning().
pyproject.toml Documents/keeps pytest filterwarnings entry to match runtime suppression behavior.

Comment thread src/raitap/utils/console.py Outdated
Comment thread src/raitap/utils/warnings.py Outdated
Comment thread src/raitap/utils/warnings.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Comment thread src/raitap/transparency/explainers/captum_explainer.py
Comment thread src/raitap/utils/warnings.py Outdated
Comment thread src/raitap/utils/warnings.py Outdated
@stanlrt stanlrt requested a review from pizzajojo May 8, 2026 18:32
@stanlrt stanlrt changed the title feat(infra): warning infra module + audience-aware panels + captum suppression feat(infra): diagnostics module + audience-aware panels + captum suppression May 8, 2026
@stanlrt stanlrt changed the title feat(infra): diagnostics module + audience-aware panels + captum suppression feat(infra): diagnostics module, better terminal warnings May 8, 2026
@stanlrt stanlrt changed the title feat(infra): diagnostics module, better terminal warnings feat(infra): diagnostics utils, better terminal warnings May 8, 2026
@stanlrt stanlrt self-assigned this May 8, 2026
@stanlrt stanlrt mentioned this pull request May 8, 2026
Comment thread src/raitap/metrics/inputs.py Outdated
Comment thread src/raitap/utils/diagnostics.py Outdated
Comment thread src/raitap/robustness/factory.py Outdated
Comment thread src/raitap/robustness/semantics.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 38 out of 39 changed files in this pull request and generated 4 comments.

Comment thread src/raitap/utils/log.py
Comment on lines +109 to +113
)
formatted = message % args if args else message
try:
warnings.warn(formatted, category, stacklevel=stacklevel + 1)
finally:
Comment thread src/raitap/utils/log.py
Comment on lines +116 to +123
def info(self, message: object, *args: object, stacklevel: int = 2, **kwargs: Any) -> None:
"""Log at INFO level on the caller's module logger."""
_caller_logger(stacklevel).info(message, *args, stacklevel=stacklevel + 1, **kwargs)

def debug(self, message: object, *args: object, stacklevel: int = 2, **kwargs: Any) -> None:
"""Log at DEBUG level on the caller's module logger."""
_caller_logger(stacklevel).debug(message, *args, stacklevel=stacklevel + 1, **kwargs)

Comment on lines +408 to +414
hw_symbol = "⚠︎ " if is_cpu else "✓ "
if is_cpu:
docs_url = "https://caiivs.github.io/raitap/using-raitap/installation.html#execution-dependencies"
hw_text = Text.from_markup(
f"[{hw_color}]{hw_symbol}{hw_label}[/] "
f"[{hw_color} underline link={docs_url}]Use GPU[/]"
)
Comment thread src/raitap/utils/log.py
Comment on lines +1 to +6
"""Unified raitap logger: ``raitap_log.warn`` / ``.info`` / ``.debug`` / ``.error`` / ``.suppress``.

A single import surface so call sites never have to choose between
:func:`warnings.warn`, :func:`logging.info`, ``logging.getLogger(__name__)``, and
``raise``. The methods underneath dispatch to the right primitive:

@stanlrt stanlrt merged commit 11ef2f5 into main May 10, 2026
11 checks passed
@stanlrt stanlrt deleted the 123-create-the-errorwarning-tracking-logic branch May 10, 2026 00:40
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.

Create the error/warning tracking logic

3 participants