UAT: CorrectionService state is in-memory only — correction requests and results are lost across process restarts #3838

Open
opened 2026-04-06 06:52:21 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/backlog-correction-service-persistence
  • Commit Message: fix(correction): persist CorrectionRequest and CorrectionResult via CorrectionAttemptRepository
  • Milestone: (backlog — no milestone)
  • Parent Epic: #397

Background and Context

CorrectionService in src/cleveragents/application/services/correction_service.py stores all correction state in in-memory dictionaries (self._corrections, self._impacts, self._attempts, self._results). This means all correction requests, impact analyses, and results are lost when the CLI process exits.

The CorrectionAttemptRepository exists in src/cleveragents/infrastructure/database/repositories.py (line 5781) and the CorrectionAttemptRecord domain model exists in src/cleveragents/domain/models/core/correction.py, but CorrectionService does not use them for persistence.

Current Behavior

class CorrectionService:
    def __init__(self, ...):
        self._corrections: dict[str, CorrectionRequest] = {}  # in-memory only
        self._impacts: dict[str, CorrectionImpact] = {}       # in-memory only
        self._attempts: dict[str, list[CorrectionAttempt]] = {}  # in-memory only
        self._results: dict[str, CorrectionResult] = {}       # in-memory only

The CorrectionAttemptRepository is never used by CorrectionService.

Expected Behavior (from spec)

Per the specification (§ Correction Attempt Persistence and the correction_attempts table DDL):

  1. When request_correction() is called, a CorrectionAttemptRecord should be created and persisted via CorrectionAttemptRepository
  2. When execute_correction() completes, the CorrectionAttemptRecord.state should be updated to complete or failed
  3. list_corrections(plan_id) should query the database, not just in-memory state
  4. The agents plan diff --correction <CORRECTION_ATTEMPT_ID> command should be able to look up corrections from a previous CLI session

Impact

  • Running agents plan correct in one CLI invocation and then agents plan diff --correction in a subsequent invocation will fail because the correction is not persisted
  • Correction history is lost on process restart
  • The CorrectionAttemptRepository infrastructure is built but unused

Code Location

  • src/cleveragents/application/services/correction_service.pyCorrectionService.__init__() and all state-mutating methods
  • src/cleveragents/infrastructure/database/repositories.pyCorrectionAttemptRepository (line 5781) — exists but unused by CorrectionService
  • src/cleveragents/domain/models/core/correction.pyCorrectionAttemptRecord domain model
  • src/cleveragents/application/container.pyCorrectionService is wired without a CorrectionAttemptRepository

Subtasks

  • Add CorrectionAttemptRepository injection to CorrectionService.__init__
  • In request_correction(), persist a CorrectionAttemptRecord with state PENDING
  • In execute_correction(), update the record state to EXECUTING then COMPLETE/FAILED
  • In list_corrections(plan_id), query the database when a repository is available
  • Update the DI container to wire CorrectionAttemptRepository into CorrectionService
  • Add Behave BDD tests verifying persistence across service instantiations

Definition of Done

  • CorrectionAttemptRecord is persisted to the database when a correction is requested
  • The record state is updated to complete or failed after execution
  • agents plan diff --correction <ID> can look up corrections from a previous CLI session
  • Behave unit tests verify persistence
  • nox -e unit_tests passes
  • nox -e typecheck passes

Backlog note: This issue was discovered during autonomous operation
on milestone (active milestone at time of discovery). 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

## Metadata - **Branch**: `fix/backlog-correction-service-persistence` - **Commit Message**: `fix(correction): persist CorrectionRequest and CorrectionResult via CorrectionAttemptRepository` - **Milestone**: *(backlog — no milestone)* - **Parent Epic**: #397 ## Background and Context `CorrectionService` in `src/cleveragents/application/services/correction_service.py` stores all correction state in in-memory dictionaries (`self._corrections`, `self._impacts`, `self._attempts`, `self._results`). This means all correction requests, impact analyses, and results are lost when the CLI process exits. The `CorrectionAttemptRepository` exists in `src/cleveragents/infrastructure/database/repositories.py` (line 5781) and the `CorrectionAttemptRecord` domain model exists in `src/cleveragents/domain/models/core/correction.py`, but `CorrectionService` does not use them for persistence. ## Current Behavior ```python class CorrectionService: def __init__(self, ...): self._corrections: dict[str, CorrectionRequest] = {} # in-memory only self._impacts: dict[str, CorrectionImpact] = {} # in-memory only self._attempts: dict[str, list[CorrectionAttempt]] = {} # in-memory only self._results: dict[str, CorrectionResult] = {} # in-memory only ``` The `CorrectionAttemptRepository` is never used by `CorrectionService`. ## Expected Behavior (from spec) Per the specification (§ Correction Attempt Persistence and the `correction_attempts` table DDL): 1. When `request_correction()` is called, a `CorrectionAttemptRecord` should be created and persisted via `CorrectionAttemptRepository` 2. When `execute_correction()` completes, the `CorrectionAttemptRecord.state` should be updated to `complete` or `failed` 3. `list_corrections(plan_id)` should query the database, not just in-memory state 4. The `agents plan diff --correction <CORRECTION_ATTEMPT_ID>` command should be able to look up corrections from a previous CLI session ## Impact - Running `agents plan correct` in one CLI invocation and then `agents plan diff --correction` in a subsequent invocation will fail because the correction is not persisted - Correction history is lost on process restart - The `CorrectionAttemptRepository` infrastructure is built but unused ## Code Location - `src/cleveragents/application/services/correction_service.py` — `CorrectionService.__init__()` and all state-mutating methods - `src/cleveragents/infrastructure/database/repositories.py` — `CorrectionAttemptRepository` (line 5781) — exists but unused by `CorrectionService` - `src/cleveragents/domain/models/core/correction.py` — `CorrectionAttemptRecord` domain model - `src/cleveragents/application/container.py` — `CorrectionService` is wired without a `CorrectionAttemptRepository` ## Subtasks - [ ] Add `CorrectionAttemptRepository` injection to `CorrectionService.__init__` - [ ] In `request_correction()`, persist a `CorrectionAttemptRecord` with state `PENDING` - [ ] In `execute_correction()`, update the record state to `EXECUTING` then `COMPLETE`/`FAILED` - [ ] In `list_corrections(plan_id)`, query the database when a repository is available - [ ] Update the DI container to wire `CorrectionAttemptRepository` into `CorrectionService` - [ ] Add Behave BDD tests verifying persistence across service instantiations ## Definition of Done - [ ] `CorrectionAttemptRecord` is persisted to the database when a correction is requested - [ ] The record state is updated to `complete` or `failed` after execution - [ ] `agents plan diff --correction <ID>` can look up corrections from a previous CLI session - [ ] Behave unit tests verify persistence - [ ] `nox -e unit_tests` passes - [ ] `nox -e typecheck` passes > **Backlog note:** This issue was discovered during autonomous operation > on milestone *(active milestone at time of discovery)*. 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
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
#397 Epic: Server & Autonomy Infrastructure
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3838
No description provided.