{"record":{"id":"2d7a1765f9ba078e","repo":"langgenius/dify","slug":"agent-published-version-not-found","errorCode":null,"errorMessage":"Agent published version not found","messagePattern":"Agent published version not found","errorType":"http","errorClass":"AgentAppGeneratorError","httpStatus":null,"severity":"error","filePath":"api/controllers/common/agent_app_parameters.py","lineNumber":51,"sourceCode":"        )\n        .limit(1)\n    )\n    if agent is None:\n        raise AgentAppGeneratorError(\"Agent App has no bound Agent\")\n    if not agent_has_workflow_callable_active_snapshot(session=session, agent=agent):\n        raise AgentAppNotPublishedError(\"Agent has not been published\")\n\n    snapshot = session.scalar(\n        select(AgentConfigSnapshot)\n        .where(\n            AgentConfigSnapshot.tenant_id == app_model.tenant_id,\n            AgentConfigSnapshot.agent_id == agent.id,\n            AgentConfigSnapshot.id == agent.active_config_snapshot_id,\n        )\n        .limit(1)\n    )\n    if snapshot is None:\n        raise AgentAppGeneratorError(\"Agent published version not found\")\n\n    agent_soul = AgentSoulConfig.model_validate(snapshot.config_snapshot_dict)\n    annotation_reply = load_annotation_reply_config(session, app_model.id) if app_model_config else None\n    features_dict = merge_agent_app_features(\n        agent_soul=agent_soul,\n        app_model_config=app_model_config,\n        annotation_reply=annotation_reply,\n    )\n    return features_dict, agent_app_variables_to_user_input_form(agent_soul.app_variables)\n","sourceCodeStart":33,"sourceCodeEnd":61,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/common/agent_app_parameters.py#L33-L61","documentation":"Raised as AgentAppGeneratorError after the publish-visibility check passed but the AgentConfigSnapshot row referenced by agent.active_config_snapshot_id could not be loaded from the DB. It indicates referential-integrity breakage: the Agent claims to be published (callable) but the snapshot backing that claim is gone. This is a data-corruption guard, not a normal user state.","triggerScenarios":"Hitting the Agent App parameters endpoint when agent.active_config_snapshot_id points to a deleted/missing AgentConfigSnapshot row (snapshot deleted manually, migration removed it, or cross-tenant mismatch). Distinguishable from error 200 because agent_has_workflow_callable_active_snapshot returned True here, yet the immediate re-query for the snapshot returns None.","commonSituations":"Manual DB surgery that deleted snapshots without clearing active_config_snapshot_id; partial migration that dropped snapshot rows; replication lag in a multi-replica DB setup; a tenant_id mismatch introduced by a bad copy/import job.","solutions":["Re-publish the Agent so a fresh AgentConfigSnapshot is created and active_config_snapshot_id is reset to a valid row.","If a known-good snapshot exists, set Agent.active_config_snapshot_id to that row's id (and ensure tenant_id matches) via a corrective migration.","Audit the snapshots table for the affected agent_id to confirm whether rows were deleted; restore from backup if available.","Add a guard in the publish/cleanup path so snapshot deletion also nulls active_config_snapshot_id."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from sqlalchemy import select\nfrom models.agent import Agent, AgentConfigSnapshot\n\ndef snapshot_is_intact(session, agent) -> bool:\n    if not agent.active_config_snapshot_id:\n        return False\n    row = session.scalar(\n        select(AgentConfigSnapshot).where(\n            AgentConfigSnapshot.tenant_id == agent.tenant_id,\n            AgentConfigSnapshot.agent_id == agent.id,\n            AgentConfigSnapshot.id == agent.active_config_snapshot_id,\n        )\n    )\n    return row is not None","typeGuard":null,"tryCatchPattern":"from core.app.apps.agent_app.errors import AgentAppGeneratorError, AgentAppNotPublishedError\n\ntry:\n    features, form = get_published_agent_app_feature_dict_and_user_input_form(app_model=app, session=session)\nexcept AgentAppNotPublishedError:\n    # publish-state issue: publish first\n    raise\nexcept AgentAppGeneratorError as exc:\n    if 'published version not found' in str(exc):\n        # referential integrity break: re-publish to repair active_config_snapshot_id\n        trigger_republish(agent_id=app.bound_agent_id)\n    raise","preventionTips":["Never hard-delete AgentConfigSnapshot rows without nulling Agent.active_config_snapshot_id.","Add a DB-level FK or cleanup hook that keeps the snapshot pointer consistent.","Run a periodic integrity check between active_config_snapshot_id and the snapshots table."],"tags":["agent-app","data-integrity","config-snapshot","publish-state"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}