Skip to content

[enhancement] Implement session persistence and recovery for interrupted executions #15

@github-actions

Description

@github-actions

Background

The Copilot SDK includes session persistence capabilities that allow SDK applications to list and reconnect to existing Copilot sessions. Recent SDK updates have enhanced this with:

  1. Session context tracking (v0.1.24) - SessionContext with working directory, git root, repository, and branch info
  2. Session filtering (v0.1.24) - listSessions() can filter by context fields in PR #427 by Jeremy Moseley
  3. Improved session management - Better object disposal and lifecycle handling in PR #481 by Steve Sanderson

These capabilities enable applications to reconnect to orphaned sessions after crashes or interruptions.

Related SDK commits:

Proposal

Implement session persistence and recovery in Planeteer to allow resuming interrupted executions:

  1. Session ID tracking: Store Copilot session IDs in the persisted plan when execution starts
  2. Graceful shutdown: On normal exit or Ctrl+C, properly dispose sessions and mark tasks as interrupted
  3. Recovery on restart: When loading a plan with incomplete tasks, detect orphaned sessions using listSessions() with repository context filtering
  4. Resume option: Offer users the choice to resume from orphaned sessions or start fresh execution
  5. Session cleanup: Provide a way to dispose orphaned sessions that are no longer needed

Implementation points:

  • Extend Task model with optional sessionId?: string field
  • Save plan JSON after each task completion (incremental persistence)
  • On load, check for tasks with status: 'running' and associated session IDs
  • Use listSessions({ filter: { repository, branch } }) to find orphaned sessions
  • Add "Resume" option in execute screen if orphaned sessions are detected

Benefit

Session persistence makes Planeteer more robust and production-ready:

  • Crash recovery: Users can resume work after unexpected crashes, network issues, or terminal closures
  • Long-running executions: For plans with many tasks, users can stop and resume execution across multiple sessions
  • Resource management: Prevents accumulation of orphaned Copilot sessions consuming resources
  • Professional UX: Matches user expectations from CI/CD and build tools that support resumable operations
  • Debugging: Users can inspect the state of failed executions and retry specific tasks

Acceptance Criteria

  • Add sessionId?: string field to Task interface in src/models/plan.ts
  • Update src/services/executor.ts to store session IDs when creating agent sessions
  • Implement incremental plan persistence - save plan JSON after each task completes or fails
  • On plan load, detect tasks with status: 'running' and check if their sessions still exist using listSessions()
  • Display orphaned sessions in execute screen with options: "Resume", "Start Fresh", "Clean Up"
  • Implement graceful shutdown handler (SIGINT/Ctrl+C) to dispose active sessions and mark tasks as interrupted
  • Add session cleanup utility to dispose orphaned sessions by repository context
  • Update SDK dependency to ^0.1.24 or later to ensure session context filtering is available
  • Add unit tests for session recovery logic
  • Document session persistence behavior in README

AI generated by Weekly Enhancement Suggestions

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions