Spaces:
Sleeping
Sleeping
File size: 1,839 Bytes
a9f2957 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | """
restart_service tool — stop and restart the buggy server subprocess.
After the agent has fixed the database state and patched worker.py, calling
this tool triggers a clean restart. The environment then automatically runs
the incident grader to check whether all three conditions are met.
"""
import logging
from debug_env.server.schemas import ToolResult
logger = logging.getLogger(__name__)
def restart_service(workdir: str, service_manager, entrypoint: str) -> ToolResult:
"""
Restart the buggy server via *service_manager*.
Args:
workdir: Absolute path to the task working directory.
service_manager: A :class:`~debug_env.server.services.ServiceManager` instance
held in shared environment state.
entrypoint: Server script filename, e.g. ``"buggy_server.py"``.
Returns:
:class:`ToolResult` with ``pass_rate=0.0`` and a status message.
The *actual* reward-bearing result is supplied by the incident grader
which runs immediately after in the ``step()`` handler.
"""
if service_manager is None:
return ToolResult(
pass_rate=0.0,
logs="No service manager found. Is this an incident task?",
success=False,
)
try:
new_port = service_manager.restart(workdir, entrypoint)
logger.info("restart_service: new port=%s", new_port)
return ToolResult(
pass_rate=0.0,
logs=f"Service restarted successfully. Now listening on port {new_port}.",
success=True,
)
except Exception as exc:
logger.error("restart_service failed: %s", exc, exc_info=True)
return ToolResult(
pass_rate=0.0,
logs=f"Service restart failed: {exc}",
success=False,
)
|