{"record":{"id":"c9a9bbc9b367a359","repo":"t8y2/dbx","slug":"timed-out-waiting-for-agent-readiness-c9a9bb","errorCode":null,"errorMessage":"timed out waiting for agent readiness","messagePattern":"timed out waiting for agent readiness","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"agents/drivers/hive-go/bench/agent_compare.py","lineNumber":46,"sourceCode":"            candidate.command,\n            stdin=subprocess.PIPE,\n            stdout=subprocess.PIPE,\n            stderr=subprocess.PIPE,\n            text=True,\n            bufsize=1,\n        )\n        self.request_id = 0\n        self.request_lock = threading.Lock()\n        self.write_lock = threading.Lock()\n        self.pending: dict[int, queue.Queue] = {}\n        self.ready = threading.Event()\n        self.saw_ready = False\n        self.exited = threading.Event()\n        self.stderr_lines: list[str] = []\n        threading.Thread(target=self._read_stdout, daemon=True).start()\n        threading.Thread(target=self._drain_stderr, daemon=True).start()\n        if not self.ready.wait(env_float(\"BENCH_READY_TIMEOUT\", 30.0)) or not self.saw_ready:\n            raise TimeoutError(self._failure(\"timed out waiting for agent readiness\"))\n\n    def _read_stdout(self) -> None:\n        assert self.process.stdout is not None\n        for line in self.process.stdout:\n            try:\n                response = json.loads(line)\n            except json.JSONDecodeError:\n                continue\n            if response.get(\"ready\") is True:\n                self.saw_ready = True\n                self.ready.set()\n                continue\n            response_id = response.get(\"id\")\n            if not isinstance(response_id, int):\n                continue\n            with self.request_lock:\n                response_queue = self.pending.get(response_id)\n            if response_queue is not None:","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/hive-go/bench/agent_compare.py#L28-L64","documentation":"The AgentProcess wrapper launches the candidate agent as a subprocess, communicates over JSON-RPC on stdio, and waits on a readiness Event. If the agent does not signal readiness within BENCH_READY_TIMEOUT (default 30s) or exits before signaling, __init__ raises TimeoutError with the captured stderr tail to help diagnose why startup failed.","triggerScenarios":"The agent subprocess starts slowly (JVM warmup, slow image pull, cold page cache), crashes immediately on startup, or blocks waiting on its own dependencies (database connection refused, missing config), so 'ready' is never seen before the timeout.","commonSituations":"Heavy-traffic CI runners where 30s is too short for a JVM-based agent; misconfigured HIVE_HOST/DB env so the agent exits or hangs; a broken agent build/jar path; startup scripts printing to stdout and corrupting the JSON-RPC channel so the ready message is never parsed.","solutions":["Increase BENCH_READY_TIMEOUT (e.g. export BENCH_READY_TIMEOUT=120) and rerun","Read the stderr tail embedded in the error to find the agent's real startup failure (missing jar, bad credentials, port in use)","Verify the agent runs standalone with the same env/args before running the bench","Ensure nothing else prints to the agent's stdout, which would break the readiness handshake"],"exampleFix":"// before\nBENCH_READY_TIMEOUT=30 python bench/agent_compare.py\n// after\nBENCH_READY_TIMEOUT=120 python bench/agent_compare.py","handlingStrategy":"retry","validationCode":"import subprocess, shutil\ndef preflight_agent(command: list[str]) -> None:\n    if shutil.which(command[0]) is None and not os.path.exists(command[0]):\n        raise SystemExit(f\"agent executable missing: {command[0]}\")\n# also verify DB connectivity before launch\n# socket.create_connection((host, port), timeout=5)","typeGuard":null,"tryCatchPattern":"try:\n    agent = AgentProcess(cmd, ...)\nexcept TimeoutError as e:\n    print(e)  # includes stderr tail\n    # retry once with a larger BENCH_READY_TIMEOUT\n    os.environ[\"BENCH_READY_TIMEOUT\"] = \"120\"\n    agent = AgentProcess(cmd, ...)","preventionTips":["Size BENCH_READY_TIMEOUT above worst-case agent startup (JVM warmup) for CI","Ensure the agent logs startup failures to stderr so the tail is informative","Keep the agent's stdout reserved for JSON-RPC only","Preflight external dependencies (DB reachable, jar exists) before launching"],"tags":["timeout","subprocess","python","process-startup"],"backgroundTag":"process-start-timeout","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}