langgenius/dify · error · AgentAppGeneratorError

Agent published version not found

Error message

Agent published version not found

What it means

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.

Source

Thrown at api/controllers/common/agent_app_parameters.py:51

        )
        .limit(1)
    )
    if agent is None:
        raise AgentAppGeneratorError("Agent App has no bound Agent")
    if not agent_has_workflow_callable_active_snapshot(session=session, agent=agent):
        raise AgentAppNotPublishedError("Agent has not been published")

    snapshot = session.scalar(
        select(AgentConfigSnapshot)
        .where(
            AgentConfigSnapshot.tenant_id == app_model.tenant_id,
            AgentConfigSnapshot.agent_id == agent.id,
            AgentConfigSnapshot.id == agent.active_config_snapshot_id,
        )
        .limit(1)
    )
    if snapshot is None:
        raise AgentAppGeneratorError("Agent published version not found")

    agent_soul = AgentSoulConfig.model_validate(snapshot.config_snapshot_dict)
    annotation_reply = load_annotation_reply_config(session, app_model.id) if app_model_config else None
    features_dict = merge_agent_app_features(
        agent_soul=agent_soul,
        app_model_config=app_model_config,
        annotation_reply=annotation_reply,
    )
    return features_dict, agent_app_variables_to_user_input_form(agent_soul.app_variables)

View on GitHub (pinned to ef8544b173)

Solutions

  1. Re-publish the Agent so a fresh AgentConfigSnapshot is created and active_config_snapshot_id is reset to a valid row.
  2. 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.
  3. Audit the snapshots table for the affected agent_id to confirm whether rows were deleted; restore from backup if available.
  4. Add a guard in the publish/cleanup path so snapshot deletion also nulls active_config_snapshot_id.
Defensive patterns

Strategy: try-catch

Validate before calling

from sqlalchemy import select
from models.agent import Agent, AgentConfigSnapshot

def snapshot_is_intact(session, agent) -> bool:
    if not agent.active_config_snapshot_id:
        return False
    row = session.scalar(
        select(AgentConfigSnapshot).where(
            AgentConfigSnapshot.tenant_id == agent.tenant_id,
            AgentConfigSnapshot.agent_id == agent.id,
            AgentConfigSnapshot.id == agent.active_config_snapshot_id,
        )
    )
    return row is not None

Try / catch

from core.app.apps.agent_app.errors import AgentAppGeneratorError, AgentAppNotPublishedError

try:
    features, form = get_published_agent_app_feature_dict_and_user_input_form(app_model=app, session=session)
except AgentAppNotPublishedError:
    # publish-state issue: publish first
    raise
except AgentAppGeneratorError as exc:
    if 'published version not found' in str(exc):
        # referential integrity break: re-publish to repair active_config_snapshot_id
        trigger_republish(agent_id=app.bound_agent_id)
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/2d7a1765f9ba078e. Report an issue: GitHub.