fix(sessions): 修复压缩续接会话详情为空 (#218)

Session detail now prefers DB-backed reconstruction for compressed continuation chains, with CLI fallback preserved and pending-deletion guard covered by tests.
This commit is contained in:
Zhicheng Han
2026-04-25 16:23:33 +02:00
committed by GitHub
parent 3993dda013
commit d2ab2bca08
4 changed files with 569 additions and 2 deletions
@@ -4,7 +4,7 @@ import {
getConversationDetailFromDb,
listConversationSummariesFromDb,
} from '../../db/hermes/conversations-db'
import { listSessionSummaries, searchSessionSummaries } from '../../db/hermes/sessions-db'
import { getSessionDetailFromDb, listSessionSummaries, searchSessionSummaries } from '../../db/hermes/sessions-db'
import { deleteUsage, getUsage, getUsageBatch } from '../../db/hermes/usage-store'
import { getModelContextLength } from '../../services/hermes/model-context'
import type { ConversationDetail, ConversationSummary } from '../../services/hermes/conversations'
@@ -48,6 +48,16 @@ function hasPendingDeletedConversation(detail: ConversationDetail): boolean {
return detail.messages.some(message => pendingIds.has(message.session_id))
}
function hasPendingDeletedSessionDetail(session: { id: string; messages?: Array<{ session_id?: string | null }> }): boolean {
const pendingIds = getPendingDeletedSessionIds()
if (pendingIds.size === 0) return false
if (pendingIds.has(session.id)) return true
return (session.messages || []).some(message => {
const messageSessionId = message.session_id || session.id
return pendingIds.has(messageSessionId)
})
}
function getGroupChatStorage() {
return getGroupChatServer()?.getStorage() || null
}
@@ -135,6 +145,21 @@ export async function get(ctx: any) {
return
}
try {
const session = await getSessionDetailFromDb(ctx.params.id)
if (session) {
if (hasPendingDeletedSessionDetail(session)) {
ctx.status = 404
ctx.body = { error: 'Session not found' }
return
}
ctx.body = { session }
return
}
} catch (err) {
logger.warn(err, 'Hermes Session DB: detail query failed, falling back to CLI')
}
const session = await hermesCli.getSession(ctx.params.id)
if (!session) {
ctx.status = 404