Skip to content

feat(pool): add graceful shutdown support#25

Merged
CrazyBoyM merged 1 commit intomainfrom
feat/sdk-positioning-and-graceful-shutdown
Jan 22, 2026
Merged

feat(pool): add graceful shutdown support#25
CrazyBoyM merged 1 commit intomainfrom
feat/sdk-positioning-and-graceful-shutdown

Conversation

@CrazyBoyM
Copy link
Contributor

Summary

  • Add gracefulShutdown() method to AgentPool for safe server restarts
  • Add resumeFromShutdown() for automatic recovery after restart
  • Add registerShutdownHandlers() for SIGTERM/SIGINT handling
  • Export new types: GracefulShutdownOptions, ShutdownResult

Test plan

  • Unit tests for graceful shutdown functionality (7 tests passing)
  • Build passes
  • Integration testing with actual agent workloads

Usage

const pool = new AgentPool({ dependencies });

// Option 1: Register signal handlers (recommended for servers)
pool.registerShutdownHandlers();

// Option 2: Manual shutdown
const result = await pool.gracefulShutdown({
  timeout: 30000,
  saveRunningList: true,
  forceInterrupt: true,
});

// Resume after restart
await pool.resumeFromShutdown(configFactory, { strategy: 'crash' });

Generated with Claude Code

## New Features

### AgentPool Graceful Shutdown
- `gracefulShutdown()`: Safely stop all agents, wait for working ones to complete
- `resumeFromShutdown()`: Resume agents from a previous graceful shutdown
- `registerShutdownHandlers()`: Convenience method for SIGTERM/SIGINT handling

### New Types
- `GracefulShutdownOptions`: Configuration for shutdown behavior
- `ShutdownResult`: Detailed result of shutdown operation

## How It Works
1. Categorizes agents into READY and WORKING states
2. Immediately persists READY agents
3. Waits for WORKING agents with configurable timeout
4. Optionally interrupts agents that don't complete in time
5. Saves running agents list for recovery after restart

## Usage

```typescript
const pool = new AgentPool({ dependencies });

// Option 1: Register signal handlers
pool.registerShutdownHandlers();

// Option 2: Manual shutdown
const result = await pool.gracefulShutdown({
  timeout: 30000,
  saveRunningList: true,
  forceInterrupt: true,
});

// Resume after restart
await pool.resumeFromShutdown(configFactory, { strategy: 'crash' });
```

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@CrazyBoyM CrazyBoyM merged commit 506a725 into main Jan 22, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant