Skip to content

Conversation

@iscekic
Copy link
Collaborator

@iscekic iscekic commented Dec 12, 2025

Context

Refactors SessionManager to use a facade pattern.

Reasoning

The previous SessionManager implementation 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 mechanism
SessionLifecycleService - deals with session actions
SessionStateManager - deals with session state
TokenValidationService - deals with token validation
SessionTitleService - deals with generating a title for the session
GitStateService - deals with git operations
SyncQueue - helper class for fs events

@iscekic iscekic self-assigned this Dec 12, 2025
@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

⚠️ No Changeset found

Latest commit: bcbad32

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

Copilot AI left a 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

also fixes issue where new sessions
would constantly be created
for instances opened without a workspace
@iscekic iscekic requested a review from Copilot December 12, 2025 16:48
@iscekic iscekic marked this pull request as ready for review December 12, 2025 16:48
Copy link
Contributor

Copilot AI left a 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.

@iscekic iscekic merged commit 230f518 into main Dec 15, 2025
12 checks passed
@iscekic iscekic deleted the improve-session-manager-maintainability branch December 15, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants