{"record":{"id":"478fc740d4b4a816","repo":"langgenius/dify","slug":"internal-server-error-478fc7","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":"InternalServerError","httpStatus":500,"severity":"critical","filePath":"api/controllers/console/explore/completion.py","lineNumber":145,"sourceCode":"            raise NotFound(\"Conversation Not Exists.\")\n        except services.errors.conversation.ConversationCompletedError:\n            raise ConversationCompletedError()\n        except services.errors.app_model_config.AppModelConfigBrokenError:\n            logger.exception(\"App model config broken.\")\n            raise AppUnavailableError()\n        except ProviderTokenNotInitError as ex:\n            raise ProviderNotInitializeError(ex.description)\n        except QuotaExceededError:\n            raise ProviderQuotaExceededError()\n        except ModelCurrentlyNotSupportError:\n            raise ProviderModelCurrentlyNotSupportError()\n        except InvokeError as e:\n            raise CompletionRequestError(e.description)\n        except ValueError as e:\n            raise e\n        except Exception:\n            logger.exception(\"internal server error.\")\n            raise InternalServerError()\n\n\n@console_ns.route(\n    \"/installed-apps/<uuid:installed_app_id>/completion-messages/<string:task_id>/stop\",\n    endpoint=\"installed_app_stop_completion\",\n)\nclass CompletionStopApi(InstalledAppResource):\n    @console_ns.response(200, \"Success\", console_ns.models[SimpleResultResponse.__name__])\n    @with_current_user_id\n    @with_session(write=False)\n    def post(self, session: Session, current_user_id: str, installed_app: InstalledApp, task_id: str):\n        app_model = installed_app.app_with_session(session=session)\n        if app_model is None:\n            raise AppUnavailableError()\n        if app_model.mode != AppMode.COMPLETION:\n            raise NotCompletionAppError()\n\n        AppTaskService.stop_task(","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/explore/completion.py#L127-L163","documentation":"Raised by CompletionApi.post as werkzeug InternalServerError (HTTP 500) from the catch-all 'except Exception' block. Any unhandled exception during AppGenerateService.generate that is not one of the specific service/provider/invoke errors triggers this. The controller logs the full traceback ('internal server error.') and returns a generic 500 to avoid leaking internals.","triggerScenarios":"POST /console/installed-apps/<id>/completion-messages that hits an unexpected exception — a bug in a service, a database error, an unhandled KeyError/AttributeError in the pipeline, a serialization failure, or infrastructure failure (Redis, vector store) not mapped to a specific error.","commonSituations":"Bug in custom plugin/tool code invoked during generation; DB connection dropped mid-request; vector store or knowledge retrieval threw an unmapped error; version skew between services; out-of-memory or timeout in a worker.","solutions":["Check the Dify backend logs for the full traceback logged by logger.exception('internal server error.').","Reproduce with the same payload and capture the stack trace to identify the root cause.","If intermittent, check DB/Redis/vector-store connectivity and capacity.","Report the traceback to the app maintainer or Dify issue tracker if it is a product bug.","Retry once; persistent 500s indicate a deterministic bug, not a transient glitch."],"exampleFix":"// before: client treats any 500 as retryable indefinitely\nwhile (!success) { tryCall(); }\n\n// after: log the request id, retry once, then surface to the user\ntry { tryCall(); }\ncatch (e) if (e.status === 500) {\n  await retryOnce();\n  notifyOpsWithRequestId(response.headers['x-request-id']);\n}","handlingStrategy":"try-catch","validationCode":"// A 500 is not reliably preventable client-side; the best pre-flight is to validate the\n// payload shape matches CompletionMessageExplorePayload and that required services are up.\nfunction isValidCompletionPayload(p) {\n  return p && typeof p.inputs === 'object' && typeof p.query === 'string';\n}","typeGuard":"function isServerError(err) {\n  return err?.status === 500;\n}","tryCatchPattern":"try {\n  await postCompletion(id, payload);\n} catch (err) {\n  if (err.status === 500) {\n    // capture request id, retry once, then surface — do not loop\n    captureRequestId(err);\n    await retryOnce();\n  } else { throw err; }\n}","preventionTips":["Always capture and log the x-request-id / trace id to speed up root-cause.","Alert on 500 spikes; a single 500 may be transient, a pattern is a bug.","Keep Dify services and DB/Redis/vector-store healthy to avoid infra 500s."],"tags":["explore","completion","internal-server-error","unhandled","logging"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}