{"record":{"id":"b3c44903531c462e","repo":"iflytek/astron-agent","slug":"9020-stage","errorCode":"9020","errorMessage":"stage不可为空","messagePattern":"stage不可为空","errorType":"error_code","errorClass":"AuditServiceException","httpStatus":null,"severity":"error","filePath":"core/common/audit_system/strategy/text_strategy.py","lineNumber":310,"sourceCode":"            is_end = 1 if current_status == Status.STOP else 0\n\n            if current_status == Status.STOP:\n                is_stage_end = 1\n\n        if self.context.last_content_stage != current_stage:\n            is_stage_end = 1\n\n        try:\n            for audit_api in self.audit_apis:\n                span.add_info_event(f\"当前审核API: {audit_api.audit_name}\")\n                stage_arg = (\n                    current_stage\n                    if self.context.last_content_stage == current_stage\n                    else self.context.last_content_stage\n                )\n\n                if stage_arg is None:\n                    raise AuditServiceException(*c9020)(\"stage不可为空\")\n                await audit_api.output_text(\n                    stage=stage_arg,\n                    content=need_audit_content,\n                    pindex=pindex,\n                    span=span,\n                    is_pending=0,\n                    is_stage_end=is_stage_end,\n                    is_end=is_end,\n                    chat_sid=self.context.chat_sid,\n                    chat_app_id=self.context.chat_app_id,\n                    uid=self.context.uid,\n                )\n        except AuditServiceException as e:\n            frame_audit_result.error = e\n            span.add_error_event(f\"审核API调用异常: {str(e)}\")\n            await self.context.output_queue_put(frame_audit_result, span)\n        except Exception as e:\n            span.add_error_event(f\"审核API调用异常: {str(e)}\")","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/common/audit_system/strategy/text_strategy.py#L292-L328","documentation":"In the text audit strategy, `_audit_api_output_text` requires a `stage` argument to route the output audit; when the computed `stage_arg` is None it raises `AuditServiceException(*c9020)` ('stage不可为空') before calling `audit_api.output_text`.","triggerScenarios":"`_audit_api_output_text_async` resolves the stage from context (falling back to `context.last_content_stage` when it differs from the current stage) and both come out None, so `stage_arg is None`.","commonSituations":"Audit pipeline invoked for output without a prior input-stage audit (last_content_stage never set); caller omitted the stage parameter; strategy context initialized incompletely.","solutions":["Ensure the input audit (`input_text`) runs before `output_text` so `last_content_stage` is populated.","Pass an explicit valid `Stage` value to the audit strategy call.","Check that the audit context object is correctly initialized and shared across the request lifecycle.","Add an assertion/validation on the caller side that stage is set before triggering output audit."],"exampleFix":"// before\nawait strategy.output_text(content=answer, pindex=0, span=span)\n// after\nawait strategy.output_text(content=answer, pindex=0, span=span, stage=Stage.AFTER_LLM)","handlingStrategy":"validation","validationCode":"if stage is None and audit_context.last_content_stage is None:\n    raise ValueError(\"output audit requires a stage; run input audit first or pass stage explicitly\")","typeGuard":"from common.audit_system.audit_api.enum import Stage\ndef has_stage(stage: Stage | None) -> bool:\n    return isinstance(stage, Stage)","tryCatchPattern":"try:\n    await strategy.output_text(...)\nexcept AuditServiceException:\n    logger.error(\"stage missing for output audit; ensure input_text ran first\")\n    raise","preventionTips":["Always run the input-stage audit before the output-stage audit in the pipeline.","Make `stage` an explicit required parameter in audit helper wrappers.","Initialize audit context (last_content_stage) at request start.","Write a unit test asserting stage resolution for both first-turn and follow-up turns."],"tags":["audit","validation","missing-argument"],"backgroundTag":"missing-required-argument","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"}