-
Notifications
You must be signed in to change notification settings - Fork 2
daf sync fails with 'Session already exists' when non-development session exists for same issue #343
Description
Description
When running daf sync, the command fails with error:
⚠ Error syncing itdove/devaiflow: Session 'itdove-devaiflow-330' already exists
This occurs when a session with the target name already exists but is NOT a development session (e.g., session_type = "ticket_creation" or "investigation").
Root Cause Analysis
The bug is in devflow/cli/commands/sync_command.py:
Lines 551-552 (GitHub sync) and 742-744 (GitLab sync):
all_sessions = session_manager.index.get_sessions(issue_key)
existing = [s for s in all_sessions if s.session_type == "development"] if all_sessions else []This check searches for sessions by issue_key and filters to only development sessions. However, when creating a new session (line 559):
session = session_manager.create_session(
name=session_name, # Uses converted name like "itdove-devaiflow-330"
issue_key=issue_key, # Uses original key like "itdove/devaiflow#330"
goal=goal,
)The create_session method uses session_name as the unique identifier. In devflow/config/models.py:1362-1363, the add_session method checks:
if session.name in self.sessions:
raise ValueError(f"Session '{session.name}' already exists")The Problem: The check only looks for development sessions with matching issue_key, but doesn't verify that no session exists with the target session_name (regardless of type).
Reproduction Steps
-
Create a ticket_creation session for an issue:
daf git new itdove/devaiflow#330 --workspace primary -
Complete the analysis and create the GitHub issue
Session remains with name="itdove-devaiflow-330", session_type="ticket_creation" -
Run sync to import the newly created issue:
daf sync -
ERROR: Session 'itdove-devaiflow-330' already exists
Scenarios Where This Occurs
- User created ticket_creation session via
daf git newordaf jira new - User created investigation session via
daf investigate - User manually created session with custom type
- Session exists with ANY session_type that is not "development"
Expected Behavior
daf sync should:
- Skip creating a new session if ANY session exists with the target name
- OR auto-update the existing session's type to "development" if appropriate
- OR display a clear error message explaining which session type already exists
Actual Behavior
The sync crashes with a generic error message that doesn't explain the root cause.
Suggested Fix
Option 1: Check by session name before creating
# Before line 554 in sync_command.py
existing_by_name = session_manager.get_session(session_name)
if existing_by_name:
# Session exists with this name, update it instead of creating
...Option 2: Better filtering logic
# Line 551-552, change to check ALL sessions by name
existing = session_manager.get_session(session_name)
if existing and existing.session_type == "development":
# Update existing development session
...
elif existing:
# Session exists but wrong type - skip or warn
console_print(f"[yellow]⚠[/yellow] Session '{session_name}' already exists with type '{existing.session_type}' (skipping)")
else:
# Create new session
...Option 3: Convert ticket_creation to development
if existing and existing.session_type == "ticket_creation":
# Convert ticket_creation session to development session
existing.session_type = "development"
session_manager.update_session(existing)Impact
- Users cannot sync issues if they previously created ticket_creation/investigation sessions
- Confusing error message doesn't explain the real problem
- Blocks workflow where users analyze issues before implementing them
Files Affected
devflow/cli/commands/sync_command.py(lines 551-563 GitHub, 742-756 GitLab, 269-287 JIRA)devflow/config/models.py(SessionIndex.add_session validation)
Additional Context
The same issue likely affects JIRA sync (lines 269-287) though the impact is less common since JIRA session names match issue keys.
- Sync command checks for existing sessions by TARGET NAME, not just issue_key
- Sync command handles ticket_creation sessions appropriately (convert to development or skip with clear message)
- Error message clearly indicates when a session already exists and what type it is
- Integration test covers scenario where ticket_creation session exists before sync
- Documentation updated to explain session type conversion behavior
- All existing tests pass after fix