diff --git a/storage-ksqlite/src/commonMain/kotlin/pw/binom/agentik/storage/ksqlite/KsqliteConversationStore.kt b/storage-ksqlite/src/commonMain/kotlin/pw/binom/agentik/storage/ksqlite/KsqliteConversationStore.kt index 51ef24d..ae6520a 100644 --- a/storage-ksqlite/src/commonMain/kotlin/pw/binom/agentik/storage/ksqlite/KsqliteConversationStore.kt +++ b/storage-ksqlite/src/commonMain/kotlin/pw/binom/agentik/storage/ksqlite/KsqliteConversationStore.kt @@ -70,8 +70,12 @@ class KsqliteConversationStore( override suspend fun delete(id: String): Boolean = withContext(Dispatchers.Default) { mutex.withLock { - val existed = get(id) != null - if (!existed) return@withContext false + // Проверяем существование через raw query, НЕ через get() — get() тоже + // берёт mutex (не реентрант), что привело бы к deadlock. + connection.prepare("SELECT 1 FROM conversation WHERE id = ?").use { check -> + check.bindText(1, id) + check.executeQuery().use { rs -> if (!rs.next()) return@withContext false } + } messageStore?.clear(id) workingMemoryStore?.clear(id) connection.prepare("DELETE FROM conversation WHERE id = ?").use { stmt -> @@ -108,7 +112,13 @@ class KsqliteConversationStore( stmt.bindText(3, id) stmt.executeUpdate() } - get(id)?.updatedAt + // raw query instead of get() (deadlock — get() also takes mutex) + connection.prepare("SELECT updated_at FROM conversation WHERE id = ?").use { stmt -> + stmt.bindText(1, id) + stmt.executeQuery().use { rs -> + if (rs.next()) Instant.fromEpochMilliseconds(rs.getLong(0)!!) else null + } + } } }