{"record":{"id":"a04090567c203d0c","repo":"t8y2/dbx","slug":"agent-exited-before-ready","errorCode":null,"errorMessage":"agent exited before ready","messagePattern":"agent exited before ready","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"agents/drivers/cassandra-go/bench/agent_compare.py","lineNumber":49,"sourceCode":"            bufsize=1,\n        )\n        self.request_id = 0\n        self.stderr_lines: list[str] = []\n        threading.Thread(target=self._drain_stderr, daemon=True).start()\n        self._wait_ready()\n\n    def _drain_stderr(self) -> None:\n        assert self.process.stderr is not None\n        for line in self.process.stderr:\n            self.stderr_lines.append(line.rstrip())\n\n    def _wait_ready(self) -> None:\n        assert self.process.stdout is not None\n        deadline = time.monotonic() + env_float(\"BENCH_READY_TIMEOUT\", 30.0)\n        while time.monotonic() < deadline:\n            line = self.process.stdout.readline()\n            if line == \"\" and self.process.poll() is not None:\n                raise RuntimeError(self._failure(\"agent exited before ready\"))\n            try:\n                if json.loads(line).get(\"ready\") is True:\n                    return\n            except (json.JSONDecodeError, AttributeError):\n                continue\n        raise TimeoutError(self._failure(\"timed out waiting for agent readiness\"))\n\n    def call(self, method: str, params: dict | None = None) -> dict:\n        self.request_id += 1\n        request = {\n            \"jsonrpc\": \"2.0\",\n            \"id\": self.request_id,\n            \"method\": method,\n            \"params\": params or {},\n        }\n        assert self.process.stdin is not None\n        assert self.process.stdout is not None\n        self.process.stdin.write(json.dumps(request, separators=(\",\", \":\")) + \"\\n\")","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/cassandra-go/bench/agent_compare.py#L31-L67","documentation":"During agent startup, _wait_ready reads the agent's stdout waiting for a JSON line with ready=true. If the agent process exits before sending that line, it raises RuntimeError('agent exited before ready') wrapped with _failure context. This distinguishes a crash during startup from a hang.","triggerScenarios":"Launching the agent subprocess in __init__ when the binary path is wrong, the agent panics on bad flags/config, or it exits immediately due to missing files or port conflicts — its stdout hits EOF before a ready message.","commonSituations":"Pointing BENCH at a non-executable or wrong-architecture binary; agent fails on database connection at boot; agent built from an older version that never emits a ready line.","solutions":["Run the agent command manually to see its actual startup error","Verify the candidate binary path and that it is executable for this platform","Check agent logs/stderr for panics, missing config, or port conflicts","Confirm the agent version emits a JSON line with \"ready\": true on stdout"],"exampleFix":"// before (agent missing)\nCANDIDATE_BIN=./argo-agent-missing python agent_compare.py\n// after\nCANDIDATE_BIN=./target/release/argo-agent python agent_compare.py","handlingStrategy":"try-catch","validationCode":"# before constructing the agent, verify the binary\nbin_path = os.getenv(\"CANDIDATE_BIN\", \"\")\nif not bin_path or not os.path.isfile(bin_path) or not os.access(bin_path, os.X_OK):\n    raise SystemExit(f\"candidate binary missing or not executable: {bin_path}\")","typeGuard":null,"tryCatchPattern":"try:\n    agent = AgentProcess(cmd)\nexcept RuntimeError as exc:\n    if \"agent exited before ready\" in str(exc):\n        print(\"agent stderr:\", agentStderrTail())  # capture captured stderr for diagnosis\n        sys.exit(2)\n    raise","preventionTips":["Run the agent command standalone once to confirm it starts and emits a ready line","Capture and surface the agent's stderr alongside this error","Pin and verify agent binary versions before benchmark runs","Check executable bit and platform architecture (linux/amd64 vs arm64) before launching"],"tags":["python","subprocess","process-crash","ipc"],"backgroundTag":"process-exited-unexpectedly","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"}