Skip to content

cleanup: dedup Alert/#109 + deprecate gradata.patterns shim/#110#114

Merged
Gradata merged 4 commits intomainfrom
fix/consolidation-cleanup
Apr 19, 2026
Merged

cleanup: dedup Alert/#109 + deprecate gradata.patterns shim/#110#114
Gradata merged 4 commits intomainfrom
fix/consolidation-cleanup

Conversation

@Gradata
Copy link
Copy Markdown
Owner

@Gradata Gradata commented Apr 19, 2026

Summary

Council-decided narrow cleanup PR, extracted from autoresearch/consolidation (PR #112 will be closed in favor of this one). Three commits:

  1. ca45ec32 — refactor(consolidation: unify duplicate Alert dataclass (quality_monitoring vs scoring/failure_detectors) #109): strip duplicate Alert/detect_failures from quality_monitoring
    Removed the older 3-field Alert + 4 detector functions + detect_failures + format_alerts + BLANDNESS_THRESHOLD from quality_monitoring.py. Canonical 4-field impl (with evidence: dict) lives in scoring/failure_detectors.py. Zero external callers of the stripped surface.

  2. bca932dc — test(consolidation: unify duplicate Alert dataclass (quality_monitoring vs scoring/failure_detectors) #109): update test_4_failure_detectors_exist to canonical module
    Points the SPEC compliance test at scoring.failure_detectors instead of quality_monitoring.

  3. 6bafb89f — feat(consolidation: decide fate of hollow patterns/ shim vs canonical contrib/patterns/ #110): deprecate gradata.patterns shim + strengthen consolidation: unify duplicate Alert dataclass (quality_monitoring vs scoring/failure_detectors) #109 guard

Council verdict (6-perspective, full mode)

Decision 1 (PR #112 strategy): 5× A, 1× D — cherry-pick safe commits to narrow PR off main. ✅ This PR.
Decision 2 (patterns/ shim): 4× B, 1× A, 1× D — DeprecationWarning + remove at v0.8.0. ✅ Done.

Addenda honored

  • Architect: verify symbol identity post-cherry-pick → added __module__ + evidence field assertions.
  • User Advocate / Temporal: runtime warning not just docs → DeprecationWarning fires in __getattr__, not only in the docstring.
  • Skeptic: don't trust agent's self-attestation of 322 cosmetic commits → this PR deliberately drops them.

Closes

Test plan

  • pytest tests/test_spec_compliance.py — 59 passed
  • pytest tests/test_bug_fixes.py -k pattern — 1 passed
  • pytest tests/test_bug_fixes.py::TestSDKExports::test_patterns_shim_emits_deprecation_warning — passes (new)
  • pytest tests/test_adaptations.py tests/test_failure_detectors_coverage.py — 312 passed
  • CI green on 3.11/3.12/3.13
  • v0.6.x release notes: add "gradata.patterns is deprecated, scheduled for removal in v0.8.0"

Generated with Gradata

Gradata and others added 3 commits April 19, 2026 13:16
…nitoring

quality_monitoring.py carried an older, simpler copy of Alert +
detect_failures + 4 detectors + format_alerts that parallel
scoring/failure_detectors.py. No external callers — only self-references
inside the module and its own __all__.

scoring/failure_detectors is the canonical impl:
- Alert has 4 fields (adds `evidence: dict`) vs. 3 here
- Proper warning/critical severity escalation (this version only warned)
- Field usage matches current MetricsWindow contract

Scope of removal from quality_monitoring.py:
- Alert dataclass
- BLANDNESS_THRESHOLD constant
- detect_being_ignored / detect_playing_safe / detect_overfitting /
  detect_regression_to_mean / detect_failures / format_alerts
- Trimmed __all__ to just the anti-pattern surface
- Updated module docstring to point at scoring/failure_detectors

Kept (no duplicate, single impl): AntiPattern, AntiPatternDetector,
Detection, DEFAULT_PATTERNS, DEFAULT_ANTI_PATTERNS, _compile_anti_pattern.

Tests: 312 passed in test_adaptations.py + test_failure_detectors_coverage.py.
Import smoke: AntiPatternDetector() still registers 13 default patterns.

Closes #109.

Co-Authored-By: Gradata <noreply@gradata.ai>
After 5b47d92 stripped detect_* functions from quality_monitoring.py,
the SPEC compliance test asserted their presence on the wrong module.
Pointing it at scoring/failure_detectors where they live canonically.

Verified: test passes. Other failures in the full suite
(test_agent_precontext_*, test_cli_export_*, test_runner_invokes_*)
are pre-existing environmental flakes (live brain DB drift and Windows
cp1252 encoding) unrelated to this branch.

Co-Authored-By: Gradata <noreply@gradata.ai>
Council-decided (6-perspective, full mode). Two decisions:

1) gradata.patterns shim (#110): DeprecationWarning + remove at v0.8.0.
   - Runtime warning (not just docs) so users who pin versions and never
     read changelogs get the signal before the shim disappears.
   - Mirrors the deprecation cadence already set for gradata.integrations
     (also scheduled for v0.8.0 per #111).
   - Module-level _WARNED flag ensures one warning per process, not one
     per attribute access.
   - Council minority (Pragmatist) preferred 'keep indefinitely'; majority
     (Architect, Skeptic, Temporal, User Advocate) favored deprecation
     cycle. User Advocate's caveat — pair with release note — applies at
     release time.

2) #109 dedup guard: lock Alert identity in test_4_failure_detectors_exist.
   - Assert Alert.__module__ resolves to scoring.failure_detectors and
     that the evidence field is present — prevents accidental
     re-introduction of the stripped 3-field duplicate.
   - Addresses Architect's verification caveat: passing tests don't prove
     symbol identity; explicit __module__ assertion does.

New test: test_patterns_shim_emits_deprecation_warning — guards against
the DeprecationWarning being silently removed. Asserts both that the
warning fires AND that it contains "v0.8.0" + "gradata.contrib.patterns"
so the message stays actionable.

Tests: 19/19 pattern + spec tests pass.

Co-Authored-By: Gradata <noreply@gradata.ai>
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Gradata has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6e5a69d1-ca04-4f49-be5e-43e8f0161fef

📥 Commits

Reviewing files that changed from the base of the PR and between 6bafb89 and 1b2f032.

📒 Files selected for processing (2)
  • src/gradata/patterns/__init__.py
  • tests/test_bug_fixes.py

📝 Walkthrough
  • Removed duplicate 3-field Alert and related failure-detector surface from gradata.enhancements.quality_monitoring; the canonical 4-field Alert (with evidence: dict) and all detector implementations now live in gradata.enhancements.scoring.failure_detectors.
  • Updated tests to import detectors from gradata.enhancements.scoring.failure_detectors and added assertions that Alert.module is the failure_detectors module and that Alert includes an evidence field.
  • Deprecates the top-level gradata.patterns shim: first attribute access now emits a DeprecationWarning (message directs users to gradata.contrib.patterns / gradata.rules) and removal is scheduled for v0.8.0; warning is emitted once per process.
  • Added tests to ensure the patterns shim emits the DeprecationWarning and forwards symbols to gradata.contrib.patterns/gradata.rules.
  • Quality_monitoring module docstring updated to point callers to scoring.failure_detectors; AntiPattern APIs remain unchanged.
  • Tests and test helpers reformatted and strengthened (minor non-functional formatting changes across tests/test_bug_fixes.py and tests/test_spec_compliance.py).
  • No security fixes included.
  • Breaking changes: any code importing Alert or the detector functions (detect_being_ignored, detect_playing_safe, detect_overfitting, detect_regression_to_mean, detect_failures, format_alerts) from gradata.enhancements.quality_monitoring must migrate imports to gradata.enhancements.scoring.failure_detectors.
  • Deprecation (non-breaking for now): imports from gradata.patterns will continue to work but will emit a runtime DeprecationWarning; update imports to gradata.contrib.patterns or gradata.rules before v0.8.0.

Walkthrough

This PR removes the duplicate Alert/alerting surface from quality_monitoring, points failure detection to gradata.enhancements.scoring.failure_detectors, converts gradata.patterns into a deprecated shim that warns on first attribute access, and updates tests to validate the reorganization and deprecation behavior.

Changes

Cohort / File(s) Summary
Quality Monitoring Module
src/gradata/enhancements/quality_monitoring.py
Removed exported failure/regression alerting surface (BLANDNESS_THRESHOLD, Alert, detection functions, format helpers) and related typing import; updated module docstring and reformatted class/dataclass/constructor layout (format-only changes to AntiPatternDetector).
Patterns Deprecation Shim
src/gradata/patterns/__init__.py
Made shim emit a single-process DeprecationWarning on first attribute access (module _WARNED flag); preserved lazy forwarding to gradata.contrib.patterns and fallback to gradata.rules.
Tests — Spec Compliance
tests/test_spec_compliance.py
Updated import to gradata.enhancements.scoring.failure_detectors; added assertions that Alert comes from the new module and includes an evidence field.
Tests — Bug Fixes
tests/test_bug_fixes.py
Reworked tests to exercise the deprecated gradata.patterns shim under warnings.catch_warnings, added test_patterns_shim_emits_deprecation_warning, and made minor formatting/fixture formatting tweaks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: deduplication of the Alert dataclass (#109) and deprecation of the patterns shim (#110), directly reflecting the changeset's core objectives.
Description check ✅ Passed The description provides comprehensive context: three commits are documented with clear intent, council decisions and addenda are honored, and the relationship to linked issues #109 and #110 is explicitly established.
Linked Issues check ✅ Passed All coding requirements from #109 and #110 are met: duplicate Alert is removed from quality_monitoring [#109], canonical Alert in scoring/failure_detectors is preserved [#109], tests updated [#109], patterns shim now emits DeprecationWarning [#110], removal scheduled for v0.8.0 [#110], test guards prevent re-introduction [#109].
Out of Scope Changes check ✅ Passed All changes are directly within scope: Alert deduplication and patterns deprecation from the linked issues; test updates and formatting in quality_monitoring/patterns/init.py/test files; no unrelated refactors or feature additions detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 fix/consolidation-cleanup

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@src/gradata/patterns/__init__.py`:
- Around line 15-17: Add "from __future__ import annotations" at the very top of
this module (before any other imports) so type annotations are postponed across
the core SDK; update src/gradata/patterns/__init__.py by inserting that future
import above the existing import warnings and keep the existing _WARNED variable
and imports unchanged.

In `@tests/test_bug_fixes.py`:
- Around line 387-409: The test test_patterns_shim_emits_deprecation_warning
collects warnings in caught but currently inspects deprecations[0] which may be
an unrelated DeprecationWarning; update the test to filter caught for
DeprecationWarning entries whose message contains the shim-specific text (e.g.
"gradata.contrib.patterns" or "v0.8.0") and then assert that this filtered list
is non-empty and that its first element's message contains the expected
substrings; reference the local variables caught and deprecations (or rename to
filtered_deprecations) and perform assertions on that filtered list instead of
deprecations[0].
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 782282ff-ef5c-4d52-b49c-539bdccb1e92

📥 Commits

Reviewing files that changed from the base of the PR and between f237534 and 6bafb89.

📒 Files selected for processing (4)
  • src/gradata/enhancements/quality_monitoring.py
  • src/gradata/patterns/__init__.py
  • tests/test_bug_fixes.py
  • tests/test_spec_compliance.py
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
tests/**

⚙️ CodeRabbit configuration file

tests/**: Test files. Verify: no hardcoded paths, assertions check specific values not just truthiness,
parametrized tests preferred for boundary conditions, floating point comparisons use pytest.approx.

Files:

  • tests/test_spec_compliance.py
  • tests/test_bug_fixes.py
src/gradata/**/*.py

⚙️ CodeRabbit configuration file

src/gradata/**/*.py: This is the core SDK. Check for: type safety (from future import annotations required), no print()
statements (use logging), all functions accepting BrainContext where DB access occurs, no hardcoded paths. Severity
scoring must clamp to [0,1]. Confidence values must be in [0.0, 1.0].

Files:

  • src/gradata/patterns/__init__.py
  • src/gradata/enhancements/quality_monitoring.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: Gradata
Repo: Gradata/gradata PR: 0
File: :0-0
Timestamp: 2026-04-17T17:18:07.417Z
Learning: In PR `#102` (gradata/gradata), Round 2 addressed: cli.py env-first brain resolution (GRADATA_BRAIN > --brain-dir > cwd), _tenant.py corrupt .tenant_id overwrite, _env_int default clamping to minimum, and _events.py tenant-scoped fallback SELECT for dedup. All ruff and 99 tests green after these fixes.
📚 Learning: 2026-04-17T17:18:07.417Z
Learnt from: Gradata
Repo: Gradata/gradata PR: 0
File: :0-0
Timestamp: 2026-04-17T17:18:07.417Z
Learning: In PR `#102` (gradata/gradata), Round 2 addressed: cli.py env-first brain resolution (GRADATA_BRAIN > --brain-dir > cwd), _tenant.py corrupt .tenant_id overwrite, _env_int default clamping to minimum, and _events.py tenant-scoped fallback SELECT for dedup. All ruff and 99 tests green after these fixes.

Applied to files:

  • tests/test_bug_fixes.py
🪛 Ruff (0.15.10)
src/gradata/patterns/__init__.py

[warning] 20-20: Missing return type annotation for private function __getattr__

(ANN202)


[warning] 21-21: Using the global statement to update _WARNED is discouraged

(PLW0603)

src/gradata/enhancements/quality_monitoring.py

[warning] 194-194: Boolean-typed positional argument in function definition

(FBT001)


[warning] 194-194: Boolean default positional argument in function definition

(FBT002)

tests/test_bug_fixes.py

[warning] 339-339: Boolean positional value in function call

(FBT003)

🔇 Additional comments (4)
src/gradata/patterns/__init__.py (1)

22-29: Deprecation shim behavior looks correct.

One-time warning emission and two-step forwarding (gradata.contrib.patterns then gradata.rules) are implemented cleanly and match the deprecation intent.

Also applies to: 33-43

tests/test_bug_fixes.py (1)

354-378: Good coverage for deprecated shim forwarding.

This import matrix meaningfully guards that gradata.patterns still forwards key symbols during deprecation.

tests/test_spec_compliance.py (1)

202-213: Canonical Alert guard is well-implemented.

The module-path assertion plus evidence field check is a strong regression guard against reintroducing the older 3-field Alert.

src/gradata/enhancements/quality_monitoring.py (1)

1-7: Cleanup aligns with consolidation and keeps behavior intact.

The docstring/API ownership clarification and local formatting refactors are clean and consistent with the Alert de-duplication objective.

Also applies to: 193-221

Comment on lines +15 to +17
import warnings

_WARNED = False
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify core SDK files that miss the required future-annotations import.
fd -e py . src/gradata | while read -r f; do
  head -n 30 "$f" | rg -q '^from __future__ import annotations$' || echo "missing: $f"
done

Repository: Gradata/gradata

Length of output: 3074


🏁 Script executed:

head -n 50 src/gradata/patterns/__init__.py

Repository: Gradata/gradata

Length of output: 1324


Add from __future__ import annotations to this core SDK module.

Line 15 begins regular imports, but this file is missing the required future-annotations import used across src/gradata/**/*.py.

🔧 Proposed fix
+from __future__ import annotations
+
 import warnings

As per coding guidelines: "src/gradata/**/*.py: This is the core SDK. Check for: type safety (from future import annotations required)".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import warnings
_WARNED = False
from __future__ import annotations
import warnings
_WARNED = False
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gradata/patterns/__init__.py` around lines 15 - 17, Add "from __future__
import annotations" at the very top of this module (before any other imports) so
type annotations are postponed across the core SDK; update
src/gradata/patterns/__init__.py by inserting that future import above the
existing import warnings and keep the existing _WARNED variable and imports
unchanged.

Comment thread tests/test_bug_fixes.py Outdated
…t warning filter

- Add `from __future__ import annotations` to patterns shim (SDK type-safety rule)
- Move sys.modules.pop + reimport inside catch_warnings block so the shim
  DeprecationWarning is actually captured; filter caught list for shim-specific
  text before asserting, eliminating false-positive on unrelated DeprecationWarnings

Co-Authored-By: Gradata <noreply@gradata.ai>
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Gradata has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@Gradata Gradata merged commit 2b1172f into main Apr 19, 2026
1 check was pending
Gradata added a commit that referenced this pull request Apr 19, 2026
Covers: gradata.patterns deprecation (remove in v0.8.0), Alert dedup (#109),
Meta-Harness A-D, multi-tenant SDK (#102), BM25 JIT ranking (#101),
gradata seed/mine CLI, rule_verifier wiring, security hardening, and 67+66
ruff-violation fixes (#100, #103).

Co-Authored-By: Gradata <noreply@gradata.ai>
Gradata added a commit that referenced this pull request Apr 19, 2026
Covers: gradata.patterns deprecation (remove in v0.8.0), Alert dedup (#109),
Meta-Harness A-D, multi-tenant SDK (#102), BM25 JIT ranking (#101),
gradata seed/mine CLI, rule_verifier wiring, security hardening, and 67+66
ruff-violation fixes (#100, #103).

Co-Authored-By: Gradata <noreply@gradata.ai>
Gradata added a commit that referenced this pull request Apr 20, 2026
* docs: v0.6.1 changelog entry covering post-v0.6.0 work through PR #114

Covers: gradata.patterns deprecation (remove in v0.8.0), Alert dedup (#109),
Meta-Harness A-D, multi-tenant SDK (#102), BM25 JIT ranking (#101),
gradata seed/mine CLI, rule_verifier wiring, security hardening, and 67+66
ruff-violation fixes (#100, #103).

Co-Authored-By: Gradata <noreply@gradata.ai>

* docs(changelog): qualify env-centralization claim

CodeRabbit flagged that GRADATA_RULE_VERIFIER is still read directly in
rule_pipeline.py. Weaken the claim rather than block on the migration.

Co-Authored-By: Gradata <noreply@gradata.ai>

---------

Co-authored-by: Gradata <noreply@gradata.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant