Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #224 +/- ##
=======================================
Coverage 92.02% 92.03%
=======================================
Files 19 19
Lines 1681 1683 +2
=======================================
+ Hits 1547 1549 +2
Misses 134 134 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…to wrapped step() Fixes a bug where pre_step/post_step are called twice per step when a subclass defines only step() and is executed via astep() during parallel stepping. Stores raw user step() as cls._raw_user_step during __init_subclass__ wrapping so astep() can bypass the wrapper. Closes mesa#222
5cc62c2 to
85040b6
Compare
|
Thanks for the fix. I have merged Merging now. |
Summary
Closes #222
Fixes a bug where
pre_step/post_step(and their async variants) are called twice per step when a subclass defines onlystep()and is executed viaastep()during parallel stepping. This is the most common usage pattern in mesa-llm.Root Cause
The default
LLMAgent.astep()callsapre_step()→self.step()→apost_step(). Butself.step()is the wrapped version from__init_subclass__, which also callspre_step()→user_step()→post_step(). Result: memory hooks fire twice.The Fix
Store the raw user
step()function ascls._raw_user_stepduring__init_subclass__wrapping. The defaultastep()calls_raw_user_stepdirectly (bypassing the pre/post wrapper), since it handles its own async pre/post hooks.astep()→ step-only subclassastep()→ astep-only subclassstep()called directlyImpact of the Bug
MemoryEntrywithstep=Noneaccumulates in STLTMemory (one per step)format_short_term()renders orphaned entries as"Step None: {data}"in the promptBackward Compatibility
step()calls still go through the wrapper (no change)astep()→step()delegation path is fixed_raw_user_stepis a private class attribute, no public API changeTest Plan
astep()with step-only agent: exactly 1 pre/post callastep()with async-only agent: exactly 1 pre/post callastep()with both-methods agent: exactly 1 pre/post callstep()call: exactly 1 pre/post callastep()calls: counts == 5, not 10step=None