{"record":{"id":"51fa378aa0561327","repo":"langgenius/dify","slug":"last-conversation-not-exists","errorCode":null,"errorMessage":"Last Conversation Not Exists.","messagePattern":"Last Conversation Not Exists\\.","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"warning","filePath":"api/controllers/console/explore/conversation.py","lineNumber":101,"sourceCode":"                    limit=args.limit,\n                    invoke_from=InvokeFrom.EXPLORE,\n                    pinned=args.pinned,\n                )\n                adapter = TypeAdapter(SimpleConversation)\n                conversations = [\n                    adapter.validate_python(\n                        ConversationResponseSource(item, session=session),\n                        from_attributes=True,\n                    )\n                    for item in pagination.data\n                ]\n                return ConversationInfiniteScrollPagination(\n                    limit=pagination.limit,\n                    has_more=pagination.has_more,\n                    data=conversations,\n                ).model_dump(mode=\"json\")\n        except LastConversationNotExistsError:\n            raise NotFound(\"Last Conversation Not Exists.\")\n\n\n@console_ns.route(\n    \"/installed-apps/<uuid:installed_app_id>/conversations/<uuid:c_id>\",\n    endpoint=\"installed_app_conversation\",\n)\nclass ConversationApi(InstalledAppResource):\n    @console_ns.response(204, \"Conversation deleted successfully\")\n    @with_current_user\n    def delete(self, current_user: Account, installed_app: InstalledApp, c_id: UUID):\n        app_model = installed_app.app_with_session(session=db.session())\n        if app_model is None:\n            raise AppUnavailableError()\n        app_mode = AppMode.value_of(app_model.mode)\n        if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:\n            raise NotChatAppError()\n\n        conversation_id = str(c_id)","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/explore/conversation.py#L83-L119","documentation":"NotFound (HTTP 404, werkzeug) with message 'Last Conversation Not Exists.' is raised in ConversationListApi.get when WebConversationService.pagination_by_last_id throws LastConversationNotExistsError. This happens when the 'last_id' query parameter references a conversation that does not exist (e.g. was deleted) — the cursor-based pagination cannot find the anchor conversation to page after.","triggerScenarios":"GET /console/explore/installed-apps/<id>/conversations?last_id=<uuid> where the conversation with that UUID was deleted, belongs to a different user, or never existed. The pagination logic uses last_id as a cursor anchor and fails when it cannot locate it.","commonSituations":"The user paginated, then deleted the conversation that was the cursor; the last_id was copied from a different user's session; the conversation expired or was cleaned up by a retention policy; a stale URL was revisited after the anchor conversation was removed.","solutions":["Retry the request without the last_id parameter to start pagination from the most recent conversation.","If the client caches last_id values, clear the cached cursor and restart pagination from the beginning.","Ensure the last_id passed is from the current user's own conversation list."],"exampleFix":"// before: keep using a stale cursor after conversations are deleted\nGET /conversations?last_id=<deleted_conv_id>\n// after: restart from the top on 404\ntry { return await getConversations(lastId); }\ncatch (e) { if (e.status===404) return await getConversations(null); throw e; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const page = await listConversations(installedAppId, lastId);\n} catch (e) {\n  if (e.status === 404 && e.message?.includes('Last Conversation')) {\n    // cursor anchor is gone — restart from the beginning\n    const freshPage = await listConversations(installedAppId, null);\n    return freshPage;\n  }\n  throw e;\n}","preventionTips":["Do not persist the last_id cursor long-term — conversations can be deleted, invalidating it.","On a 404 cursor error, restart pagination from the beginning without a last_id parameter.","Ensure the last_id originates from the current user's own conversation list."],"tags":["conversation","not-found","pagination","cursor","installed-app"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}