hugsbun's picture
feat: add SRE incident benchmark (Pivot 2 - Scenario A)
a9f2957
Raw
History Blame Contribute Delete
1.84 kB
"""
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,
)