Skip to content

fix(#561): Redesign conversation state management to address agent persistence after interruptions#565

Merged
tusharmath merged 19 commits into
mainfrom
conversation-fix
Mar 20, 2025
Merged

fix(#561): Redesign conversation state management to address agent persistence after interruptions#565
tusharmath merged 19 commits into
mainfrom
conversation-fix

Conversation

@tusharmath
Copy link
Copy Markdown
Collaborator

@tusharmath tusharmath commented Mar 20, 2025

Overview

This PR refactors the conversation state management system to fix an issue where agent states incorrectly remain marked as active after Ctrl+C interruptions, leading to potential state corruption in subsequent interactions.

Purpose

When users interrupt a conversation with Ctrl+C, the is_active flags on agents remained set to true, causing incorrect behavior if the conversation was resumed later. This refactoring removes the problematic flag entirely and fundamentally redesigns how agent activity is tracked and synchronized.

Implementation

The implementation takes a three-pronged approach:

  1. Architecture Change: The Orchestrator now maintains the conversation in memory with proper synchronization using RwLock, rather than repeatedly fetching it from storage.

  2. State Management: Removed the is_active flag from AgentState and instead determine agent activity dynamically by checking if its event queue is empty.

  3. API Improvements: Renamed methods in ConversationService to be more intuitive:

    • getfind (more explicit about possible absence)
    • Added upsert method for clear responsibility
    • Removed redundant methods by moving their functionality to the Orchestrator
  4. Synchronization: Added explicit conversation state synchronization to ensure persistence after state changes.

Testing

To test these changes:

  1. Start a conversation with a multi-agent system
  2. Interrupt with Ctrl+C during agent processing
  3. Resume the conversation
  4. Verify that agents properly respond to new events

This fix ensures that conversation state is properly maintained across interruptions without corruption.

Related Issues

Fixes #561: "bug: Agent states remain active after Ctrl+C interruption"
Fixes #543
Fixes #541

Changelog

Changed in conversation.rs

  • Removed is_active flag from AgentState
  • Reworked dispatch_event to track activity based on queue emptiness
  • Improved event handling to reduce cloning

Changed in lib.rs

  • Simplified ConversationService trait interface
  • Renamed methods for clarity: getfind and added upsert
  • Moved agent-specific operations to the Orchestrator

Changed in orch.rs

  • Redesigned Orchestrator to store conversation with RwLock
  • Added conversation synchronization after state changes
  • Improved event polling for better error handling
  • Added queue clearing logic during initialization

Changed in api.rs and executor.rs

  • Updated to use new method names and patterns
  • Improved conversation retrieval in executor service

Suggested Reviewers

  • @laststylebender14 - Owner of the related issue
  • Team members familiar with the conversation system architecture
laststylebender14 and others added 18 commits March 20, 2025 14:01
…oring Orchestrator to use conversation state
Move the responsibility of clearing conversation state queue from the executor
to the orchestration layer for better separation of concerns.

Co-authored-by: Forge <forge@antinomy.ai>
@tusharmath tusharmath enabled auto-merge (squash) March 20, 2025 14:35
@tusharmath tusharmath merged commit 1acce8c into main Mar 20, 2025
@amitksingh1490 amitksingh1490 deleted the conversation-fix branch October 1, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants