{"record":{"id":"ef1c0b30b624f68a","repo":"iflytek/astron-agent","slug":"aiui-ragerror","errorCode":"AIUI_RAGError","errorMessage":"【url】{url}, reason {msg_json}","messagePattern":"【url】(.+?), reason (.+?)","errorType":"error_code","errorClass":"ThirdPartyException","httpStatus":null,"severity":"error","filePath":"core/knowledge/infra/aiui/aiui.py","lineNumber":312,"sourceCode":"                        response_text = await response.text()\n                        logger.info(\n                            f\"【url】:{url};Response 【XINGHUO-RAG】 body:{response_text}\"\n                        )\n                        span_context.add_info_events({\"AIUI_OUTPUT\": response_text})\n                        msg_json = json.loads(response_text)\n                        try:\n                            if msg_json[\"message\"][\"code\"] == 0:\n                                return msg_json[\"data\"]\n\n                            if msg_json[\"message\"][\"code\"] == 1020:\n                                return msg_json[\"data\"]\n\n                            error_msg = f\"【url】{url}, reason {msg_json} \"\n                            logger.error(\n                                f\"{url} Failed to AIUI knowledge, err reason {error_msg}\"\n                            )\n\n                            raise ThirdPartyException(\n                                e=CodeEnum.AIUI_RAGError, msg=msg_json\n                            )\n                        except Exception:\n                            raise ThirdPartyException(\n                                e=CodeEnum.AIUI_RAGError, msg=msg_json\n                            )\n\n            except aiohttp.ClientError as e:\n                logger.error(f\"AIUI Network error: {e}\")\n                span_context.record_exception(e)\n                raise ThirdPartyException(\n                    e=CodeEnum.AIUI_RAGError, msg=f\"AIUI Network error: {e}\"\n                ) from e\n\n            except asyncio.TimeoutError as e:\n                logger.error(f\"AIUI Request timeout: {url}\")\n                span_context.record_exception(e)\n                raise ThirdPartyException(","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/infra/aiui/aiui.py#L294-L330","documentation":"The shared AIUI request() helper in core/knowledge/infra/aiui/aiui.py raises ThirdPartyException(AIUI_RAGError) when the AIUI HTTP endpoint returns a non-success business payload. The exception message (f\"【url】{url}, reason {msg_json}\") is written to the log; the raised exception carries the parsed response body msg_json as its message. It is thrown both on the detected-error path and from a nested except Exception fallback around response handling.","triggerScenarios":"Any AIUI call (chunk_query, document_parse, chunk_split, chunk_save, chunk_delete, get_doc_content) whose response body contains an error code/message instead of a success payload — e.g. AIUI auth failure, invalid app credentials, unknown docId/repoId, or AIUI-side service errors.","commonSituations":"Expired or wrong AIUI API key/secret in env config; querying docIds that were not ingested; AIUI returning HTML/error JSON that still parses; transient AIUI outage; the nested except Exception path converting any parsing hiccup into this same error.","solutions":["Read msg_json in the exception message to get AIUI's own error code/description and address that root cause first.","Verify AIUI credentials and assembled auth URL (assemble_auth_url) — invalid signatures commonly surface here.","Confirm the docIds/repoIds passed (e.g. AIUI_QUERY_REPOID_V2 env) exist in the AIUI workspace.","Add retry with backoff for transient AIUI 5xx/business errors, and log the full response body for diagnosis."],"exampleFix":"// before\ntry:\n    return await request(post_body, url)\nexcept ThirdPartyException:\n    raise\n// after\ntry:\n    return await request(post_body, url)\nexcept ThirdPartyException as e:\n    logger.warning(\"AIUI call failed, retrying: %s\", e)\n    await asyncio.sleep(1)\n    return await request(post_body, url)","handlingStrategy":"try-catch","validationCode":"assert os.getenv(\"AIUI_APP_ID\") and os.getenv(\"AIUI_API_SECRET\"), \"AIUI credentials not configured\"","typeGuard":"null","tryCatchPattern":"try:\n    result = await chunk_query(...)\nexcept ThirdPartyException as e:\n    logger.error(\"AIUI business error: %s\", e)\n    # inspect e message for AIUI's own code/desc before deciding to retry","preventionTips":["Keep AIUI credentials and repo id env vars current","Log full AIUI response bodies for debugging","Retry transient business errors with backoff","Monitor AIUI service health"],"tags":["third-party-api","aiui","http"],"backgroundTag":"upstream-api-error","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"}