UAT: PlanLifecycleService missing rollback_plan service method - CLI bypasses service layer #3677

Open
opened 2026-04-05 21:30:46 +00:00 by freemo · 2 comments
Owner

Bug Report

What was tested:
PlanLifecycleService in src/cleveragents/application/services/plan_lifecycle_service.py — specifically looking for a rollback_plan method corresponding to the agents plan rollback CLI command.

Expected behavior (from spec):
The spec defines agents plan rollback [--yes|-y] <PLAN_ID> <CHECKPOINT_ID> as a CLI command (specification.md line 346). Following the service layer pattern used by all other plan lifecycle operations (use_action, execute_plan, apply_plan, cancel_plan), there should be a corresponding rollback_plan(plan_id, checkpoint_id) method on PlanLifecycleService that:

  1. Validates the plan exists and is in a valid state for rollback
  2. Delegates to CheckpointService.rollback_to_checkpoint()
  3. Updates plan state appropriately
  4. Emits domain events

Actual behavior:
PlanLifecycleService has no rollback_plan method. The CLI command agents plan rollback bypasses the service layer entirely and calls CheckpointService.rollback_to_checkpoint() directly from the CLI layer. This means:

  • No plan state validation before rollback
  • No domain events emitted for plan rollback via the lifecycle service
  • Business logic is in the CLI layer rather than the service layer

Code locations:

  • src/cleveragents/application/services/plan_lifecycle_service.py — missing rollback_plan method
  • src/cleveragents/application/services/checkpoint_service.py — has rollback_to_checkpoint() (line 259) and selective_rollback() (line 468)
  • The plan lifecycle service docstring table shows only: use_action, execute_plan, apply_plan — no rollback

Impact:

  • Architectural inconsistency: all other plan lifecycle operations go through PlanLifecycleService, but rollback bypasses it
  • Missing plan state validation before rollback (e.g., should not rollback an already-applied plan)
  • Missing lifecycle domain events for rollback operations

Steps to reproduce (code analysis):

  1. Read src/cleveragents/application/services/plan_lifecycle_service.py
  2. Search for rollback_plan — not found
  3. Read src/cleveragents/cli/commands/plan.py — rollback command calls CheckpointService directly

Metadata

  • Branch: fix/plan-lifecycle-service-rollback-method
  • Commit Message: fix(plan-lifecycle): add rollback_plan method to PlanLifecycleService
  • Milestone: (none — backlog)
  • Parent Epic: #397

Subtasks

  • Add rollback_plan(plan_id: str, checkpoint_id: str) -> None method to PlanLifecycleService
  • Implement plan state validation before delegating to CheckpointService.rollback_to_checkpoint()
  • Emit appropriate domain events for rollback lifecycle transition
  • Update CLI agents plan rollback command to call PlanLifecycleService.rollback_plan() instead of CheckpointService directly
  • Write Behave unit tests (TDD: failing test first) covering the new method and state validation
  • Update PlanLifecycleService docstring table to include rollback_plan
  • Ensure all nox stages pass

Definition of Done

  • PlanLifecycleService.rollback_plan(plan_id, checkpoint_id) exists and is statically typed
  • CLI agents plan rollback routes through PlanLifecycleService, not directly to CheckpointService
  • Plan state is validated before rollback (raises appropriate exception for invalid states)
  • Domain events are emitted for rollback lifecycle transitions
  • Behave unit tests cover the new method, state validation, and domain event emission
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone v3.7.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Bug Report **What was tested:** `PlanLifecycleService` in `src/cleveragents/application/services/plan_lifecycle_service.py` — specifically looking for a `rollback_plan` method corresponding to the `agents plan rollback` CLI command. **Expected behavior (from spec):** The spec defines `agents plan rollback [--yes|-y] <PLAN_ID> <CHECKPOINT_ID>` as a CLI command (specification.md line 346). Following the service layer pattern used by all other plan lifecycle operations (`use_action`, `execute_plan`, `apply_plan`, `cancel_plan`), there should be a corresponding `rollback_plan(plan_id, checkpoint_id)` method on `PlanLifecycleService` that: 1. Validates the plan exists and is in a valid state for rollback 2. Delegates to `CheckpointService.rollback_to_checkpoint()` 3. Updates plan state appropriately 4. Emits domain events **Actual behavior:** `PlanLifecycleService` has no `rollback_plan` method. The CLI command `agents plan rollback` bypasses the service layer entirely and calls `CheckpointService.rollback_to_checkpoint()` directly from the CLI layer. This means: - No plan state validation before rollback - No domain events emitted for plan rollback via the lifecycle service - Business logic is in the CLI layer rather than the service layer **Code locations:** - `src/cleveragents/application/services/plan_lifecycle_service.py` — missing `rollback_plan` method - `src/cleveragents/application/services/checkpoint_service.py` — has `rollback_to_checkpoint()` (line 259) and `selective_rollback()` (line 468) - The plan lifecycle service docstring table shows only: `use_action`, `execute_plan`, `apply_plan` — no rollback **Impact:** - Architectural inconsistency: all other plan lifecycle operations go through `PlanLifecycleService`, but rollback bypasses it - Missing plan state validation before rollback (e.g., should not rollback an already-applied plan) - Missing lifecycle domain events for rollback operations **Steps to reproduce (code analysis):** 1. Read `src/cleveragents/application/services/plan_lifecycle_service.py` 2. Search for `rollback_plan` — not found 3. Read `src/cleveragents/cli/commands/plan.py` — rollback command calls `CheckpointService` directly --- ## Metadata - **Branch**: `fix/plan-lifecycle-service-rollback-method` - **Commit Message**: `fix(plan-lifecycle): add rollback_plan method to PlanLifecycleService` - **Milestone**: *(none — backlog)* - **Parent Epic**: #397 ## Subtasks - [ ] Add `rollback_plan(plan_id: str, checkpoint_id: str) -> None` method to `PlanLifecycleService` - [ ] Implement plan state validation before delegating to `CheckpointService.rollback_to_checkpoint()` - [ ] Emit appropriate domain events for rollback lifecycle transition - [ ] Update CLI `agents plan rollback` command to call `PlanLifecycleService.rollback_plan()` instead of `CheckpointService` directly - [ ] Write Behave unit tests (TDD: failing test first) covering the new method and state validation - [ ] Update `PlanLifecycleService` docstring table to include `rollback_plan` - [ ] Ensure all nox stages pass ## Definition of Done - [ ] `PlanLifecycleService.rollback_plan(plan_id, checkpoint_id)` exists and is statically typed - [ ] CLI `agents plan rollback` routes through `PlanLifecycleService`, not directly to `CheckpointService` - [ ] Plan state is validated before rollback (raises appropriate exception for invalid states) - [ ] Domain events are emitted for rollback lifecycle transitions - [ ] Behave unit tests cover the new method, state validation, and domain event emission - [ ] All nox stages pass - [ ] Coverage >= 97% > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.7.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Backlog — Architectural consistency issue. Rollback works but bypasses the service layer pattern used by all other plan lifecycle operations.
  • Milestone: None (backlog)
  • Story Points: 5 — L — Requires adding a new service method with state validation, domain event emission, updating the CLI to route through the service, and comprehensive tests.
  • MoSCoW: Should Have — All other plan lifecycle operations go through PlanLifecycleService. Rollback bypassing this layer means no state validation and no domain events, which is an architectural inconsistency that should be corrected.
  • Parent Epic: #397

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Backlog — Architectural consistency issue. Rollback works but bypasses the service layer pattern used by all other plan lifecycle operations. - **Milestone**: None (backlog) - **Story Points**: 5 — L — Requires adding a new service method with state validation, domain event emission, updating the CLI to route through the service, and comprehensive tests. - **MoSCoW**: Should Have — All other plan lifecycle operations go through `PlanLifecycleService`. Rollback bypassing this layer means no state validation and no domain events, which is an architectural inconsistency that should be corrected. - **Parent Epic**: #397 --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
freemo referenced this issue from a commit 2026-04-06 07:20:15 +00:00
```
Author
Owner

PR #3911 created on branch fix/plan-lifecycle-service-rollback-method. I will monitor and handle all review feedback until merged.

Implementation summary:

  • Added PLAN_ROLLED_BACK event type to EventType enum
  • Added rollback_plan(plan_id, checkpoint_id) -> RollbackResult to PlanLifecycleService with state validation and domain event emission
  • Updated CLI agents plan rollback to route through PlanLifecycleService.rollback_plan() instead of CheckpointService directly
  • Added 11 Behave scenarios covering state validation, domain events, and delegation
  • Typecheck: 0 errors

Automated by CleverAgents Bot
Supervisor: Implementation | Agent: ca-issue-worker

PR #3911 created on branch `fix/plan-lifecycle-service-rollback-method`. I will monitor and handle all review feedback until merged. **Implementation summary:** - Added `PLAN_ROLLED_BACK` event type to `EventType` enum - Added `rollback_plan(plan_id, checkpoint_id) -> RollbackResult` to `PlanLifecycleService` with state validation and domain event emission - Updated CLI `agents plan rollback` to route through `PlanLifecycleService.rollback_plan()` instead of `CheckpointService` directly - Added 11 Behave scenarios covering state validation, domain events, and delegation - Typecheck: 0 errors --- **Automated by CleverAgents Bot** Supervisor: Implementation | Agent: ca-issue-worker
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#3677
No description provided.