[ORCH-118] Resource cleanup #253

Closed
opened 2026-02-02 22:10:00 +00:00 by jason.woltje · 0 comments
Owner

Clean up resources when agent terminates.

Acceptance Criteria

  • src/killswitch/cleanup.service.ts implemented
  • Stop Docker container
  • Remove Docker container
  • Remove git worktree
  • Clear Valkey state
  • Emit cleanup event
  • Run cleanup on: agent completion, agent failure, killswitch
  • NestJS service with proper dependency injection
  • Comprehensive unit tests with 10 test cases covering all scenarios
  • Integrated with KillswitchService

Implementation Summary

Created CleanupService as a dedicated, reusable service for agent resource cleanup.

Files Created/Modified

  • Created: apps/orchestrator/src/killswitch/cleanup.service.ts
  • Created: apps/orchestrator/src/killswitch/cleanup.service.spec.ts (10 test cases)
  • Modified: apps/orchestrator/src/killswitch/killswitch.service.ts
  • Modified: apps/orchestrator/src/killswitch/killswitch.service.spec.ts
  • Modified: apps/orchestrator/src/killswitch/killswitch.module.ts
  • Modified: apps/orchestrator/src/valkey/types/events.types.ts

Key Features

  1. Best-effort cleanup: Continues even if individual steps fail
  2. Event emission: Publishes agent.cleanup event with status details
  3. Resource tracking: Reports success/failure for each cleanup step
  4. Service integration: Properly injected via NestJS DI
  5. Reusable: Can be called from any service

Test Coverage

All 25 tests pass (10 CleanupService, 8 KillswitchService, 7 Controller)

Cleanup order: Docker -> Git worktree -> Valkey state -> Event emission

Clean up resources when agent terminates. ## Acceptance Criteria - [x] src/killswitch/cleanup.service.ts implemented - [x] Stop Docker container - [x] Remove Docker container - [x] Remove git worktree - [x] Clear Valkey state - [x] Emit cleanup event - [x] Run cleanup on: agent completion, agent failure, killswitch - [x] NestJS service with proper dependency injection - [x] Comprehensive unit tests with 10 test cases covering all scenarios - [x] Integrated with KillswitchService ## Implementation Summary Created CleanupService as a dedicated, reusable service for agent resource cleanup. ### Files Created/Modified - Created: apps/orchestrator/src/killswitch/cleanup.service.ts - Created: apps/orchestrator/src/killswitch/cleanup.service.spec.ts (10 test cases) - Modified: apps/orchestrator/src/killswitch/killswitch.service.ts - Modified: apps/orchestrator/src/killswitch/killswitch.service.spec.ts - Modified: apps/orchestrator/src/killswitch/killswitch.module.ts - Modified: apps/orchestrator/src/valkey/types/events.types.ts ### Key Features 1. Best-effort cleanup: Continues even if individual steps fail 2. Event emission: Publishes agent.cleanup event with status details 3. Resource tracking: Reports success/failure for each cleanup step 4. Service integration: Properly injected via NestJS DI 5. Reusable: Can be called from any service ### Test Coverage All 25 tests pass (10 CleanupService, 8 KillswitchService, 7 Controller) Cleanup order: Docker -> Git worktree -> Valkey state -> Event emission
jason.woltje added this to the M6-AgentOrchestration (0.0.6) milestone 2026-02-02 22:10:00 +00:00
jason.woltje added the orchestrator label 2026-02-02 22:10:00 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaic/stack#253