Python
fix(engine): changing a session's model no longer closes it when the reviewer is OpenAI Decisions or Jev (OPE-246)
Devika Vermaf16aea360408
diff --git a/coworker/engine.py b/coworker/engine.pyindex 716c262b..150ba7ff 100644--- a/coworker/engine.py+++ b/coworker/engine.py@@ -589,9 +589,14 @@ class TurnEngine:# The reviewer judges with the session's own model (§1.5: "if it's trusted to# drive the agent, it's strong enough to review it"). Bound once at session build,# it would otherwise keep the OLD model for the rest of the session after a- # switch — silently reviewing with a model the user moved away from.+ # switch — silently reviewing with a model the user moved away from. A+ # decision-model reviewer (OpenAI Decisions, Jev) judges with its own service's+ # model, which a session switch must not change (its `model` is read-only).if self.reviewer is not None:- self.reviewer.model = model+ from .decision_reviewer import DecisionReviewer++ if not isinstance(self.reviewer, DecisionReviewer):+ self.reviewer.model = modelif not had_history:return Nonefrom .providers.matrix import model_labelsdiff --git a/tests/test_auto_approve.py b/tests/test_auto_approve.pyindex 7e613157..85f8523b 100644--- a/tests/test_auto_approve.py+++ b/tests/test_auto_approve.py@@ -1091,6 +1091,23 @@ def test_reviewer_follows_a_model_switch(tmp_path):assert engine.reviewer.model == "anthropic:claude-sonnet-5"+def test_a_decision_model_reviewer_keeps_its_model_on_a_switch(tmp_path):+ # With OpenAI Decisions or Jev as the reviewer, picking a model in a session raised+ # AttributeError (DecisionReviewer.model has no setter) and closed the session's socket.+ # Those reviewers judge with their own service's model, so a switch leaves it alone.+ from coworker.decision_reviewer import build_decision_reviewer++ engine, _rows, _approvals = _engine(tmp_path, [AssistantTurn(text="ok", finish_reason="stop")])+ engine.reviewer = build_decision_reviewer("jev", api_key="test-key-not-real")+ before = engine.reviewer.model+ engine.messages.append({"role": "user", "content": "hi"})++ engine.switch_model("openai:model-b") # must not raise++ assert engine.model == "openai:model-b"+ assert engine.reviewer.model == before++def test_model_switch_with_no_reviewer_attached_still_works(tmp_path):engine, _rows, _approvals = _engine(tmp_path, [AssistantTurn(text="ok", finish_reason="stop")])engine.reviewer = None