Skip to content

refactor(forecast,registry): move model family taxonomy to shared (#268)#385

Merged
w7-mgfcode merged 4 commits into
devfrom
refactor/shared-model-taxonomy
Jun 12, 2026
Merged

refactor(forecast,registry): move model family taxonomy to shared (#268)#385
w7-mgfcode merged 4 commits into
devfrom
refactor/shared-model-taxonomy

Conversation

@w7-mgfcode

@w7-mgfcode w7-mgfcode commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #268.

  • Moves ModelFamily + model_family_for to app/shared/model_taxonomy.py, breaking the registry → forecasting eager import edge (slice-cycle resolution per the cross-slice import pattern in docs/_base/ARCHITECTURE.md).
  • Promotes the registry-related lazy imports that the cycle forced to module scope.
  • Tracks the reliability E4 PRP for the shared model taxonomy under PRPs/.
  • Syncs uv.lock with the 0.2.21 release version.

Validation

  • uv run ruff check . && uv run ruff format --check .
  • uv run mypy app/ ✅ (334 files, no issues)
  • uv run pyright app/ ✅ (0 errors)
  • uv run pytest -m "not integration" ✅ (1929 passed)

Summary by Sourcery

Move the model family taxonomy into a shared module to break cross-slice import cycles and promote previously lazy cross-slice imports to module scope.

Enhancements:

  • Centralize the ModelFamily enum and model_family_for mapping in a new app/shared/model_taxonomy module and re-export them from forecasting for back-compat.
  • Simplify registry, forecasting, model_selection, and batch services by replacing lazy cross-slice imports with eager module-scope imports where safe, keeping only the intentional jobs↔forecasting lazy pair.
  • Add shared tests to lock the model taxonomy mapping, re-export identity, JSON schema contract, and cold-boot import behavior.
  • Update architecture documentation to record the resolved ModelFamily-driven cycle and the shared-type pattern for future cases.

Build:

  • Sync uv.lock with the 0.2.21 release version.

Documentation:

  • Add a PRP document describing the Reliability E4 shared model taxonomy refactor and its motivation and validation steps.

Tests:

  • Introduce a dedicated test suite for the shared model taxonomy, including subprocess-based cold-boot import probes to guard against reintroducing import cycles.

@sourcery-ai

sourcery-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Moves the ModelFamily enum and its model_type→family mapping into a shared module, removes the registry↔forecasting import cycle by updating imports and lazy-loading patterns, and adds tests and docs to lock in the new shared taxonomy and cold-boot behavior.

File-Level Changes

Change Details Files
Extract ModelFamily taxonomy into shared module and re-export from forecasting for back-compat.
  • Introduce app/shared/model_taxonomy.py defining ModelFamily, _MODEL_FAMILY_MAP, and model_family_for using shared logging.
  • Remove in-slice ModelFamily and mapping definitions from forecasting schemas/feature_metadata and replace them with imports from the shared module.
  • Add explicit re-exports of ModelFamily and model_family_for from forecasting modules to preserve existing import paths for services and tests.
app/shared/model_taxonomy.py
app/features/forecasting/schemas.py
app/features/forecasting/feature_metadata.py
Resolve registry↔forecasting import cycle by pointing registry at shared taxonomy and making registry imports into forecasting eager.
  • Change registry.schemas to import ModelFamily and model_family_for from the shared taxonomy, simplify the RunResponse.model_family computed field, and update docstrings.
  • Promote previously lazy imports of RegistryService/RunStatus and registry schemas in forecasting and model_selection services to module scope now that registry no longer imports forecasting.
  • Promote lazy JobService/JobStatus/JobCreate imports in batch.service to module scope and update comments to reflect that the alembic cycle is gone.
  • Keep jobs↔forecasting service imports lazy by design and update architecture docs to describe this as a mutual-dependency precedent and document this refactor as the resolved-cycle example.
app/features/registry/schemas.py
app/features/forecasting/service.py
app/features/model_selection/capabilities.py
app/features/model_selection/service.py
app/features/batch/service.py
docs/_base/ARCHITECTURE.md
Add tests and PRP documentation to lock the shared taxonomy behavior and cold-boot guarantees.
  • Add shared tests that verify the mapping, identity of re-exported ModelFamily/model_family_for across legacy paths, JSON schema stability, and subprocess cold-boot import probes for registry, forecasting, and app.main.
  • Record the design and validation plan for moving ModelFamily into shared in a new PRP document under PRPs/.
  • Update uv.lock to align with the 0.2.21 toolchain release used by the project.
app/shared/tests/test_model_taxonomy.py
PRPs/PRP-reliability-E4-shared-model-taxonomy.md
uv.lock

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b53be45-4271-4a1f-92d5-258095ba5405

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/shared-model-taxonomy

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.

@sourcery-ai sourcery-ai 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.

Hey - I've found 2 issues, and left some high level feedback:

  • The subprocess cold-boot probes in app/shared/tests/test_model_taxonomy.py are great for this bug class, but if you plan more shared-cycle checks it may be worth centralizing these probes into a small shared test helper or fixture to avoid duplicating the subprocess + parameterization logic across future tests.
  • Since _MODEL_FAMILY_MAP is intentionally re-exported from feature_metadata for a single drift-lock test, consider adding a short comment at the map’s new home in app/shared/model_taxonomy.py that points to that test, so future refactors understand why this private symbol is being pulled across slices.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The subprocess cold-boot probes in `app/shared/tests/test_model_taxonomy.py` are great for this bug class, but if you plan more shared-cycle checks it may be worth centralizing these probes into a small shared test helper or fixture to avoid duplicating the subprocess + parameterization logic across future tests.
- Since `_MODEL_FAMILY_MAP` is intentionally re-exported from `feature_metadata` for a single drift-lock test, consider adding a short comment at the map’s new home in `app/shared/model_taxonomy.py` that points to that test, so future refactors understand why this private symbol is being pulled across slices.

## Individual Comments

### Comment 1
<location path="app/features/model_selection/capabilities.py" line_range="133-134" />
<code_context>
     from the module-level sets. Returns the full catalog plus the documented
     default candidate set.
     """
-    # Lazy cross-slice import (mirror service.py) — avoids closing an alembic
-    # cold-boot import cycle through the forecasting slice.
-    from app.features.forecasting.feature_metadata import model_family_for
-
</code_context>
<issue_to_address>
**issue (bug_risk):** model_family_for is now undefined in build_model_catalog

`build_model_catalog` still references `model_family_for`, but that symbol is no longer defined in this module since the lazy import was removed. This will trigger a `NameError` at runtime. Please reintroduce an import for `model_family_for` (e.g., from `app.shared.model_taxonomy` at module scope or inside `build_model_catalog`).
</issue_to_address>

### Comment 2
<location path="PRPs/PRP-reliability-E4-shared-model-taxonomy.md" line_range="22-24" />
<code_context>
+2. Back-compat re-exports from the two old homes (`forecasting/schemas.py`,
+   `forecasting/feature_metadata.py`) using the redundant-alias idiom (`import X as X`) so every
+   existing importer — including both untouched test suites — keeps resolving under
+   `mypy --strict` (no-implicit-reexport).
+3. The 6 mapped lazy-import sites resolved per the verdict table below: 5 retired (promoted to
+   module scope), 1 kept-but-re-documented (the genuinely mutual jobs↔forecasting pair).
</code_context>
<issue_to_address>
**nitpick (typo):** Use the canonical mypy option name `no_implicit_reexport` for consistency.

This occurrence uses the hyphenated form `no-implicit-reexport`, while later you correctly use `no_implicit_reexport`, which matches the real config key. For consistency and to help readers map this back to `mypy.ini`/`pyproject.toml`, please switch this to `no_implicit_reexport` as well.

```suggestion
   `forecasting/feature_metadata.py`) using the redundant-alias idiom (`import X as X`) so every
   existing importer — including both untouched test suites — keeps resolving under
   `mypy --strict` (no_implicit_reexport).
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread app/features/model_selection/capabilities.py
Comment on lines +22 to +24
`forecasting/feature_metadata.py`) using the redundant-alias idiom (`import X as X`) so every
existing importer — including both untouched test suites — keeps resolving under
`mypy --strict` (no-implicit-reexport).

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.

nitpick (typo): Use the canonical mypy option name no_implicit_reexport for consistency.

This occurrence uses the hyphenated form no-implicit-reexport, while later you correctly use no_implicit_reexport, which matches the real config key. For consistency and to help readers map this back to mypy.ini/pyproject.toml, please switch this to no_implicit_reexport as well.

Suggested change
`forecasting/feature_metadata.py`) using the redundant-alias idiom (`import X as X`) so every
existing importer — including both untouched test suites — keeps resolving under
`mypy --strict` (no-implicit-reexport).
`forecasting/feature_metadata.py`) using the redundant-alias idiom (`import X as X`) so every
existing importer — including both untouched test suites — keeps resolving under
`mypy --strict` (no_implicit_reexport).

@w7-mgfcode w7-mgfcode merged commit e59cdbd into dev Jun 12, 2026
8 checks passed
@w7-mgfcode w7-mgfcode deleted the refactor/shared-model-taxonomy branch June 12, 2026 15:43
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