UAT: PlanApplyService.apply_with_validation_gate() never calls sandbox.commit() — Apply phase does not merge sandbox changes into real project resources #3839

Open
opened 2026-04-06 06:53:35 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/plan-apply-sandbox-commit
  • Commit Message: fix(apply): call sandbox.commit() in apply_with_validation_gate to merge changes into real resources
  • Milestone: (backlog — no milestone)
  • Parent Epic: #394

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

Summary

PlanApplyService.apply_with_validation_gate() in src/cleveragents/application/services/plan_apply_service.py never calls sandbox.commit() to merge sandbox changes into real project resources. The Apply phase transitions the plan to applied state but does not actually commit any sandbox changes to the real filesystem, git repository, or database.

What Was Tested

Code-level analysis of PlanApplyService.apply_with_validation_gate() against specification §19807-19891 (Apply Phase).

Expected Behavior (from spec)

Per specification §19807-19814:

  • Apply takes the sandboxed work product and makes it "real" in the project
  • Apply is a controlled commit step that separates "generated work" from "committed work"
  • After successful apply, changes have been committed to real project resources

Per specification §19865-19869:

  • When Apply succeeds: changes have been committed to real project resources

The sandbox infrastructure (src/cleveragents/infrastructure/sandbox/) has commit() methods on all sandbox implementations:

  • GitWorktreeSandbox.commit() — merges worktree changes back to main branch
  • CopyOnWriteSandbox.commit() — syncs changed files back to original path
  • TransactionSandbox.commit() — commits the database transaction
  • OverlaySandbox.commit() — commits overlay changes

Actual Behavior

PlanApplyService.apply_with_validation_gate() (lines 482-662) does:

  1. Validates the plan is not in terminal state
  2. Checks the changeset is not empty
  3. Checks validation gate (required validations passed)
  4. Creates a pre_apply checkpoint
  5. Calls persist_apply_summary() to store metadata
  6. Calls lifecycle.complete_apply() to transition plan state to applied

It never calls sandbox.commit() on any sandbox. The sandbox changes remain in the sandbox and are never merged into the real project resources.

Code Location

  • src/cleveragents/application/services/plan_apply_service.py, lines 482-662
  • The sandbox.commit() methods exist in src/cleveragents/infrastructure/sandbox/ but are never called from PlanApplyService
  • src/cleveragents/infrastructure/sandbox/strategy_adapter.py line 166 shows sandbox.commit() is available

Impact

This is a critical functional gap:

  • Plans that "apply successfully" do not actually apply any changes to real resources
  • The git worktree is never merged back to the main branch
  • Copy-on-write sandbox changes are never synced back
  • Database transactions are never committed
  • Users believe their plan was applied but no actual changes occurred

Steps to Reproduce

  1. Create a plan and run it through Strategize and Execute phases
  2. Call apply_with_validation_gate(plan_id)
  3. Observe that the plan transitions to applied state
  4. Check the real project resources — no changes have been made
  5. The sandbox still contains the changes but they were never committed

Subtasks

  • Add sandbox resolution logic to PlanApplyService (resolve sandbox from plan's sandbox_refs)
  • Call sandbox.commit() for each sandbox associated with the plan during Apply
  • Handle commit failures by calling handle_merge_failure() with conflict details
  • Update applied_artifacts with the commit results (commit hash, file list)
  • Add Behave tests for sandbox commit during Apply phase
  • Add integration tests verifying real resource changes after Apply

Definition of Done

  • PlanApplyService.apply_with_validation_gate() calls sandbox.commit() for all plan sandboxes
  • Commit failures are handled via handle_merge_failure()
  • applied_artifacts is populated with commit results
  • All existing tests pass
  • New Behave tests cover sandbox commit behavior
  • All nox stages pass
  • Coverage >= 97%

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

## Metadata - **Branch**: `fix/plan-apply-sandbox-commit` - **Commit Message**: `fix(apply): call sandbox.commit() in apply_with_validation_gate to merge changes into real resources` - **Milestone**: *(backlog — no milestone)* - **Parent Epic**: #394 > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.3.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. ## Summary `PlanApplyService.apply_with_validation_gate()` in `src/cleveragents/application/services/plan_apply_service.py` never calls `sandbox.commit()` to merge sandbox changes into real project resources. The Apply phase transitions the plan to `applied` state but does not actually commit any sandbox changes to the real filesystem, git repository, or database. ## What Was Tested Code-level analysis of `PlanApplyService.apply_with_validation_gate()` against specification §19807-19891 (Apply Phase). ## Expected Behavior (from spec) Per specification §19807-19814: - Apply takes the sandboxed work product and makes it "real" in the project - Apply is a controlled commit step that separates "generated work" from "committed work" - After successful apply, changes have been committed to real project resources Per specification §19865-19869: - When Apply succeeds: changes have been committed to real project resources The sandbox infrastructure (`src/cleveragents/infrastructure/sandbox/`) has `commit()` methods on all sandbox implementations: - `GitWorktreeSandbox.commit()` — merges worktree changes back to main branch - `CopyOnWriteSandbox.commit()` — syncs changed files back to original path - `TransactionSandbox.commit()` — commits the database transaction - `OverlaySandbox.commit()` — commits overlay changes ## Actual Behavior `PlanApplyService.apply_with_validation_gate()` (lines 482-662) does: 1. Validates the plan is not in terminal state 2. Checks the changeset is not empty 3. Checks validation gate (required validations passed) 4. Creates a pre_apply checkpoint 5. Calls `persist_apply_summary()` to store metadata 6. Calls `lifecycle.complete_apply()` to transition plan state to `applied` **It never calls `sandbox.commit()` on any sandbox.** The sandbox changes remain in the sandbox and are never merged into the real project resources. ## Code Location - `src/cleveragents/application/services/plan_apply_service.py`, lines 482-662 - The `sandbox.commit()` methods exist in `src/cleveragents/infrastructure/sandbox/` but are never called from `PlanApplyService` - `src/cleveragents/infrastructure/sandbox/strategy_adapter.py` line 166 shows `sandbox.commit()` is available ## Impact This is a critical functional gap: - Plans that "apply successfully" do not actually apply any changes to real resources - The git worktree is never merged back to the main branch - Copy-on-write sandbox changes are never synced back - Database transactions are never committed - Users believe their plan was applied but no actual changes occurred ## Steps to Reproduce 1. Create a plan and run it through Strategize and Execute phases 2. Call `apply_with_validation_gate(plan_id)` 3. Observe that the plan transitions to `applied` state 4. Check the real project resources — no changes have been made 5. The sandbox still contains the changes but they were never committed ## Subtasks - [ ] Add sandbox resolution logic to `PlanApplyService` (resolve sandbox from plan's `sandbox_refs`) - [ ] Call `sandbox.commit()` for each sandbox associated with the plan during Apply - [ ] Handle commit failures by calling `handle_merge_failure()` with conflict details - [ ] Update `applied_artifacts` with the commit results (commit hash, file list) - [ ] Add Behave tests for sandbox commit during Apply phase - [ ] Add integration tests verifying real resource changes after Apply ## Definition of Done - [ ] `PlanApplyService.apply_with_validation_gate()` calls `sandbox.commit()` for all plan sandboxes - [ ] Commit failures are handled via `handle_merge_failure()` - [ ] `applied_artifacts` is populated with commit results - [ ] All existing tests pass - [ ] New Behave tests cover sandbox commit behavior - All nox stages pass - Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
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.

Blocks
#394 Epic: Decision Framework
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3839
No description provided.