{"record":{"id":"538768bf86a46230","repo":"666ghj/MiroFish","slug":"interview-simulation-id","errorCode":null,"errorMessage":"模拟环境未运行或已关闭，无法执行Interview: {simulation_id}","messagePattern":"模拟环境未运行或已关闭，无法执行Interview: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/app/services/simulation_runner.py","lineNumber":1729,"sourceCode":"                - \"reddit\": 只采访Reddit平台\n                - None: 双平台模拟时同时采访两个平台，返回整合结果\n            timeout: 超时时间（秒）\n\n        Returns:\n            采访结果字典\n\n        Raises:\n            ValueError: 模拟不存在或环境未运行\n            TimeoutError: 等待响应超时\n        \"\"\"\n        sim_dir = os.path.join(cls.RUN_STATE_DIR, simulation_id)\n        if not os.path.exists(sim_dir):\n            raise ValueError(f\"模拟不存在: {simulation_id}\")\n\n        ipc_client = SimulationIPCClient(sim_dir)\n\n        if not ipc_client.check_env_alive():\n            raise ValueError(f\"模拟环境未运行或已关闭，无法执行Interview: {simulation_id}\")\n\n        logger.info(f\"发送Interview命令: simulation_id={simulation_id}, agent_id={agent_id}, platform={platform}\")\n\n        response = ipc_client.send_interview(\n            agent_id=agent_id,\n            prompt=prompt,\n            platform=platform,\n            timeout=timeout\n        )\n\n        if response.status.value == \"completed\":\n            return {\n                \"success\": True,\n                \"agent_id\": agent_id,\n                \"prompt\": prompt,\n                \"result\": response.result,\n                \"timestamp\": response.timestamp\n            }","sourceCodeStart":1711,"sourceCodeEnd":1747,"githubUrl":"https://github.com/666ghj/MiroFish/blob/b5b53acc57189a4a42e44a23e149dc655c98fe82/backend/app/services/simulation_runner.py#L1711-L1747","documentation":"After confirming the run directory exists, interview_agent builds a SimulationIPCClient over the run's IPC channel and calls check_env_alive(); if the OASIS environment process inside the simulation is not alive (not started, exited, or IPC socket dead), it refuses to send the Interview command with this ValueError.","triggerScenarios":"Interviewing while the simulation is still STARTING (env process not yet listening), after the env process has exited/crashed, after the simulation was stopped, or when the IPC socket/pipe in sim_dir is stale from a previous run.","commonSituations":"Frontend enables the interview panel based on run existence rather than env liveness; polling too early after start; env crashed mid-run while the runner state still says RUNNING.","solutions":["Retry with backoff for the first ~30-60s after start until check_env_alive() passes (env boot takes time).","Check the simulation's runner_status and env logs — if the env process exited, restart the simulation before interviewing.","If a stale IPC socket is suspected (crashed prior run), clean the run directory / restart the simulation."],"exampleFix":"// before\nresp = SimulationRunner.interview_agent(sim_id, agent_id, prompt);\n\n// after\nfrom app.services.simulation_ipc import SimulationIPCClient\nclient = SimulationIPCClient(sim_dir)\nfor _ in range(12):  # up to ~60s for env boot\n    if client.check_env_alive():\n        break\n    time.sleep(5)\nelse:\n    raise ServiceUnavailable(f\"env for {sim_id} not alive\")\nresp = SimulationRunner.interview_agent(sim_id, agent_id, prompt);","handlingStrategy":"retry","validationCode":"from app.services.simulation_ipc import SimulationIPCClient\n\ndef env_ready(sim_id: str) -> bool:\n    sim_dir = Path(SimulationRunner.RUN_STATE_DIR) / sim_id\n    return sim_dir.is_dir() and SimulationIPCClient(str(sim_dir)).check_env_alive()","typeGuard":null,"tryCatchPattern":"try:\n    SimulationRunner.interview_agent(sim_id, agent_id, prompt)\nexcept ValueError as e:\n    if \"环境未运行\" in str(e):\n        return {\"success\": False, \"retry_after\": 5}  # client backs off\n    raise","preventionTips":["Enable the interview UI only when env liveness is confirmed, not on run creation.","Retry with backoff through the STARTING window.","Treat repeated env-death as a crashed run: check env logs before more retries."],"tags":["simulation","interview","ipc","process-liveness","timing"],"backgroundTag":null,"analyzedSha":"b5b53acc57189a4a42e44a23e149dc655c98fe82","analyzedAt":"2026-08-14T22:29:33.146Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}