Skip to content

Feature: Add “Switch Provider” (safe migrate) for existing agent sessions #408

@stephanchenette

Description

@stephanchenette

Summary

Users cannot change an existing session’s provider without creating a separate agent manually. Add a first-class Switch Provider action
that feels like hot-swap, but is implemented as a safe migration to a new session under the target provider.

Problem

Current behavior locks provider after session creation and provider identity is deeply coupled to runtime/session internals.

Code references:

  • src/renderer/components/NewInstanceModal.tsx:1190
  • src/renderer/components/NewInstanceModal.tsx:1595
  • src/renderer/App.tsx:5951
  • src/renderer/App.tsx:6053
  • src/main/utils/agent-args.ts:80
  • src/main/ipc/handlers/agentSessions.ts:399

Goal

Provide a one-click workflow to switch an existing session to another provider with context continuity, without mutating the original
session’s toolType in place.

Non-Goals

  • In-place mutation of session.toolType.
  • Reuse of source provider session/thread IDs on target provider.
  • Cross-provider normalization of every provider-specific config flag in v1.

Proposed Solution

  1. Add a new UI action: Switch Provider... in Edit Agent modal and session quick actions.
  2. Implement orchestration API: switchProvider(sourceSessionId, targetProvider, options).
  3. Internally reuse existing transfer pipeline from useSendToAgent to create a new session with toolType: targetProvider.
  4. Preserve source session unchanged and link provenance metadata on the new session.
  5. Auto-focus new session after success and show clear success/failure toasts.

UX Requirements

  1. Entry points:
  • Edit Agent modal near provider field (read-only stays read-only).
  • Session context menu / quick actions.
  1. Confirmation modal includes:
  • Source provider.
  • Target provider.
  • Option: Groom context for target provider (default on).
  • Option: Archive source session after successful switch (default off).
  1. Success behavior:
  • Create new session.
  • Navigate to new session.
  • Add transfer notice in logs.
  • Keep source session available unless archive option selected.
  1. Failure behavior:
  • Source session unchanged.
  • No partial mutation.
  • Error toast with retry action.

Data Contract (v1)

New fields on Session:

  • migratedFromSessionId?: string
  • migratedFromProvider?: ToolType
  • migrationTimestamp?: number

Portable fields to copy:

  • name (or generated “(Provider)” variant if collision)
  • projectRoot, cwd
  • nudgeMessage
  • sessionSshRemoteConfig
  • transfer context/logs

Fields not copied directly:

  • provider-specific agentSessionId
  • provider-specific command args/env where unsafe to map automatically

Acceptance Criteria

  1. User can trigger Switch Provider... from Edit Agent and session menu.
  2. Switching Claude -> Codex creates a new Codex session with transferred context.
  3. Switching Codex -> Claude creates a new Claude session with transferred context.
  4. Source session toolType remains unchanged in all cases.
  5. New session receives fresh target-provider session/thread ID on first run.
  6. Failure in target creation/spawn leaves source session fully intact.
  7. Optional archive setting archives source only after successful target creation.
  8. Provenance fields are persisted on the new session.
  9. Works for local and SSH-enabled sessions.
  10. Unit/integration tests cover happy path, failure path, and provenance persistence.

Task Breakdown

  1. UI wiring:
  • Add Switch Provider... action in NewInstanceModal and session actions.
  • Add switch confirmation modal with options.
  1. Orchestration:
  • Add switchProvider(...) service/hook.
  • Reuse useSendToAgent transfer logic instead of duplicating flow.
  1. Session metadata:
  • Extend Session type with migration provenance fields.
  • Persist fields through existing session persistence.
  1. Config handling:
  • Implement safe portable-copy function for session fields.
  • Explicitly exclude provider-specific resume/session identifiers.
  1. Archive behavior:
  • Add post-success optional archive operation on source session.
  1. Telemetry/logging:
  • Add structured logs for start/success/failure of switch operations.
  1. Tests:
  • Add renderer tests for modal/action behavior.
  • Add orchestration tests for success/failure semantics.
  • Add persistence tests for provenance fields.

Test Plan

  1. Manual:
  • Start session with provider A, run conversation, switch to provider B, confirm context transfer and new provider execution.
  • Repeat with grooming off.
  • Repeat with SSH-enabled session.
  1. Automated:
  • Unit tests for portable-copy mapper and provenance fields.
  • Integration tests for orchestration success/failure rollback semantics.
  • UI tests for action visibility and modal flow.

Rollout Plan

  1. Ship behind feature flag: ENABLE_SWITCH_PROVIDER.
  2. Dogfood in internal builds.
  3. Remove flag after stability + test coverage meets threshold.

Risks

  • Context transfer quality variance across providers.
  • Provider-specific config leakage if copy mapping is too permissive.
  • User confusion if old and new sessions look identical.

Mitigations

  • Clear transfer notice in new session logs.
  • Conservative config copy policy in v1.
  • Explicit success message: “New session created; original preserved.”

Definition of Done

  • Acceptance criteria met.
  • Tests added and passing.
  • Feature flag enabled for internal testing.
  • Docs updated in user-facing session management docs.
  1. Add labels if they exist:
  • enhancement
  • ux
  • multi-provider

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions