Repository navigation
refactor: refactor session handling and i18n defaults - #670
Conversation
haiphucnguyen
commented
Aug 23, 2026
- Update ChatViewModel to set session title immediately using raw message text.
- Adjust SessionManager to perform web search setting on a background thread.
- Add default directive labels and placeholders to all i18n resource files.
- Clean up unused imports and minor test helper adjustments.
- Update Main.kt to pass project context to UI content.
- Update ChatViewModel to set session title immediately using raw message text. - Adjust SessionManager to perform web search setting on a background thread. - Add default directive labels and placeholders to all i18n resource files. - Clean up unused imports and minor test helper adjustments. - Update Main.kt to pass project context to UI content.
There was a problem hiding this comment.
Pull request overview
This PR refactors “start chat from project” session initialization to reduce race conditions between DB reloads and in-memory message updates, and it rounds out i18n resources with new/default directive-related strings.
Changes:
- Update session creation flow to (a) perform DB writes on
Dispatchers.IOand (b) bind a freshly-createdChatViewModelto a new session without an async DB reload. - Set the session title immediately from the first raw user message text while waiting for the AI-generated summary title.
- Add/move directive default labels and add “set/unset default directive” strings across i18n bundles; minor cleanup in a CLI integration test helper.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| shared/src/main/kotlin/io/askimo/core/exception/UserException.kt | Removes trailing whitespace at EOF. |
| desktop/src/main/kotlin/io/askimo/desktop/Main.kt | Passes the loaded project into session creation when starting a chat from project detail. |
| desktop-shared/src/main/resources/i18n/messages.properties | Reorders project default-directive strings; adds base “set/unset default directive” strings. |
| desktop-shared/src/main/resources/i18n/messages_zh_TW.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/resources/i18n/messages_zh_CN.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/resources/i18n/messages_vi_VN.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/resources/i18n/messages_pt_BR.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/resources/i18n/messages_ko_KR.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/resources/i18n/messages_ja_JP.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/resources/i18n/messages_fr.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/resources/i18n/messages_es.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/resources/i18n/messages_de.properties | Adds project default-directive strings and directive default set/unset strings. |
| desktop-shared/src/main/kotlin/io/askimo/ui/session/SessionManager.kt | Refactors project session creation: IO dispatcher for DB work; uses Snapshot.withMutableSnapshot; binds new session before sending first message; sets web search flag off-thread. |
| desktop-shared/src/main/kotlin/io/askimo/ui/chat/ChatViewModel.kt | Sets session title immediately on first message; adds bindNewSession to avoid async DB reload races for brand-new sessions. |
| cli/src/test/kotlin/io/askimo/core/chat/service/ChatDirectiveServiceIT.kt | Minor formatting cleanup of a helper method. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
desktop-shared/src/main/kotlin/io/askimo/ui/session/SessionManager.kt:699
- Wrapping
viewModel.sendMessage(...)inSnapshot.withMutableSnapshotmeans the snapshot block includes side effects (EventBus.post, starting timers, launching coroutines, etc.). If snapshot apply fails, those side effects may already have happened even though the state mutations were rejected. Prefer keeping snapshot blocks side-effect free by moving snapshot management intoChatViewModel.sendMessage(wrap only its state writes) or by splittingsendMessageinto a pure state-mutation part + a side-effect part.
Snapshot.withMutableSnapshot {
viewModel.sendMessage(projectId, mode, message, attachments, enabledServerIds)
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Suppressed comments (1)
desktop-shared/src/main/kotlin/io/askimo/ui/chat/ChatViewModel.kt:876
bindNewSession()performs a synchronous DB existence check viachatDirectiveService.resolveDefaultDirectiveId(project), which callsChatDirectiveRepository.exists()(Exposedtransaction). This is invoked fromSessionManager.createProjectSessionAndSendMessage()insideSnapshot.withMutableSnapshot, so it can block the snapshot/state mutation section and run on a non-IO dispatcher. Consider resolving the default directive ID onDispatchers.IObefore the snapshot/state writes and passing the resolved ID intobindNewSession(or setting it after binding) sobindNewSessionbecomes pure state initialization.
fun bindNewSession(sessionId: String, title: String, project: Project?) {
currentSessionId.value = sessionId
sessionTitle = title
this.project = project
messages = emptyList()
currentCursor = null
hasMoreMessages = false
bookmarkedMessageIds = emptySet()
selectedDirective = chatDirectiveService.resolveDefaultDirectiveId(project)
errorMessage = null
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Suppressed comments (3)
Previously missed (3) — in code that hasn't changed since the last review.
desktop-shared/src/main/kotlin/io/askimo/ui/session/SessionManager.kt:704
getOrCreateChatViewModel()is executed insideSnapshot.withMutableSnapshot. Creating aChatViewModelcurrently runschatDirectiveService.resolveDefaultDirectiveId(...)during property initialization (see ChatViewModel.kt:110), which performs blocking DB access. That can stall the snapshot apply and defeats the goal of keeping the snapshot block to plain, fast state writes.
Create the ViewModel outside the snapshot and only do the Compose state updates + bindNewSession inside the snapshot.
lateinit var viewModel: ChatViewModel
Snapshot.withMutableSnapshot {
// bindNewSession (not switchToSession/resumeSession) avoids an async DB
// reload racing sendMessage()'s in-memory mutation below.
activeSessionId = newSession.id
createdSessions.add(newSession.id)
viewModel = getOrCreateChatViewModel(newSession.id)
viewModel.bindNewSession(sessionId = newSession.id, title = message, project = project, defaultDirectiveId = resolvedDirectiveId)
desktop-shared/src/main/kotlin/io/askimo/ui/session/SessionManager.kt:694
resolvedDirectiveIdis applied only to the in-memory ViewModel (bindNewSession), but the newly-created session in the DB still hasdirectiveId = nullwhen the caller didn’t explicitly pass one. SinceresumeSession()restoresselectedDirectivefrom the persisted session, the default directive selection will be lost after restart / reload.
Persist the resolved default to the session (or set it on createSession) when directiveId is null and a default was resolved.
val resolvedDirectiveId = directiveId ?: withContext(Dispatchers.IO) {
chatDirectiveService.resolveDefaultDirectiveId(project)
}
cli/src/test/kotlin/io/askimo/core/chat/service/ChatDirectiveServiceIT.kt:77
- The single-line
createDirectivehelper is very long and hurts readability (and may violate any line-length formatting rules). Keep it formatted like the surrounding helpers for maintainability.
private fun createDirective(name: String): ChatDirective = directiveRepository.save(ChatDirective(name = name, content = "Some instructions"))
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
desktop-shared/src/main/kotlin/io/askimo/ui/session/SessionManager.kt:689
Snapshot.withMutableSnapshotis meant to batch Compose snapshot state writes; mixing in non-snapshot side effects (like mutatingcreatedSessions, which is a plainMutableSet) inside the block can undermine the goal of using a snapshot here and makes the block harder to reason about. MovecreatedSessions.add(...)outside the snapshot so the snapshot only contains Compose-observed state writes.
Snapshot.withMutableSnapshot {
// bindNewSession (not switchToSession/resumeSession) avoids an async DB
// reload racing sendMessage()'s in-memory mutation below.
activeSessionId = newSession.id
createdSessions.add(newSession.id)