langgenius/dify · critical · InternalServerError
Internal Server Error
Error message
Internal Server Error
What it means
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.
Source
Thrown at api/controllers/console/explore/completion.py:145
raise NotFound("Conversation Not Exists.")
except services.errors.conversation.ConversationCompletedError:
raise ConversationCompletedError()
except services.errors.app_model_config.AppModelConfigBrokenError:
logger.exception("App model config broken.")
raise AppUnavailableError()
except ProviderTokenNotInitError as ex:
raise ProviderNotInitializeError(ex.description)
except QuotaExceededError:
raise ProviderQuotaExceededError()
except ModelCurrentlyNotSupportError:
raise ProviderModelCurrentlyNotSupportError()
except InvokeError as e:
raise CompletionRequestError(e.description)
except ValueError as e:
raise e
except Exception:
logger.exception("internal server error.")
raise InternalServerError()
@console_ns.route(
"/installed-apps/<uuid:installed_app_id>/completion-messages/<string:task_id>/stop",
endpoint="installed_app_stop_completion",
)
class CompletionStopApi(InstalledAppResource):
@console_ns.response(200, "Success", console_ns.models[SimpleResultResponse.__name__])
@with_current_user_id
@with_session(write=False)
def post(self, session: Session, current_user_id: str, installed_app: InstalledApp, task_id: str):
app_model = installed_app.app_with_session(session=session)
if app_model is None:
raise AppUnavailableError()
if app_model.mode != AppMode.COMPLETION:
raise NotCompletionAppError()
AppTaskService.stop_task(View on GitHub (pinned to ef8544b173)
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.
Example fix
// before: client treats any 500 as retryable indefinitely
while (!success) { tryCall(); }
// after: log the request id, retry once, then surface to the user
try { tryCall(); }
catch (e) if (e.status === 500) {
await retryOnce();
notifyOpsWithRequestId(response.headers['x-request-id']);
} Defensive patterns
Strategy: try-catch
Validate before calling
// A 500 is not reliably preventable client-side; the best pre-flight is to validate the
// payload shape matches CompletionMessageExplorePayload and that required services are up.
function isValidCompletionPayload(p) {
return p && typeof p.inputs === 'object' && typeof p.query === 'string';
} Type guard
function isServerError(err) {
return err?.status === 500;
} Try / catch
try {
await postCompletion(id, payload);
} catch (err) {
if (err.status === 500) {
// capture request id, retry once, then surface — do not loop
captureRequestId(err);
await retryOnce();
} else { throw err; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- HTTP status errors: handling 4xx and 5xx responses — how to handle 4xx and 5xx responses properly.
Related errors
- Internal Server Error
- app_unavailable
- not_completion_app
- Conversation Not Exists.
- conversation_completed
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/478fc740d4b4a816.
Report an issue: GitHub.