Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(wiki): degrade gracefully when revision snapshot is missing
ChenRussell5036062355da
diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.tsindex 22b4ce262..17e019037 100755--- a/frontend/src/i18n/locales/en-US.ts+++ b/frontend/src/i18n/locales/en-US.ts@@ -3205,6 +3205,9 @@ export default {revisionDiffContent: 'Body',revisionDiffEmpty: 'No differences in title, summary, or body vs current',revisionLoadFailed: 'Failed to load revision history',+ revisionNotRetained: 'This version has no retained snapshot or it was cleaned up',+ revisionNotRetainedRange: 'v{ver} · full content',+ revisionNotRetainedHint: 'No snapshot is retained for the previous version v{prev} (versions from before the upgrade were not snapshotted; old snapshots may also have been pruned) — showing the full content of v{ver} from scratch.',revertBtn: 'Revert to this version',revertConfirm: 'Revert to v{ver}? The current content is snapshotted first, so the revert itself can be undone.',revertSuccess: 'Reverted to v{ver}',diff --git a/frontend/src/i18n/locales/ja-JP.ts b/frontend/src/i18n/locales/ja-JP.tsindex 8fcd47d3a..6f5269d18 100644--- a/frontend/src/i18n/locales/ja-JP.ts+++ b/frontend/src/i18n/locales/ja-JP.ts@@ -3205,6 +3205,9 @@ export default {revisionDiffContent: '本文',revisionDiffEmpty: '現在の版とタイトル・要約・本文に差分はありません',revisionLoadFailed: '改訂履歴の読み込みに失敗しました',+ revisionNotRetained: 'このバージョンのスナップショットは保持されていないか、整理済みです',+ revisionNotRetainedRange: 'v{ver} · 全体の内容',+ revisionNotRetainedHint: '前の版(v{prev})のスナップショットは保持されていません(アップグレード前の版はスナップショットが記録されず、古いスナップショットは自動整理される場合があります)。v{ver}の全体の内容を最初から表示しています。',revertBtn: 'このバージョンに戻す',revertConfirm: 'v{ver}に戻しますか?現在の内容は先にスナップショットとして保存されるため、この復元自体も取り消せます。',revertSuccess: 'v{ver}に戻しました',diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.tsindex 5e85677a3..6c28f9b2a 100755--- a/frontend/src/i18n/locales/ko-KR.ts+++ b/frontend/src/i18n/locales/ko-KR.ts@@ -4258,6 +4258,9 @@ export default {revisionDiffContent: '본문',revisionDiffEmpty: '제목, 요약, 본문에서 현재 버전과 차이가 없습니다',revisionLoadFailed: '버전 기록을 불러오지 못했습니다',+ revisionNotRetained: '이 버전의 스냅샷이 보관되어 있지 않거나 정리되었습니다',+ revisionNotRetainedRange: 'v{ver} · 전체 내용',+ revisionNotRetainedHint: '이전 버전(v{prev})의 스냅샷이 보관되어 있지 않습니다(업그레이드 이전 버전은 스냅샷이 기록되지 않으며 오래된 스냅샷은 정리될 수 있음). v{ver}의 전체 내용을 처음부터 표시합니다.',revertBtn: '이 버전으로 롤백',revertConfirm: 'v{ver}(으)로 롤백하시겠습니까? 현재 내용은 먼저 기록으로 저장됩니다.',revertSuccess: 'v{ver}(으)로 롤백했습니다',diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.tsindex 929d56033..4ea81c0b0 100755--- a/frontend/src/i18n/locales/ru-RU.ts+++ b/frontend/src/i18n/locales/ru-RU.ts@@ -4258,6 +4258,9 @@ export default {revisionDiffContent: 'Содержимое',revisionDiffEmpty: 'Нет различий в заголовке, резюме и содержимом с текущей версией',revisionLoadFailed: 'Не удалось загрузить историю версий',+ revisionNotRetained: 'Снимок этой версии не сохранён или был очищен',+ revisionNotRetainedRange: 'v{ver} · полное содержимое',+ revisionNotRetainedHint: 'Снимок предыдущей версии (v{prev}) не сохранён — для версий до обновления снимки не записывались, а старые могли быть очищены. Показано полное содержимое v{ver} с нуля.',revertBtn: 'Откатить к этой версии',revertConfirm: 'Откатить к v{ver}? Текущее содержимое сначала будет сохранено в историю.',revertSuccess: 'Выполнен откат к v{ver}',diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.tsindex 05fa62fac..25c218442 100755--- a/frontend/src/i18n/locales/zh-CN.ts+++ b/frontend/src/i18n/locales/zh-CN.ts@@ -4260,6 +4260,9 @@ export default {revisionDiffContent: '正文',revisionDiffEmpty: '此版本与当前在标题、摘要和正文上均无差异',revisionLoadFailed: '加载版本历史失败',+ revisionNotRetained: '该版本的快照未保留或已被清理',+ revisionNotRetainedRange: 'v{ver} · 完整内容',+ revisionNotRetainedHint: '上一版 v{prev} 没有留存快照(升级前的历史不记录快照,旧快照也可能被自动清理),以下从空白开始展示 v{ver} 的完整内容。',revertBtn: '回滚到此版本',revertConfirm: '确定回滚到 v{ver} 吗?当前内容会先保存为历史版本,回滚操作可再次撤销。',revertSuccess: '已回滚到 v{ver}',diff --git a/frontend/src/views/knowledge/wiki/WikiRevisionDrawer.vue b/frontend/src/views/knowledge/wiki/WikiRevisionDrawer.vueindex b1ad0aeb9..84e6d95d3 100644--- a/frontend/src/views/knowledge/wiki/WikiRevisionDrawer.vue+++ b/frontend/src/views/knowledge/wiki/WikiRevisionDrawer.vue@@ -75,7 +75,10 @@</div><div v-else-if="viewMode !== 'raw'" class="wiki-rev-diff">- <div v-if="diffSections.length === 0" class="wiki-rev-empty-diff">+ <div v-if="snapshotMissing" class="wiki-rev-empty-diff">+ {{ t('knowledgeEditor.wikiBrowser.revisionNotRetained') }}+ </div>+ <div v-else-if="diffSections.length === 0" class="wiki-rev-empty-diff">{{ t('knowledgeEditor.wikiBrowser.revisionDiffEmpty') }}</div><template v-for="section in diffSections" :key="section.field">@@ -121,6 +124,11 @@ interface DiffPair {toVersion: numberfrom: WikiRevisionSnapshotto: WikiRevisionSnapshot+ // True when the previous version's snapshot is not retained (version+ // superseded before the revision feature existed, or pruned by retention):+ // `from` fell back to empty, so the range label and hint must not claim a+ // real v(from) → v(to) diff.+ fromMissing?: boolean}const props = defineProps<{@@ -161,8 +169,13 @@ const viewMode = ref<ViewMode>('incremental')const reverting = ref(false)const diffLoading = ref(false)const diffPair = ref<DiffPair | null>(null)+// True when the selected version's own snapshot is gone (e.g. pruned between+// list load and click) — the diff pane shows a hint instead of a diff.+const snapshotMissing = ref(false)-const snapshotCache = new Map<number, WikiRevisionSnapshot>()+// A null value caches "known not retained" so the 404 is not re-fetched on+// every diff reload.+const snapshotCache = new Map<number, WikiRevisionSnapshot | null>()const currentVersion = computed(() => props.currentPage?.version ?? null)@@ -198,6 +211,9 @@ const versionRangeLabel = computed(() => {return selectedRevision.value ? `v${selectedRevision.value.version}` : ''}if (!diffPair.value) return ''+ if (diffPair.value.fromMissing) {+ return t('knowledgeEditor.wikiBrowser.revisionNotRetainedRange', { ver: diffPair.value.toVersion })+ }if (diffPair.value.fromVersion < 1) {return t('knowledgeEditor.wikiBrowser.revisionInitialRange', { ver: diffPair.value.toVersion })}@@ -212,6 +228,12 @@ const contextHint = computed(() => {].filter(Boolean).join(' · ')}if (viewMode.value === 'incremental') {+ if (diffPair.value?.fromMissing) {+ return t('knowledgeEditor.wikiBrowser.revisionNotRetainedHint', {+ prev: diffPair.value.fromVersion,+ ver: diffPair.value.toVersion,+ })+ }if ((isCurrentSelected.value && (currentVersion.value ?? 0) <= 1)|| selectedVersion.value === 1) {return t('knowledgeEditor.wikiBrowser.revisionInitialCreationHint')@@ -291,7 +313,11 @@ function snapshotFromRevisionData(data: WikiPageRevision, content: string): Wiki}}-async function loadVersionSnapshot(version: number): Promise<WikiRevisionSnapshot> {+// Returns null when the version has no retained snapshot — versions+// superseded before the revision feature existed were never snapshotted, and+// old machine-authored snapshots get pruned. Both are expected states, not+// errors, so callers degrade instead of surfacing a failure.+async function loadVersionSnapshot(version: number): Promise<WikiRevisionSnapshot | null> {if (!props.currentPage) {return { title: '', summary: '', content: '' }}@@ -299,18 +325,27 @@ async function loadVersionSnapshot(version: number): Promise<WikiRevisionSnapshoreturn snapshotFromPage(props.currentPage)}const cached = snapshotCache.get(version)- if (cached) return cached- const res = await getWikiRevision(props.kbId, props.slug, version)- const data = (res as any).data || (res as any)- const snap = snapshotFromRevisionData(data, data.content || '')- snapshotCache.set(version, snap)- return snap+ if (cached !== undefined) return cached+ try {+ const res = await getWikiRevision(props.kbId, props.slug, version)+ const data = (res as any).data || (res as any)+ const snap = snapshotFromRevisionData(data, data.content || '')+ snapshotCache.set(version, snap)+ return snap+ } catch (e: any) {+ if (e?.status === 404) {+ snapshotCache.set(version, null)+ return null+ }+ throw e+ }}let diffRequestSeq = 0async function loadDiffPair() {const seq = ++diffRequestSeq+ snapshotMissing.value = falseif (!props.currentPage || selectedVersion.value === null || !canShowDiff.value) {diffPair.value = nulldiffLoading.value = false@@ -337,13 +372,34 @@ async function loadDiffPair() {diffLoading.value = truetry {- const from = fromVer < 1- ? { title: '', summary: '', content: '' }- : await loadVersionSnapshot(fromVer)- if (seq !== diffRequestSeq) return+ let from: WikiRevisionSnapshot+ let fromMissing = false+ if (fromVer < 1) {+ from = { title: '', summary: '', content: '' }+ } else {+ const prev = await loadVersionSnapshot(fromVer)+ if (seq !== diffRequestSeq) return+ if (prev) {+ from = prev+ } else {+ // The previous version's snapshot is not retained (pre-revision+ // history or pruned). Diff from empty so the pane still shows this+ // version's full content instead of an error toast.+ from = { title: '', summary: '', content: '' }+ fromMissing = true+ }+ }const to = await loadVersionSnapshot(toVer)if (seq !== diffRequestSeq) return- diffPair.value = { fromVersion: fromVer, toVersion: toVer, from, to }+ if (!to) {+ // The selected version's own snapshot vanished (e.g. pruned while the+ // drawer was open) — nothing to diff, show the hint pane instead of a+ // misleading "no differences" empty state.+ snapshotMissing.value = true+ diffPair.value = null+ return+ }+ diffPair.value = { fromVersion: fromVer, toVersion: toVer, from, to, fromMissing }} catch (e: any) {if (seq !== diffRequestSeq) returndiffPair.value = null@@ -365,6 +421,7 @@ function resetAndLoad() {loadingDetail.value = falsediffPair.value = nulldiffLoading.value = false+ snapshotMissing.value = falseviewMode.value = 'incremental'loadList(0)void loadDiffPair()@@ -428,7 +485,11 @@ async function selectRevision(rev: WikiPageRevision) {snapshotCache.set(rev.version, snapshotFromRevisionData(data, data.content || ''))} catch (e: any) {if (seq !== detailRequestSeq) return- MessagePlugin.error(e?.message || t('knowledgeEditor.wikiBrowser.revisionLoadFailed'))+ // 404 = snapshot not retained (pre-revision history or pruned); the raw+ // server message is English and gives the user nothing actionable.+ MessagePlugin.error(e?.status === 404+ ? t('knowledgeEditor.wikiBrowser.revisionNotRetained')+ : (e?.message || t('knowledgeEditor.wikiBrowser.revisionLoadFailed')))} finally {if (seq === detailRequestSeq) loadingDetail.value = false}