Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3620,6 +3620,7 @@ def _bg_review_auto_deny(command, description, **kwargs):
credential_pool=getattr(self, "_credential_pool", None),
parent_session_id=self.session_id,
enabled_toolsets=["memory", "skills"],
reasoning_config=self.reasoning_config,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Current main moved the review-fork constructor to agent/background_review.py:683-697 in 1f6eb1738c206e95c3e0641c3d8000a4d0be841b; run_agent.py:1598-1625 is now a wrapper. Relocate this argument to the extracted constructor so the fix reaches the live path.

)
review_agent._memory_write_origin = "background_review"
review_agent._memory_write_context = "background_review"
Expand Down
49 changes: 49 additions & 0 deletions tests/run_agent/test_background_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import pytest

import run_agent as run_agent_module
from run_agent import AIAgent

Expand All @@ -20,6 +22,7 @@ def _bare_agent() -> AIAgent:
agent._memory_store = object()
agent._memory_enabled = True
agent._user_profile_enabled = False
agent.reasoning_config = None
agent._MEMORY_REVIEW_PROMPT = "review memory"
agent._SKILL_REVIEW_PROMPT = "review skills"
agent._COMBINED_REVIEW_PROMPT = "review both"
Expand Down Expand Up @@ -190,3 +193,49 @@ def close(self):
assert captured_bg_callback[0].startswith("💾 Self-improvement review:"), (
captured_bg_callback[0]
)


@pytest.mark.parametrize("reasoning_cfg", [
None,
{"enabled": True, "effort": "xhigh"},
{"enabled": False},
])
def test_background_review_inherits_reasoning_config(monkeypatch, reasoning_cfg):
"""_spawn_background_review() must forward the parent's reasoning_config.

Without this, a session configured for xhigh reasoning effort spawns a
review agent that falls back to the transport default (medium), generating
unexpected medium-effort upstream requests (#18871).
"""
captured: dict = {}

class FakeReviewAgent:
def __init__(self, **kwargs):
captured["reasoning_config"] = kwargs.get("reasoning_config")
self._session_messages = []

def run_conversation(self, **kwargs):
pass

def shutdown_memory_provider(self):
pass

def close(self):
pass

monkeypatch.setattr(run_agent_module, "AIAgent", FakeReviewAgent)
monkeypatch.setattr(run_agent_module.threading, "Thread", ImmediateThread)

agent = _bare_agent()
agent.reasoning_config = reasoning_cfg

AIAgent._spawn_background_review(
agent,
messages_snapshot=[{"role": "user", "content": "hello"}],
review_memory=True,
)

assert captured["reasoning_config"] == reasoning_cfg, (
f"Expected reasoning_config={reasoning_cfg!r} to be forwarded to the "
f"review agent, got {captured['reasoning_config']!r}"
)