feat(correcting-plans): implement Predictive Error Prevention (Layer 4) with Error Pattern Database #571

Closed
opened 2026-03-04 23:39:44 +00:00 by freemo · 2 comments
Owner

Metadata

Field Value
Commit Message feat(correcting-plans): implement Predictive Error Prevention (Layer 4) with Error Pattern Database
Branch feature/m5-predictive-error-prevention

Summary

The specification defines a Layer 4: Predictive Error Prevention system (spec line ~19543) that learns from past failures to proactively prevent recurring errors. This feature is not tracked by any existing issue and has no implementation in the codebase.

Spec Reference

  • Section: Core Concepts > Correcting Plans > Layer 4: Predictive Error Prevention
  • Lines: 19543-19556

Description

The spec describes an Error Pattern Database that:

  1. Records historical failure patterns (e.g., "Async conversion in payment module" caused "Race condition in payment confirmation", "Timeout handling breaks idempotency")
  2. Maps each pattern to preventive checks (e.g., "Add explicit transaction boundaries", "Verify idempotency keys are preserved")
  3. Is consulted before plan execution to inject preventive guidance into the actor's context

Acceptance Criteria

  • Define ErrorPattern domain model with fields: pattern (text), historical_failures (list of strings), preventive_checks (list of strings), created_at, frequency, last_seen
  • Create database table error_patterns with appropriate indexes
  • Implement ErrorPatternRepository with CRUD + pattern-matching query
  • Implement ErrorPatternService that:
    • Records new failure patterns when plans fail (post-mortem analysis)
    • Matches current plan context against known patterns
    • Returns preventive checks for matched patterns
  • Wire into plan execution: before Execute phase, query ErrorPatternService and inject preventive checks into actor context as guidance
  • CLI: agents diagnostics should include error pattern statistics
  • Tests: unit tests for pattern matching, integration test for end-to-end flow

Suggested Milestone

v3.5.0 (Context Intelligence & Scaling)

Priority

Medium

Suggested Assignee

@freemo (architecture/complex domain logic)

Subtasks

  • Code: Implement ErrorPattern domain model, error_patterns DB table + Alembic migration, ErrorPatternRepository (CRUD + pattern matching), and ErrorPatternService (record failures, match patterns, return preventive checks)
  • Code: Wire ErrorPatternService into plan execution — query before Execute phase and inject preventive checks into actor context as guidance
  • Code: Add error pattern statistics to agents diagnostics CLI output
  • Docs: Update docs/specification.md cross-references and any relevant ADR if architectural decisions are made
  • Behave tests: Add BDD feature file features/correcting_plans/predictive_error_prevention.feature covering pattern recording, matching, and preventive check injection
  • Robot tests: Add Robot Framework integration test verifying end-to-end flow: plan fails → pattern recorded → subsequent plan receives preventive guidance
  • ASV benchmarks: Add ASV benchmark for pattern-matching query performance against large pattern databases (benchmarks/bench_error_pattern_matching.py)
  • Quality: coverage ≥97%: Verify via nox -s coverage_report
  • Quality: nox full suite: Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
## Metadata | Field | Value | |-------|-------| | **Commit Message** | `feat(correcting-plans): implement Predictive Error Prevention (Layer 4) with Error Pattern Database` | | **Branch** | `feature/m5-predictive-error-prevention` | ## Summary The specification defines a **Layer 4: Predictive Error Prevention** system (spec line ~19543) that learns from past failures to proactively prevent recurring errors. This feature is not tracked by any existing issue and has no implementation in the codebase. ## Spec Reference - **Section**: Core Concepts > Correcting Plans > Layer 4: Predictive Error Prevention - **Lines**: 19543-19556 ## Description The spec describes an Error Pattern Database that: 1. Records **historical failure patterns** (e.g., "Async conversion in payment module" caused "Race condition in payment confirmation", "Timeout handling breaks idempotency") 2. Maps each pattern to **preventive checks** (e.g., "Add explicit transaction boundaries", "Verify idempotency keys are preserved") 3. Is consulted **before plan execution** to inject preventive guidance into the actor's context ### Acceptance Criteria - [ ] Define `ErrorPattern` domain model with fields: `pattern` (text), `historical_failures` (list of strings), `preventive_checks` (list of strings), `created_at`, `frequency`, `last_seen` - [ ] Create database table `error_patterns` with appropriate indexes - [ ] Implement `ErrorPatternRepository` with CRUD + pattern-matching query - [ ] Implement `ErrorPatternService` that: - Records new failure patterns when plans fail (post-mortem analysis) - Matches current plan context against known patterns - Returns preventive checks for matched patterns - [ ] Wire into plan execution: before Execute phase, query ErrorPatternService and inject preventive checks into actor context as guidance - [ ] CLI: `agents diagnostics` should include error pattern statistics - [ ] Tests: unit tests for pattern matching, integration test for end-to-end flow ## Suggested Milestone v3.5.0 (Context Intelligence & Scaling) ## Priority Medium ## Suggested Assignee @freemo (architecture/complex domain logic) ## Subtasks - [ ] **Code**: Implement `ErrorPattern` domain model, `error_patterns` DB table + Alembic migration, `ErrorPatternRepository` (CRUD + pattern matching), and `ErrorPatternService` (record failures, match patterns, return preventive checks) - [ ] **Code**: Wire `ErrorPatternService` into plan execution — query before Execute phase and inject preventive checks into actor context as guidance - [ ] **Code**: Add error pattern statistics to `agents diagnostics` CLI output - [ ] **Docs**: Update `docs/specification.md` cross-references and any relevant ADR if architectural decisions are made - [ ] **Behave tests**: Add BDD feature file `features/correcting_plans/predictive_error_prevention.feature` covering pattern recording, matching, and preventive check injection - [ ] **Robot tests**: Add Robot Framework integration test verifying end-to-end flow: plan fails → pattern recorded → subsequent plan receives preventive guidance - [ ] **ASV benchmarks**: Add ASV benchmark for pattern-matching query performance against large pattern databases (`benchmarks/bench_error_pattern_matching.py`) - [ ] **Quality: coverage ≥97%**: Verify via `nox -s coverage_report` - [ ] **Quality: nox full suite**: Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done.
freemo self-assigned this 2026-03-05 00:29:58 +00:00
freemo added this to the v3.4.0 milestone 2026-03-05 00:29:58 +00:00
Author
Owner

Triage note (PM): Adding required ## Subtasks section per CONTRIBUTING.md template. The issue body has been updated to include the standard subtask checklist below.

The ## Subtasks section will be appended to the issue body.

**Triage note (PM):** Adding required `## Subtasks` section per CONTRIBUTING.md template. The issue body has been updated to include the standard subtask checklist below. The `## Subtasks` section will be appended to the issue body.
Author
Owner

CTO verification: Issue verified. Layer 4 Predictive Error Prevention is specified (lines ~19543-19556) and has no implementation. Queued for implementation after #572.

**CTO verification:** Issue verified. Layer 4 Predictive Error Prevention is specified (lines ~19543-19556) and has no implementation. Queued for implementation after #572.
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
#396 Epic: ACMS Context Pipeline
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#571
No description provided.