Skip to content

refactor: Ensure only one chat session at a time#378

Merged
edenreich merged 2 commits intomainfrom
refactor/single-chat-session-enforcement
Jan 24, 2026
Merged

refactor: Ensure only one chat session at a time#378
edenreich merged 2 commits intomainfrom
refactor/single-chat-session-enforcement

Conversation

@edenreich
Copy link
Copy Markdown
Contributor

Summary

This PR refactors chat session management to ensure only one chat session runs at a time and improves tool execution event handling.

Changes

1. Session Management

  • Added cleanup in StartChatSession() to end existing sessions before starting new ones
  • Prevents multiple concurrent chat sessions which could cause race conditions

2. Event Enhancement

  • Extended ToolExecutionCompletedEvent with RequestID and Timestamp fields
  • Provides better tracking and correlation of tool execution events

3. Bug Fixes

  • Removed duplicate session cleanup in HandleComputerUseResumedEvent
  • Changed auto-save from goroutines to synchronous execution to prevent race conditions
  • Removed excessive debug logging that was cluttering output

4. Code Cleanup

  • Simplified tool preview rendering logic
  • Removed unnecessary debug logging statements
  • Improved code organization and readability

5. Testing

  • Added comprehensive unit tests for tool execution completion events in agent_test_additions.go

Technical Details

Key Changes:

  • internal/services/agent.go: Added session cleanup before starting new chat sessions
  • internal/domain/ui_events.go: Enhanced ToolExecutionCompletedEvent struct
  • internal/services/conversation.go: Fixed auto-save concurrency by removing goroutines
  • internal/handlers/chat_handler.go: Removed duplicate session cleanup
  • internal/services/agent_test_additions.go: New test file for event handling

Files Modified:

  • 11 files changed, 308 insertions(+), 96 deletions(-)

Impact

  • Backward Compatible: Yes, maintains existing API and behavior
  • Performance: Improved by reducing unnecessary logging and preventing race conditions
  • Reliability: Better session lifecycle management prevents potential deadlocks
  • Observability: Enhanced event tracking with request IDs and timestamps

Testing

  • All existing tests pass
  • New unit tests added for tool execution events
  • Manual testing confirms single session enforcement works correctly

Adds session cleanup before starting new chat sessions to prevent multiple concurrent sessions. Also enhances ToolExecutionCompletedEvent with request ID and timestamp for better tracking. Removes unnecessary debug logging and fixes auto-save concurrency issues.
@edenreich edenreich merged commit 4ebea6d into main Jan 24, 2026
5 checks passed
@edenreich edenreich deleted the refactor/single-chat-session-enforcement branch January 24, 2026 18:29
ig-semantic-release-bot bot pushed a commit that referenced this pull request Jan 24, 2026
## [0.99.1](v0.99.0...v0.99.1) (2026-01-24)

### ♻️ Code Refactoring

* Ensure only one chat session at a time ([#378](#378)) ([4ebea6d](4ebea6d))

### 📚 Documentation

* Revise README description for CLI functionality ([6f3702f](6f3702f))

### 🧹 Maintenance

* Update package dependencies to latest versions ([#377](#377)) ([43960ce](43960ce))
@ig-semantic-release-bot
Copy link
Copy Markdown

🎉 This PR is included in version 0.99.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant