Skip to content
Merged
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
11 changes: 8 additions & 3 deletions packages/bub-acp-server/src/bub_acp_server/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import contextlib
import json
import logging
import os
import re
import time
from collections import deque
Expand Down Expand Up @@ -953,7 +954,8 @@ def _build_inbound(
context: dict[str, str] = {}
if model := session.runtime.get("model"):
context["_runtime_model"] = model
if reasoning_effort := session.runtime.get(REASONING_EFFORT_CONFIG_ID):
reasoning_effort = session.runtime.get(REASONING_EFFORT_CONFIG_ID)
if reasoning_effort and reasoning_effort != "auto":
context["_runtime_reasoning_effort"] = reasoning_effort
context["_runtime_workspace"] = str(session.cwd)
inbound = ACPInboundMessage(
Expand Down Expand Up @@ -1408,11 +1410,14 @@ def _load_sessions(self) -> dict[str, ACPSession]:
def _save_sessions(self) -> None:
self._session_store_path.parent.mkdir(parents=True, exist_ok=True)
payload = [session.to_json() for session in self._sessions.values()]
temp_path = self._session_store_path.with_suffix(".json.tmp")
temp_path = self._session_store_path.with_suffix(f".json.{os.getpid()}.tmp")
temp_path.write_text(
json.dumps(payload, indent=2, sort_keys=True), encoding="utf-8"
)
temp_path.replace(self._session_store_path)
try:
temp_path.replace(self._session_store_path)
except FileNotFoundError:
temp_path.unlink(missing_ok=True)

async def _attach_session_history(self, session: ACPSession) -> None:
router = self._require_stream_router()
Expand Down
41 changes: 41 additions & 0 deletions packages/bub-acp-server/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,3 +1340,44 @@ async def test_prompt_sends_complete_output_when_stream_has_no_text_chunks() ->

assert client.updates[0][1].content.text == "late text"
assert len(client.updates) == 1


@pytest.mark.asyncio
async def test_auto_reasoning_effort_is_not_forwarded(tmp_path: Path) -> None:
framework = ConfigFramework()
client = FakeClient()
agent = BubACPAgent(framework)
agent.on_connect(client)
created = await agent.new_session(cwd=str(tmp_path))
await agent.set_config_option(
config_id="reasoning_effort",
session_id=created.session_id,
value="auto",
)

await agent.prompt(
[TextContentBlock(type="text", text="hello")],
session_id=created.session_id,
)

assert "_runtime_reasoning_effort" not in framework.messages[0].context


def test_save_sessions_tolerates_concurrent_store_rotation(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
agent = BubACPAgent(FakeFramework())
agent._session_store_path = tmp_path / "acp-sessions.json"
agent._sessions["s1"] = agent_module.ACPSession(session_id="s1", cwd=tmp_path)

def failing_replace(self: Path, target: Path) -> Path:
raise FileNotFoundError(str(self))

monkeypatch.setattr(Path, "replace", failing_replace)
agent._save_sessions() # must not raise
assert not list(tmp_path.glob("*.tmp"))
monkeypatch.undo()

agent._save_sessions()
data = json.loads((tmp_path / "acp-sessions.json").read_text(encoding="utf-8"))
assert [item["session_id"] for item in data] == ["s1"]
Loading