{"record":{"id":"614c3f2ee32254a1","repo":"iflytek/astron-agent","slug":"failed-to-xinghuo-rag-code-resp-status","errorCode":null,"errorMessage":"Failed to 【XINGHUO-RAG】; code: {resp.status}","messagePattern":"Failed to 【XINGHUO-RAG】; code: (.+?)","errorType":"exception","errorClass":"ThirdPartyException","httpStatus":null,"severity":"error","filePath":"core/knowledge/infra/xinghuo/xinghuo.py","lineNumber":553,"sourceCode":"\n    Args:\n        resp: HTTP response object\n        url: Request URL\n        span_context: Tracking context\n\n    Returns:\n        Dict[str, Any]: Processed response data\n\n    Raises:\n        ThirdPartyException: Raised when response error occurs\n    \"\"\"\n    response_text = await resp.text()\n    if span_context:\n        span_context.add_info_events({\"RAG_OUTPUT\": response_text})\n\n    if resp.status != 200:\n        logger.error(f\"{url} Failed to 【XINGHUO-RAG】; err code {resp.status}\")\n        raise ThirdPartyException(f\"Failed to 【XINGHUO-RAG】; code: {resp.status}\")\n\n    try:\n        msg_js = await resp.json()\n    except json.JSONDecodeError:\n        msg_js = json.loads(response_text)\n\n    if msg_js.get(\"code\") == 0 and msg_js.get(\"flag\"):\n        return msg_js.get(\"data\", {})\n\n    error_desc = msg_js.get(\"desc\", \"Unknown error from XINGHUO-RAG\")\n    logger.error(f\"{url} Failed to 【XINGHUO-RAG】, err reason {error_desc}\")\n    raise ThirdPartyException(e=CodeEnum.CBG_RAGError, msg=error_desc)\n\n\ndef _handle_form_request_error(e: Exception, url: str, span_context: Any) -> None:\n    \"\"\"\n    Handle form request errors\n","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/infra/xinghuo/xinghuo.py#L535-L571","documentation":"Raised by _process_form_response when the XINGHUO-RAG HTTP endpoint returns a non-200 status code. The library wraps the status code into a ThirdPartyException so callers get a uniform error type for upstream RAG failures. It indicates the remote CBG/XINGHUO RAG service rejected the request at the HTTP level.","triggerScenarios":"Any async_form_request to a XINGHUO-RAG URL (topk search, doc upload, chunk ops) where the aiohttp response status is not 200 — e.g. 401 from expired app_id/app_secret, 404 from wrong base URL, 400 from malformed form fields.","commonSituations":"Misconfigured XINGHUO base URL or app credentials in environment config; expired or revoked XINGHUO API keys; XINGHUO service outage or gateway returning 5xx; wrong endpoint path after API version change.","solutions":["Verify the XINGHUO base URL and endpoint path in configuration are correct for your environment","Check XINGHUO app_id/app_secret credentials are valid and not expired","Log the response body at the failing status to see the upstream error detail (response_text is already captured in RAG_OUTPUT span events)","Check XINGHUO service health/status page or retry after transient 5xx","Add retry with backoff for transient 5xx statuses in async_form_request"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import aiohttp\nasync def endpoint_ok(session: aiohttp.ClientSession, url: str) -> bool:\n    try:\n        async with session.get(url.replace('/api', '/health')) as r:\n            return r.status == 200\n    except Exception:\n        return False","typeGuard":"def is_ok(resp: aiohttp.ClientResponse) -> bool:\n    return resp.status == 200","tryCatchPattern":"try:\n    data = await async_form_request(body, url)\nexcept ThirdPartyException as e:\n    if 'code:' in str(e):\n        logger.warning(f\"XINGHUO HTTP failure: {e}\")\n        # surface to user / alert ops","preventionTips":["Validate XINGHUO base URL and credentials at service startup","Monitor/alert on non-200 responses to the RAG endpoint","Use health checks before critical RAG calls","Keep credentials rotation automated to avoid 401s"],"tags":["http","third-party","rag","network"],"backgroundTag":"http-non-200-response","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}