Repository navigation
Manage agent run outside view life cycle - #724
Merged
haiphucnguyen merged 4 commits intoSep 19, 2026
Merged
haiphucnguyen merged 4 commits into
haiphucnguyen merged 4 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
One or more issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Decouples agent run ViewModels from Compose navigation by introducing centralized caching and lifecycle management.
Changes:
- Adds global
AgentRunManagercaching ViewModels by workspace. - Routes
AgentRunAreathrough the manager. - Adds workspace/view disposal cleanup.
| File | Description |
|---|---|
| desktop-shared/src/main/kotlin/io/askimo/ui/agent/AgentView.kt | Updated as part of this pull request. |
| desktop-shared/src/main/kotlin/io/askimo/ui/agent/AgentsViewModel.kt | Updated as part of this pull request. |
| desktop-shared/src/main/kotlin/io/askimo/ui/agent/AgentRunManager.kt | Updated as part of this pull request. |
| desktop-shared/src/main/kotlin/io/askimo/ui/agent/AgentRunArea.kt | Updated as part of this pull request. |
💡 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.
Copilot review overview
🟡 Changes recommended
Critical lifecycle issues can leak ViewModels and abort in-flight runs, while completion refreshes can be lost.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (2)
Resolved since last review (2)
Comment on lines
+34
to
+38
| // Cache of AgentRunViewModel instances by workspace ID | ||
| private val agentRunViewModels = mutableMapOf<String, AgentRunViewModel>() | ||
|
|
||
| // Shared coroutine scope for all agent runs (not tied to any UI context) | ||
| private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) |
haiphucnguyen
approved these changes
Sep 19, 2026
haiphucnguyen
left a comment
Collaborator
There was a problem hiding this comment.
Thank you @totodev90 !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Decouple
AgentRunViewModellifecycle from Compose composables by implementing a globalAgentRunManagerservice. This ensures in-flight agent runs complete and persist to history even when users navigate away from the agents view (e.g., to Settings, Projects, or other views).Related Issue(s)
No assigned issue — resolved through architectural improvement.
Type of Change
What Changed & Why
Problem:
Agent runs were tied to the composable lifecycle via
remember { AgentRunViewModel(...) }with aDisposableEffectthat calledclose()on unmount. This caused:Solution:
Implemented
AgentRunManager— a global singleton service mirroringSessionManager's proven pattern:AgentRunManager.kt— cachesAgentRunViewModelinstances by workspace ID with a persistentCoroutineScopeindependent of Compose lifecycleAgentRunArea.kt— changed from localremember { AgentRunViewModel(...) }toAgentRunManager.getOrCreateAgentRunViewModel()AgentsViewModel.selectWorkspace()— closes old workspace ViewModel when switching to a new workspaceAgentView.kt— addedDisposableEffectto clean up current workspace ViewModel when leaving the agents viewBenefits:
historyRepo.save()on global scopeSessionManagerarchitecture for chat sessionsHow to Test