{"record":{"id":"b29a5f780a162cc0","repo":"langgenius/dify","slug":"invalid-param-b29a5f","errorCode":"invalid_param","errorMessage":"Original app model config not found","messagePattern":"Original app model config not found","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"api/controllers/console/app/model_config.py","lineNumber":119,"sourceCode":"        # validate config\n        model_configuration = AppModelConfigService.validate_configuration(\n            tenant_id=current_tenant_id,\n            config=cast(dict, request.json),\n            app_mode=AppMode.value_of(app_model.mode),\n            session=session,\n        )\n\n        new_app_model_config = AppModelConfig(\n            app_id=app_model.id,\n            created_by=current_user_id,\n            updated_by=current_user_id,\n        )\n        new_app_model_config = new_app_model_config.from_model_config_dict(model_configuration)\n\n        if app_model.mode == AppMode.AGENT_CHAT or app_model.is_agent_with_session(session=session):\n            original_app_model_config = app_model.app_model_config_with_session(session=session)\n            if original_app_model_config is None:\n                raise ValueError(\"Original app model config not found\")\n            agent_mode = original_app_model_config.agent_mode_dict\n            # decrypt agent tool parameters if it's secret-input\n            parameter_map = {}\n            masked_parameter_map = {}\n            tool_map = {}\n            for tool in agent_mode.get(\"tools\") or []:\n                if not isinstance(tool, dict) or len(tool.keys()) <= 3:\n                    continue\n\n                agent_tool_entity = AgentToolEntity.model_validate(tool)\n                # get tool\n                try:\n                    tool_runtime = ToolManager.get_agent_tool_runtime(\n                        tenant_id=current_tenant_id,\n                        app_id=app_model.id,\n                        agent_tool=agent_tool_entity,\n                        user_id=current_user_id,\n                    )","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/model_config.py#L101-L137","documentation":"A raw ValueError('Original app model config not found') raised in AppModelConfigApi.post when an AGENT_CHAT (or agent-with-session) app has no existing AppModelConfig row (api/controllers/console/app/model_config.py:117-119). The handler needs the original config to decrypt/migrate agent tool parameters; without it, it cannot safely produce the new config. Flask translates the ValueError into a 400 with code invalid_param.","triggerScenarios":"POSTing an updated model config to an AGENT_CHAT app that has no AppModelConfig attached — e.g. the app was created but its config row was never initialized, was deleted, or the app is mid-migration. The check is `app_model.app_model_config_with_session(session)` returning None.","commonSituations":"App created via a path that skipped config initialization; manual DB edit deleted the config row; migration/import left the app in a partial state; agent chat app whose app_model_config_id is null.","solutions":["Initialize the app's AppModelConfig before updating — create a default config row or use the app-setup flow that bootstraps it.","Verify app_model.app_model_config_id is non-null and points to an existing AppModelConfig row in the DB.","If the row was accidentally deleted, restore from a backup or recreate via AppModelConfig.from_model_config_dict with the default agent template.","Avoid manually mutating the apps/app_model_configs tables; use the console API to manage configs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before POSTing a config update for an agent-chat app, confirm a config exists\nconst app = await fetch(`/console/apps/${appId}`).then(r=>r.json())\nif (app.mode === 'AGENT_CHAT' && !app.app_model_config_id) {\n  await initAppConfig(appId) // bootstrap a default config first\n}\nawait updateModelConfig(appId, config)","typeGuard":null,"tryCatchPattern":"try {\n  await updateModelConfig(appId, config)\n} catch (e) {\n  if (e.code === 'invalid_param' && /Original app model config/.test(e.message)) {\n    await initAppConfig(appId); return updateModelConfig(appId, config)\n  }\n  throw e\n}","preventionTips":["Never manually delete AppModelConfig rows.","Ensure app-creation flows initialize the config for agent-chat apps.","Audit app_model_config_id is non-null after migrations."],"tags":["model-config","agent-chat","invalid-param","api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}