{"record":{"id":"e9e605349909d1c7","repo":"langgenius/dify","slug":"invalid-action","errorCode":"invalid_action","errorMessage":"Document not in indexing state.","messagePattern":"Document not in indexing state\\.","errorType":"error_code","errorClass":"InvalidActionError","httpStatus":400,"severity":"error","filePath":"api/controllers/console/datasets/datasets_document.py","lineNumber":1250,"sourceCode":"        session: Session,\n        current_tenant_id: str,\n        current_user: Account,\n        dataset_id: UUID,\n        document_id: UUID,\n        action: Literal[\"pause\", \"resume\"],\n    ):\n        dataset_id_str = str(dataset_id)\n        document_id_str = str(document_id)\n        document = self.get_document(session, dataset_id_str, document_id_str, current_user, current_tenant_id)\n\n        # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor\n        if not current_user.is_dataset_editor:\n            raise Forbidden()\n\n        match action:\n            case \"pause\":\n                if document.indexing_status != IndexingStatus.INDEXING:\n                    raise InvalidActionError(\"Document not in indexing state.\")\n\n                document.paused_by = current_user.id\n                document.paused_at = naive_utc_now()\n                document.is_paused = True\n\n            case \"resume\":\n                if document.indexing_status not in {IndexingStatus.PAUSED, IndexingStatus.ERROR}:\n                    raise InvalidActionError(\"Document not in paused or error state.\")\n\n                document.paused_by = None\n                document.paused_at = None\n                document.is_paused = False\n\n        return SimpleResultResponse(result=\"success\").model_dump(mode=\"json\"), 200\n\n\n@console_ns.route(\"/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/metadata\")\nclass DocumentMetadataApi(DocumentResource):","sourceCodeStart":1232,"sourceCodeEnd":1268,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/datasets_document.py#L1232-L1268","documentation":"HTTP 400, error_code invalid_action, raised by the processing pause/resume handler when action=\"pause\" but document.indexing_status != IndexingStatus.INDEXING (datasets_document.py:1249). Pause is only meaningful while indexing is actively running.","triggerScenarios":"PATCH .../processing/pause on a document whose status is waiting, parsing, completed, error, or already paused; the match arm rejects it.","commonSituations":"UI pause button enabled for a stale status; double pause click; pausing a document that already errored.","solutions":["Check the document's indexing_status via the indexing-status endpoint before pausing.","Only call pause when status is INDEXING.","If the document errored, call resume instead (resume accepts ERROR)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Pre-flight: only pause a document actively indexing\nstatus = console.get_document_indexing_status(dataset_id, document_id)\nif status[\"indexing_status\"] != \"indexing\":\n    raise RuntimeError(f\"Cannot pause: status is {status['indexing_status']}, expected 'indexing'.\")","typeGuard":"def is_pauseable(status: dict) -> bool:\n    return status.get(\"indexing_status\") == \"indexing\"","tryCatchPattern":"try:\n    console.process_document(dataset_id, document_id, action=\"pause\")\nexcept HTTPError as e:\n    if e.response.status_code == 400 and e.response.json().get(\"code\") == \"invalid_action\":\n        # refresh status; document may have already left INDEXING\n        refresh_document_status(document_id)\n    else:\n        raise","preventionTips":["Poll indexing_status before pause; disable the control when it is not INDEXING.","Avoid double-clicking pause; the first call may already change state."],"tags":["indexing","state-machine","invalid-action","knowledge"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}