Skip to content

Conversation

@markovejnovic
Copy link
Contributor

Summary

  • Add _clone_class() helper that rebuilds class methods with shared clean_globals and __module__ = "__mp_main__" so cloudpickle serializes classes by value instead of by reference
  • Extend _make_picklable() to detect and clone classes from the test module alongside functions
  • Handles regular methods, staticmethod, classmethod, property, inheritance, and cross-class references

Test Plan

  • test_module_level_class — basic class instantiation inside container
  • test_class_inheritance — inheritance, property, staticmethod, classmethod
  • test_class_referencing_another_class — class method instantiating another module-level class
  • Full test suite (16/16 passing)
  • ruff check passes
  • pyright passes

@mesa-dot-dev
Copy link

mesa-dot-dev bot commented Feb 9, 2026

Mesa Description

Summary

  • Refactored _container.py to simplify serialization and add support for pickling module-level classes, enabling them to be used inside the test container.
  • Replaced the complex _make_picklable helper with a more direct approach using cloudpickle.register_pickle_by_value to serialize the test module by value.
  • The new implementation handles various class features, including inheritance, properties, staticmethod, classmethod, and inter-class references.
  • Added new linter ignore rules in pyproject.toml for the new, comprehensive class support tests.

Test Plan

  • test_module_level_class — basic class instantiation inside container
  • test_class_inheritance — inheritance, property, staticmethod, classmethod
  • test_class_referencing_another_class — class method instantiating another module-level class
  • Full test suite (16/16 passing)
  • ruff check passes
  • pyright passes

Description generated by Mesa. Update settings

@markovejnovic
Copy link
Contributor Author

/review

Copy link

@mesa-dot-dev mesa-dot-dev bot left a comment

Choose a reason for hiding this comment

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

Performed full review of b147318...a21e1bd

Analysis

  1. The class cloning implementation breaks Python inheritance semantics by recreating base classes without memoization, potentially breaking identity checks and altering method resolution order.

  2. The implementation ignores metaclasses by always using the default type, which can lead to unexpected behavior for classes that depend on custom metaclasses.

  3. Descriptor instances and nested classes are copied verbatim with references to original module state, creating potential for subtle runtime divergence.

  4. Missing key architectural components: a caching mechanism for cloned classes, proper metaclass-aware construction, and an escape hatch for module-dependent objects.

Tip

Help

Slash Commands:

  • /review - Request a full code review
  • /review latest - Review only changes since the last review
  • /describe - Generate PR description. This will update the PR body or issue comment depending on your configuration
  • /help - Get help with Mesa commands and configuration options

3 files reviewed | 2 comments | Edit Agent SettingsRead Docs

Copy link

@mesa-dot-dev mesa-dot-dev bot left a comment

Choose a reason for hiding this comment

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

Performed full review of b147318...a21e1bd

Analysis

  1. The class cloning approach in _make_picklable lacks memoization, potentially breaking shared identities and method resolution order (MRO) in complex class hierarchies.

  2. The current implementation ignores metaclasses when rebuilding classes, which could break functionality for classes that depend on specific metaclass behavior.

  3. The indiscriminate attribute copying doesn't respect descriptor protocols, risking incorrect state propagation for properties and other descriptor-based attributes.

  4. The solution may work for simple classes but likely fails with advanced Python features (metaclasses, descriptors, complex inheritance) that aren't covered by the current test cases.

Tip

Help

Slash Commands:

  • /review - Request a full code review
  • /review latest - Review only changes since the last review
  • /describe - Generate PR description. This will update the PR body or issue comment depending on your configuration
  • /help - Get help with Mesa commands and configuration options

3 files reviewed | 2 comments | Edit Agent SettingsRead Docs

@markovejnovic markovejnovic changed the title feat: Support class serialization in _make_picklable bug: Support class serialization in _make_picklable Feb 9, 2026
@markovejnovic markovejnovic merged commit e47aacd into main Feb 9, 2026
3 checks passed
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