Skip to content

Commit 70bbd20

Browse files
committed
fix(D3b): set_model also requires callable derive; reset inside try (Greptile)
- Greptile: runtime_checkable only checks the derive attribute exists (and not even callability pre-3.12); also require callable(model.derive) so a non-callable derive is rejected at swap time. - Greptile: move the leading MoodRegistry._reset() inside the try for consistency with the test_mood.py fixture pattern.
1 parent b4b8402 commit 70bbd20

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/hive/agents/mood.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ def __init__(self) -> None:
8282
self._model: MoodModel = CircumplexMood()
8383

8484
def set_model(self, model: MoodModel) -> None:
85-
# MoodModel is runtime-checkable, so this catches a misconfigured model
86-
# at swap time rather than with an AttributeError on the next derive().
87-
if not isinstance(model, MoodModel):
88-
raise TypeError("mood model must implement MoodModel (a derive(...) method)")
85+
# MoodModel is runtime-checkable but only checks that a `derive` attribute
86+
# exists (pre-3.12 doesn't even check callability), so also require it be
87+
# callable -- catching a misconfigured model at swap time rather than with
88+
# an error on the next derive(). Signature validation is left to runtime.
89+
if not isinstance(model, MoodModel) or not callable(model.derive):
90+
raise TypeError("mood model must implement MoodModel (a callable derive(...) method)")
8991
self._model = model
9092

9193
def derive(self, happiness: float, suffering_load: float, in_crisis: bool) -> MoodState:

tests/test_narrative_in_prompt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ async def test_pursuit_prompt_includes_mood(hive_dir: Path) -> None:
120120
from hive.runtime.persona import Persona
121121

122122
# Isolate the global MoodRegistry so a model swapped by another test can't
123-
# change the derived label this test asserts on.
124-
MoodRegistry._reset()
123+
# change the derived label this test asserts on (reset before and after).
125124
try:
125+
MoodRegistry._reset()
126126
store = HiveStore(hive_dir / "hive.db")
127127
await store.initialize()
128128
agent = AgentState(

0 commit comments

Comments
 (0)