Skip to content

feat: replaced vulture with grimp - better deadcode detection#242

Merged
HardMax71 merged 2 commits intomainfrom
fix/deadcode-detection
Mar 1, 2026
Merged

feat: replaced vulture with grimp - better deadcode detection#242
HardMax71 merged 2 commits intomainfrom
fix/deadcode-detection

Conversation

@HardMax71
Copy link
Owner

@HardMax71 HardMax71 commented Mar 1, 2026


Summary by cubic

Switched dead code detection from Vulture to Grimp to catch orphan modules and reduce false positives. Added an orphan-check script, updated CI and pre-commit, and refactored imports to keep the module graph accurate.

  • New Features

    • Added backend/scripts/check_orphan_modules.py using grimp; whitelists app.main and skips empty package init files.
    • CI and pre-commit run the orphan check; workflow renamed to grimp.yml; docs (AGENTS.md, operations/cicd.md) now reference Grimp.
    • Replaced Vulture with Grimp in pyproject and uv.lock; removed Vulture config.
  • Refactors

    • Standardized imports: repositories via app.db; UnifiedProducer via app.events.
    • Removed unused files: backend/app/events/consumer_group_monitor.py and backend/vulture_whitelist.py.
    • Exposed repository classes in app.db.init to clarify exports and fix import errors.

Written for commit f7a261c. Summary will update on new commits.

Summary by CodeRabbit

  • Chores

    • Replaced Vulture with Grimp-based orphan-module checks across CI, pre-commit hooks and docs
    • Updated CI/CD workflows and development tooling to run the new orphan-module validation
  • Refactor

    • Consolidated backend import/export structure for repositories and event producer usage
    • Removed obsolete consumer-group monitoring scaffolding and simplified related service imports

Copilot AI review requested due to automatic review settings March 1, 2026 20:57
@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

This PR consolidates backend import paths by moving repository and producer imports from deeper modules (app.db.repositories, app.events.core) to their parent packages (app.db, app.events). It replaces Vulture dead-code detection with a Grimp-based orphan-module check (new script, CI and pre-commit changes) and removes the consumer_group_monitor.py module.

Changes

Cohort / File(s) Summary
Dead Code Detection Tool Migration
.github/workflows/grimp.yml, .pre-commit-config.yaml, backend/pyproject.toml, backend/scripts/check_orphan_modules.py, backend/vulture_whitelist.py, AGENTS.md, docs/operations/cicd.md
Replaces Vulture with Grimp: CI/workflow and pre-commit hooks updated to run backend/scripts/check_orphan_modules.py; Vulture config/whitelist removed; new Grimp-based script detects orphan modules and exits nonzero when found.
Repository Export/Import Consolidation
backend/app/db/__init__.py, backend/app/db/repositories/__init__.py, backend/app/core/providers.py, backend/app/dlq/manager.py, backend/app/services/admin/*, backend/app/services/*, backend/app/services/saga/*, backend/app/services/result_processor/processor.py, backend/app/services/saved_script_service.py, backend/app/services/sse/sse_service.py, backend/app/services/user_settings_service.py
Re-exports and updates imports to expose repository classes at app.db (instead of app.db.repositories) and updates modules to import repositories from app.db. __init__.py updated to include added exports (AdminEventsRepository, DLQRepository, ResourceAllocationRepository).
Event Producer Import Consolidation
backend/app/core/providers.py, backend/app/services/auth_service.py, backend/app/services/event_replay/replay_service.py, backend/app/services/execution_service.py, backend/app/services/k8s_worker/worker.py, backend/app/services/kafka_event_service.py, backend/app/services/saga/..., backend/app/events/core/producer.py
Moves UnifiedProducer and related imports from app.events.core to app.events; producer module also updated to import EventRepository from consolidated app.db.
Module Deletion
backend/app/events/consumer_group_monitor.py
Removes the entire consumer group monitor module, including ConsumerGroupHealth/State enums, dataclasses (ConsumerGroupMember, ConsumerGroupStatus, DescribedGroup), and parsing/helper functions for Kafka describe-groups/member-assignment handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • (none with a strong code-level connection found in the provided list)

Poem

🐰
I hopped through imports, light and spry,
Pulling paths one layer high,
Grimp sniffed out the lonely files,
Vulture slept across the piles,
Now the codebase naps — no why.

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: replacing Vulture with Grimp for dead-code detection. It accurately reflects the primary objective and core changes throughout the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/deadcode-detection

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.

@codecov-commenter
Copy link

codecov-commenter commented Mar 1, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Flag Coverage Δ
backend-e2e 83.04% <100.00%> (+0.63%) ⬆️
backend-unit 67.96% <100.00%> (+0.52%) ⬆️
frontend-unit 86.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
backend/app/core/providers.py 94.92% <100.00%> (ø)
backend/app/db/__init__.py 100.00% <ø> (ø)
backend/app/db/repositories/__init__.py 100.00% <100.00%> (ø)
backend/app/dlq/manager.py 45.00% <100.00%> (ø)
backend/app/events/core/producer.py 78.26% <100.00%> (ø)
backend/app/services/admin/admin_events_service.py 79.86% <100.00%> (ø)
...kend/app/services/admin/admin_execution_service.py 100.00% <100.00%> (ø)
...ckend/app/services/admin/admin_settings_service.py 100.00% <100.00%> (ø)
backend/app/services/admin/admin_user_service.py 100.00% <100.00%> (ø)
backend/app/services/auth_service.py 93.26% <100.00%> (ø)
... and 15 more
Components Coverage Δ
Backend 90.14% <100.00%> (+0.69%) ⬆️
Frontend 86.78% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 34 files

Copy link

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 replaces Vulture-based dead-code detection with a Grimp-based “orphan module” check in the backend CI/tooling, and refactors backend imports to use app.db / app.events re-export facades.

Changes:

  • Swap Vulture CI/docs/pre-commit configuration for a Grimp orphan-module check, implemented via a new backend script.
  • Remove the Vulture whitelist/config and the (now-unused) consumer_group_monitor module.
  • Refactor many backend imports to use from app.db import … and from app.events import UnifiedProducer.

Reviewed changes

Copilot reviewed 33 out of 34 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/operations/cicd.md Updates CI diagram/docs to reference Grimp and the new local command.
backend/vulture_whitelist.py Removes Vulture whitelist file (no longer needed).
backend/uv.lock Adds grimp and removes vulture from the lockfile/groups.
backend/scripts/check_orphan_modules.py Adds Grimp-based orphan module detection script used by CI/pre-commit.
backend/pyproject.toml Replaces vulture dependency/config with grimp and removes vulture-specific exclusions.
backend/app/services/user_settings_service.py Switches repository import to app.db facade.
backend/app/services/sse/sse_service.py Switches repository import to app.db facade.
backend/app/services/saved_script_service.py Switches repository import to app.db facade.
backend/app/services/saga/saga_service.py Switches repository imports to app.db facade.
backend/app/services/saga/saga_orchestrator.py Switches repository imports to app.db facade and producer import to app.events.
backend/app/services/saga/execution_saga.py Switches repository import to app.db facade and producer import to app.events.
backend/app/services/runtime_settings.py Switches repository import to app.db facade.
backend/app/services/result_processor/processor.py Switches repository import to app.db facade and producer import to app.events.
backend/app/services/notification_service.py Switches repository import to app.db facade.
backend/app/services/notification_scheduler.py Switches repository import to app.db facade.
backend/app/services/kafka_event_service.py Switches producer import to app.events.
backend/app/services/k8s_worker/worker.py Switches producer import to app.events.
backend/app/services/execution_service.py Switches repository import to app.db facade and producer import to app.events.
backend/app/services/event_service.py Switches repository import to app.db facade.
backend/app/services/event_replay/replay_service.py Switches repository import to app.db facade and producer import to app.events.
backend/app/services/auth_service.py Switches repository import to app.db facade and producer import to app.events.
backend/app/services/admin/admin_user_service.py Switches repository import to app.db facade.
backend/app/services/admin/admin_settings_service.py Switches repository import to app.db facade.
backend/app/services/admin/admin_execution_service.py Switches repository import to app.db facade.
backend/app/services/admin/admin_events_service.py Switches repository import to app.db facade.
backend/app/events/core/producer.py Switches repository import to app.db facade.
backend/app/events/consumer_group_monitor.py Removes unused module (consistent with orphan-module cleanup).
backend/app/dlq/manager.py Switches repository import to app.db facade.
backend/app/db/repositories/init.py Refactors admin repository imports via app.db.repositories.admin.
backend/app/db/init.py Expands/maintains app.db re-export surface used by updated imports.
backend/app/core/providers.py Switches imports to app.db and app.events facades.
AGENTS.md Updates developer commands/docs from Vulture to the new Grimp script.
.pre-commit-config.yaml Replaces Vulture hook with Grimp orphan-module check hook.
.github/workflows/grimp.yml Adds Grimp workflow to run the orphan-module check in CI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@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: 1

🧹 Nitpick comments (2)
backend/pyproject.toml (1)

146-146: Consider pinning grimp to a specific version for reproducible builds.

The dependency uses grimp>=3.14 which allows automatic patch and minor version upgrades. Other lint dependencies in this file (mypy, ruff) are pinned to exact versions (e.g., mypy==1.19.1, ruff==0.14.10). For consistency and to prevent unexpected breaking changes in CI, consider using grimp==3.14 instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/pyproject.toml` at line 146, Replace the loose dependency spec
"grimp>=3.14" in pyproject.toml with a pinned exact version to ensure
reproducible builds; update the entry "grimp>=3.14" to "grimp==3.14" so it
matches the pinning style used for other linters (e.g., mypy==1.19.1,
ruff==0.14.10).
backend/scripts/check_orphan_modules.py (1)

21-22: Add Google-style docstrings for function compliance.

_is_empty_init() and main() should include Google-style docstrings with explicit Args/Returns sections.

As per coding guidelines, "Use Google-style docstrings with Args/Returns/Raises sections for all functions and classes".

Also applies to: 35-35

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/scripts/check_orphan_modules.py` around lines 21 - 22, Add
Google-style docstrings to both _is_empty_init(module: str) and main()
describing purpose, parameters, return values and exceptions; for _is_empty_init
include an Args section documenting module: str and a Returns section indicating
bool, and mention any raised exceptions in Raises (e.g.,
IOError/FileNotFoundError if you open files); for main include Args (if any),
Returns (e.g., exit code or None) and Raises for uncaught exceptions. Ensure the
docstrings follow Google style with a short summary line, a blank line, then
Args/Returns/Raises sections and place them immediately under the function
definitions for _is_empty_init and main.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/scripts/check_orphan_modules.py`:
- Around line 27-32: The helper _is_empty_init currently treats any string
literal lines as meaningful which misclassifies docstring-only __init__.py
files; update _is_empty_init to parse the source with ast.parse and treat a
module as empty if, after removing the module-level docstring (an ast.Expr of
ast.Str/ast.Constant containing a string) there are no remaining significant
nodes; specifically, in _is_empty_init use ast.parse(source) and consider the
module empty when all nodes in module.body are either the docstring Expr or are
pass/empty constructs (or simply check that no node remains that is not a
module-level docstring), ensuring comments/whitespace are ignored and only
executable statements mark the file as non-empty.

---

Nitpick comments:
In `@backend/pyproject.toml`:
- Line 146: Replace the loose dependency spec "grimp>=3.14" in pyproject.toml
with a pinned exact version to ensure reproducible builds; update the entry
"grimp>=3.14" to "grimp==3.14" so it matches the pinning style used for other
linters (e.g., mypy==1.19.1, ruff==0.14.10).

In `@backend/scripts/check_orphan_modules.py`:
- Around line 21-22: Add Google-style docstrings to both _is_empty_init(module:
str) and main() describing purpose, parameters, return values and exceptions;
for _is_empty_init include an Args section documenting module: str and a Returns
section indicating bool, and mention any raised exceptions in Raises (e.g.,
IOError/FileNotFoundError if you open files); for main include Args (if any),
Returns (e.g., exit code or None) and Raises for uncaught exceptions. Ensure the
docstrings follow Google style with a short summary line, a blank line, then
Args/Returns/Raises sections and place them immediately under the function
definitions for _is_empty_init and main.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef85eeb and 3588638.

⛔ Files ignored due to path filters (1)
  • backend/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (33)
  • .github/workflows/grimp.yml
  • .pre-commit-config.yaml
  • AGENTS.md
  • backend/app/core/providers.py
  • backend/app/db/__init__.py
  • backend/app/db/repositories/__init__.py
  • backend/app/dlq/manager.py
  • backend/app/events/consumer_group_monitor.py
  • backend/app/events/core/producer.py
  • backend/app/services/admin/admin_events_service.py
  • backend/app/services/admin/admin_execution_service.py
  • backend/app/services/admin/admin_settings_service.py
  • backend/app/services/admin/admin_user_service.py
  • backend/app/services/auth_service.py
  • backend/app/services/event_replay/replay_service.py
  • backend/app/services/event_service.py
  • backend/app/services/execution_service.py
  • backend/app/services/k8s_worker/worker.py
  • backend/app/services/kafka_event_service.py
  • backend/app/services/notification_scheduler.py
  • backend/app/services/notification_service.py
  • backend/app/services/result_processor/processor.py
  • backend/app/services/runtime_settings.py
  • backend/app/services/saga/execution_saga.py
  • backend/app/services/saga/saga_orchestrator.py
  • backend/app/services/saga/saga_service.py
  • backend/app/services/saved_script_service.py
  • backend/app/services/sse/sse_service.py
  • backend/app/services/user_settings_service.py
  • backend/pyproject.toml
  • backend/scripts/check_orphan_modules.py
  • backend/vulture_whitelist.py
  • docs/operations/cicd.md
💤 Files with no reviewable changes (2)
  • backend/app/events/consumer_group_monitor.py
  • backend/vulture_whitelist.py

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 1, 2026

Copy link

@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 `@backend/scripts/check_orphan_modules.py`:
- Around line 22-27: Add full Google-style docstrings for both _is_empty_init
and main: for _is_empty_init(module: str) include a short summary, an Args
section documenting module (path or module name), a Returns section stating it
returns bool indicating whether the module __init__.py contains only an optional
module docstring and no other statements, and a Raises section if you
expect/handle exceptions (e.g., SyntaxError from ast.parse) or omit Raises if
none. For main(), add a summary and Args (if it accepts CLI args or uses none),
a Returns section describing the exit code or None, and a Raises section for any
exceptions that propagate; ensure both docstrings follow Google-style headings
exactly ("Args:", "Returns:", "Raises:") and reference behavior found in the
existing function logic (use of AST inspection in _is_empty_init and script
entry behavior in main).
- Around line 28-31: The code builds init_path relative to the current working
directory which makes detection flaky; instead resolve package paths relative to
the script location. Change the logic that computes init_path (currently using
Path(module.replace(".", "/")) / "__init__.py") to base the path off the script
directory (e.g. Path(__file__).parent.resolve()) and then join
module.replace(".", "/") and "__init__.py"; keep using init_path.is_file() and
init_path.read_text() unchanged. This ensures init_path and the empty-package
detection are deterministic in CI/pre-commit runs.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3588638 and f7a261c.

📒 Files selected for processing (1)
  • backend/scripts/check_orphan_modules.py

@HardMax71 HardMax71 merged commit d31dfd3 into main Mar 1, 2026
18 checks passed
@HardMax71 HardMax71 deleted the fix/deadcode-detection branch March 1, 2026 21:20
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.

3 participants