fix(telemetry): break helpers->core import cycle so metrics plugins register#1180
Open
ajbozarth wants to merge 1 commit into
Open
fix(telemetry): break helpers->core import cycle so metrics plugins register#1180ajbozarth wants to merge 1 commit into
ajbozarth wants to merge 1 commit into
Conversation
…egister mellea/helpers loaded mellea.core at module level, creating a cycle when mellea.core.utils -> mellea.telemetry -> metrics' bottom-of-module registration -> mellea.helpers ran during core init. The except ImportError swallowed the cycle as "plugin framework is not installed", so MELLEA_METRICS_ENABLED=true registered zero plugins in production. Move helpers' core imports under TYPE_CHECKING or into function bodies, and replace the except ImportError with an explicit _HAS_PLUGIN_FRAMEWORK check so future cycle-shape regressions surface loudly. Closes generative-computing#1079. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
Contributor
Author
|
So while wrapping up work on phase 1 of #444 I discovered a chicken and egg issue with registering plugins that makes fully lazy init not work. In addition I found that this bug also affected the tracing work. So I decided to quickly open this bug fix since it was more severe than I thought (essentially metrics has been non-functional since I switched it to use hooks). The remaining items in #1079 are now |
This was referenced Jun 1, 2026
Open
planetf1
approved these changes
Jun 2, 2026
Contributor
planetf1
left a comment
There was a problem hiding this comment.
LGTM — reproduced on the parent (0 plugins), confirmed all 8 register here.
Two non-blocking follow-ups:
metrics_plugins.py:18importsfrom mellea.core.base import GenerationMetadataat module level — the same cycle this PR fixes, safe only becausecore/__init__.pyimports.basebefore.utils. If that order ever changes the cycle reopens, now silently (since this PR removes the loud failure). Worth a follow-up to make plugin registration lazy and drop the dependency on import order.- A regression test in
test/package/test_dependency_isolation.py(already runs isolated interpreters) asserting the plugin count is non-zero with metrics enabled would help — the existing plugin tests use mocks, so they couldn't catch this failure mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Fixes #1079
Description
mellea/helpers loaded mellea.core at module level, creating a cycle when
mellea.core.utils -> mellea.telemetry -> metrics' bottom-of-module registration -> mellea.helpersran during core init. Theexcept ImportErrorswallowed the cycle as "plugin framework is not installed", soMELLEA_METRICS_ENABLED=trueregistered zero plugins in production.helpers/async_helpers.pyandopenai_compatible_helpers.py: move core imports underTYPE_CHECKINGor into function bodies.telemetry/metrics.py: replaceexcept ImportErrorwith explicit_HAS_PLUGIN_FRAMEWORKcheck; move registration block below__all__.The lazy-init migration originally scoped in #1079 is declined in favor of eager-parity with the upcoming tracing plugin design.
Testing
Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.