-
Notifications
You must be signed in to change notification settings - Fork 1.6k
improve session manager maintainability #4419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors SessionManager to use a facade pattern, improving maintainability by separating concerns into specialized services. The changes introduce new service classes for token validation, session lifecycle management, session synchronization, git state handling, and more, while SessionManager now acts as a lightweight facade that delegates to these services.
Key Changes
- Extracted session management logic into specialized services (SessionSyncService, SessionLifecycleService, TokenValidationService, SessionTitleService, GitStateService, SyncQueue)
- SessionManager now acts as a facade, delegating operations to appropriate services
- Added comprehensive test coverage for all new services
- Enhanced TrpcClient with custom error handling via TrpcError class
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| SessionManager.spec.ts | Completely rewritten to test facade pattern with mocked services |
| SessionSyncService.spec.ts | New comprehensive tests for session synchronization logic |
| SessionLifecycleService.spec.ts | New tests for session restoration, sharing, forking operations |
| TokenValidationService.spec.ts | New tests for token validation with caching |
| SessionTitleService.spec.ts | New tests for session title generation |
| GitStateService.spec.ts | New tests for git state operations |
| SessionStateManager.spec.ts | New tests for in-memory state management |
| SyncQueue.spec.ts | New tests for queue operations and flushing |
| TrpcClient.spec.ts | Updated tests with TrpcError handling |
| SessionClient.spec.ts | Reorganized tests for CRUD operations |
| SessionPersistenceManager.test.ts | Updated to use SessionStateManager dependency |
| AgentManagerProvider.ts | Added null-safety check for shareSession call |
| session-manager-utils.ts | Added onSessionSynced callback and null-safety check |
src/shared/kilocode/cli-sessions/core/__tests__/SessionLifecycleService.spec.ts
Outdated
Show resolved
Hide resolved
src/shared/kilocode/cli-sessions/core/__tests__/SessionLifecycleService.spec.ts
Outdated
Show resolved
Hide resolved
src/shared/kilocode/cli-sessions/core/__tests__/SessionLifecycleService.spec.ts
Outdated
Show resolved
Hide resolved
src/shared/kilocode/cli-sessions/core/__tests__/SessionLifecycleService.spec.ts
Outdated
Show resolved
Hide resolved
src/shared/kilocode/cli-sessions/core/__tests__/SessionLifecycleService.spec.ts
Outdated
Show resolved
Hide resolved
src/shared/kilocode/cli-sessions/core/__tests__/SessionLifecycleService.spec.ts
Outdated
Show resolved
Hide resolved
src/shared/kilocode/cli-sessions/core/__tests__/SessionLifecycleService.spec.ts
Outdated
Show resolved
Hide resolved
src/shared/kilocode/cli-sessions/core/__tests__/TrpcClient.spec.ts
Outdated
Show resolved
Hide resolved
also fixes issue where new sessions would constantly be created for instances opened without a workspace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 32 out of 32 changed files in this pull request and generated no new comments.
Context
Refactors
SessionManagerto use a facade pattern.Reasoning
The previous
SessionManagerimplementation grew into a gigantic god-class, as I was, over time, changing the syncing approach and keeping it in tune with the feature requests that were coming in. This lead to it being very hard to maintain - changes in one spot would break functionality in another. It was also very hard to test - both the functionality as well as unit test.The refactor introduces the facade pattern, splitting up functionality into more manageable sub-classes, which are easier to reason about. They're also easier to test.
SessionSyncService- deals with the syncing mechanismSessionLifecycleService- deals with session actionsSessionStateManager- deals with session stateTokenValidationService- deals with token validationSessionTitleService- deals with generating a title for the sessionGitStateService- deals with git operationsSyncQueue- helper class for fs events