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
7 changes: 4 additions & 3 deletions src/toad/acp/agent_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import json
import os
from collections.abc import Callable
from contextlib import ExitStack
from contextvars import ContextVar
from functools import partial
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -70,8 +70,7 @@ async def start(self, agent, processes: tuple[AgentProcess, ...]=()):
env = os.environ.copy()
cwd = str(agent.project_root_path.resolve())
selection = RouteSelection.capture(agent.controller.transcripts.access.launch_root.path)
with ExitStack() as acquisition:
acquisition.enter_context(selection.route.hold_client_route())
with selection.route.hold_client_route():
if not agent.session.accepts_updates:
return self
for connection in dict.fromkeys((self, *processes)):
Expand All @@ -95,6 +94,8 @@ async def start(self, agent, processes: tuple[AgentProcess, ...]=()):

async def prompt(self, agent, content, metadata: dict[str, JsonValue], require: Callable[[], None]):
"""The agent-comms-acp child writes the prompt under Core's maintenance gate."""
access = agent.controller.transcripts.access
await access.preparation.run_thread(partial(access.require, self.route_selection))
require()
return await self.rpc.prompt(agent.session_id, content, **metadata)

Expand Down
4 changes: 1 addition & 3 deletions src/toad/comms_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import asyncio
import threading
from collections.abc import Callable, Mapping
from contextlib import ExitStack
from dataclasses import dataclass, field
from functools import partial
from pathlib import Path
Expand Down Expand Up @@ -372,8 +371,7 @@ def require(self, selected: RouteSelection) -> Observing:
def open_selected(self, selected: RouteSelection) -> Observing:
def attach() -> Observing:
previous = self.observation
with ExitStack() as acquisition:
acquisition.enter_context(selected.route.hold_client_route())
with selected.route.hold_client_route():
service = Comms(selected.route)
if service.root.resolve() != selected.root or RouteSelection.capture() != selected:
raise RouteChangedError("Comms route changed while opening the service")
Expand Down
Loading