fix: proactively check session existence before use

Используем ctx.session.get({ sessionID }) для проверки существования
сессии в OpenCode ДО отправки prompt. Если сессия удалена/невалидна —
создаём новую. Убрана реактивная обработка Session.NotFoundError.
This commit is contained in:
Бородин Роман 2026-09-26 01:16:19 +03:00
parent c95ac899d2
commit 5fa1fd2676
1 changed files with 11 additions and 0 deletions

View File

@ -144,6 +144,17 @@ async function runPlugin(ctx: any, options: any, dataDir: string) {
let opencodeSessionId = session.opencodeSessionId let opencodeSessionId = session.opencodeSessionId
// If we have a session ID from the map, verify it exists in OpenCode
if (opencodeSessionId) {
try {
await ctx.session.get({ sessionID: opencodeSessionId })
log(`Using existing OpenCode session ${opencodeSessionId}`)
} catch (getErr: any) {
log(`Session ${opencodeSessionId} not found in OpenCode, creating new one`)
opencodeSessionId = ""
}
}
// If no session ID yet, create one // If no session ID yet, create one
if (!opencodeSessionId) { if (!opencodeSessionId) {
log(`Creating new OpenCode session for ${roomId}:${threadRootId}`) log(`Creating new OpenCode session for ${roomId}:${threadRootId}`)