You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unified Agent Lifecycle Management with AgentService (#376)
CLOSE https://linear.app/sourcegraph/issue/CODY-6258/visual-studio-plugin-crashes-on-disconnect
Introduced a new `AgentService` class to centralize and unify all agent
lifecycle management, ensuring proper initialization and restart
workflows.
Architectural Changes
### New AgentService Class
(src/Cody.VisualStudio/Services/AgentService.cs)
- Encapsulates complete agent initialization workflow (Start →
Initialize → Component Setup)
- Manages automatic restart with full re-initialization on disconnection
- Provides centralized event handling for initialization success/failure
- Eliminates duplicated initialization logic
### AgentClient Refactoring
(src/Cody.VisualStudio/Client/AgentClient.cs)
- Removed restart logic from OnAgentDisconnected()
- Added AgentDisconnected event to delegate restart handling to
AgentService
- Agent is now focused solely on connection management, not lifecycle
orchestration
### CodyPackage Integration (src/Cody.VisualStudio/CodyPackage.cs)
- Replaced direct agent initialization with
AgentServiceManager.InitializeAsync()
- Added OnAgentServiceInitialized() callback for post-initialization
component setup
- Simplified InitializeAgent() method by delegating complexity to
AgentService
Benefits
- ✅ Complete restart workflow: Agent now properly re-initializes after
disconnection
- ✅ Single responsibility: Clear separation between connection
(AgentClient) and lifecycle (AgentService)
- ✅ Maintainability: Centralized initialization logic easier to modify
and test
- ✅ Consistency: All agent startup paths go through the same workflow
## Test plan
1. Start VS Experimental instance
2. Kill Node.js process hosting the agent
3. Check "Cody" output window and follow the agent restart flow
4. Check the chat which should automatically refresh itself
privatereadonlyBlockingCollection<WebViewEvent>_events;//TODO: when custom editors will be introduced, make it richer, like BlockingCollection<WebViewsEvents>, where WebViewsEvents will be a class
0 commit comments