Files
proffesor-for-testing__agen…/docs/analysis/patterns-db-not-updating.md
Profa b3d2018ee2 feat: v1.8.0 - Quality Hardening & Pattern Isolation
Critical bug fixes and code quality improvements from brutal-honest-review.

## Critical Fixes (9/10 completed, 1 deferred)

1. Fixed Agent Pattern Isolation (CRITICAL)
   - Added SwarmMemoryManager.queryPatternsByAgent()
   - SQL filtering by agent_id in metadata
   - Each agent now isolated

2. Fixed Async Method Cascade
   - Changed getPatterns() to async
   - Fixed 10 callers across 6 files
   - Build passes

3. Fixed Misleading Logging
   - Added isRealAgentDB() detection
   - Honest mock vs real reporting

4. Consolidated Embedding Generation
   - Created EmbeddingGenerator utility
   - Removed 50+ duplicate lines

5. Added AgentDB Initialization Checks
   - Empty DB detection
   - HNSW index verification

6. Integration Test Suite
   - 26 new test cases
   - Error path coverage

7. Repository Cleanup
   - Removed 19 temp test files

8. New QE Skill: sherlock-review
   - Evidence-based investigative review
   - 38 QE skills total

9. Deferred: Wire Up Real Test Execution
   - Deferred to v1.9.0 (documented)

## Statistics
- Fixes: 9/10 (90%, 1 deferred)
- Files Modified: 16
- Files Created: 3
- Files Deleted: 19
- Integration Tests: 26
- Build: PASSING

## Breaking Changes
- getPatterns() now async - add await

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 12:32:03 +00:00

7.6 KiB

Why patterns.db Is NOT Being Updated

Date: November 16, 2025 Issue: .agentic-qe/patterns.db last modified October 24, not receiving new patterns


Root Cause Analysis

The Problem

QE agents are storing patterns in agentdb.db (via AgentDB), but NOT in patterns.db (via QEReasoningBank).

Evidence

  1. patterns.db last modified: October 24, 2025
  2. agentdb.db episodes: 1,747 records (actively updated)
  3. Test execution added: 14 new episodes to agentdb.db
  4. patterns.db change: 0 records added

Code Analysis

How QEReasoningBank is Initialized

File: src/agents/TestGeneratorAgent.ts:144-146

// Constructor - Line 144
this.reasoningBank = new QEReasoningBank({
  minQuality: 0.7
  // ❌ NO DATABASE PROVIDED
});

File: src/agents/TestGeneratorAgent.ts:188-191

// Later in initializeComponents() - Line 188
this.reasoningBank = new QEReasoningBank({
  minQuality: 0.7,
  database: db  // ✅ Database provided
});

The Issue

File: src/reasoning/QEReasoningBank.ts:109-118

constructor(config: { minQuality?: number; database?: Database } = {}) {
  this.vectorSimilarity = new VectorSimilarity({ useIDF: true });
  this.qualityScorer = new PatternQualityScorer();
  this.minQuality = config.minQuality ?? 0.7;
  this.database = config.database;  // ← Database is optional

  // Initialize database adapter if database is provided
  if (this.database) {
    this.dbAdapter = new PatternDatabaseAdapter(this.database);
  }
  // ❌ If no database, dbAdapter is undefined
}

File: src/reasoning/QEReasoningBank.ts:224-233

// NEW: Persist to database using adapter
if (this.dbAdapter) {  // ← This check fails if no database
  try {
    await this.dbAdapter.storePattern(pattern);
    console.log(`[QEReasoningBank] ✅ Persisted pattern ${pattern.id} to database`);
  } catch (error) {
    console.error(`[QEReasoningBank] ❌ Failed to persist pattern ${pattern.id}:`, error);
  }
}
// ⚠️ If dbAdapter is undefined, patterns are stored in memory only

What Actually Happens

Pattern Storage Flow

Agent generates test
       ↓
   Pattern created
       ↓
   ┌─────────────────────────────────────┐
   │ QEReasoningBank.storePattern()      │
   │                                     │
   │ 1. Store in memory ✅               │
   │ 2. Generate vector embedding ✅     │
   │ 3. Update indexes ✅                │
   │ 4. Check if (this.dbAdapter) ❌     │
   │    → dbAdapter is undefined         │
   │    → Skip database persistence      │
   └─────────────────────────────────────┘
       ↓
   Pattern stored in MEMORY ONLY
   (Lost when agent terminates)

Why AgentDB Gets Patterns

File: src/agents/BaseAgent.ts:907-911

const patternId = await this.agentDB.store(pattern);
const storeTime = Date.now() - startTime;

console.info(
  `[${this.agentId.id}] ✅ ACTUALLY stored pattern in AgentDB: ${patternId} (${storeTime}ms)`
);

This is SEPARATE from QEReasoningBank!


The Dual Storage Problem

Two Parallel Pattern Storage Systems

  1. AgentDB (agentdb.db)

    • Used by: BaseAgent for learning experiences
    • Storage: Via this.agentDB.store()
    • Status: ✅ WORKING
    • Records: 1,747 episodes
  2. QEReasoningBank (patterns.db)

    • Used by: QE agents for test patterns
    • Storage: Via this.reasoningBank.storePattern()
    • Status: ❌ NOT WORKING (no database adapter)
    • Records: Not updated since October 24

Why This Matters

AgentDB patterns (episodes):

  • Generic learning experiences
  • Any agent action/reward
  • Vector embeddings for similarity
  • Used for: Agent learning, recommendations

QEReasoningBank patterns (test patterns):

  • Specific to test generation
  • Test templates, frameworks, quality scores
  • Used for: Test pattern matching, reuse

How to Fix

Option 1: Ensure Database is Provided to QEReasoningBank

File: src/agents/TestGeneratorAgent.ts

Change initialization to always provide database:

// In constructor
if (this.patternConfig.enabled) {
  // Get database from memoryStore immediately
  const db = await this.getDatabaseFromMemoryStore();

  this.reasoningBank = new QEReasoningBank({
    minQuality: 0.7,
    database: db  // ✅ Provide database upfront
  });

  await this.reasoningBank.initialize();
}

Option 2: Use AgentDB for All Pattern Storage

Remove patterns.db entirely and consolidate all pattern storage in AgentDB:

// Store patterns in AgentDB instead of QEReasoningBank
await this.agentDB.store({
  type: 'test-pattern',
  domain: 'test-generation',
  pattern_data: JSON.stringify(pattern),
  vector: patternEmbedding
});

Option 3: Initialize QEReasoningBank with patterns.db Path

Modify QEReasoningBank to create its own database:

export class QEReasoningBank {
  constructor(config: {
    minQuality?: number;
    database?: Database;
    dbPath?: string;  // ← New option
  } = {}) {
    // If dbPath provided but no database, create one
    if (config.dbPath && !config.database) {
      this.database = new Database(config.dbPath);
      this.dbAdapter = new PatternDatabaseAdapter(this.database);
    }
  }
}

Current State Summary

What's Working ✅

  1. AgentDB pattern storage - All 1,747 episodes stored successfully
  2. Pattern retrieval from AgentDB - Semantic search works
  3. Learning system - Agents learn and store experiences
  4. Memory-only patterns - QEReasoningBank stores patterns in memory during agent execution

What's NOT Working ❌

  1. patterns.db persistence - No patterns written since October 24
  2. QEReasoningBank database integration - dbAdapter is undefined
  3. Pattern survival - Memory patterns lost when agent terminates
  4. Cross-session pattern reuse - Can't reuse patterns from previous runs via QEReasoningBank

Impact

Low Impact (For Now)

The lack of patterns.db updates has minimal impact currently because:

  1. ✅ Patterns ARE being stored in AgentDB
  2. ✅ Learning IS working via AgentDB
  3. ✅ Agents can retrieve past patterns via AgentDB
  4. ✅ Vector similarity search works via AgentDB

Potential Future Issues

  1. Test pattern reuse - Can't reuse test templates from patterns.db
  2. Pattern library growth - No accumulation of test patterns
  3. Cross-project sharing - Can't share patterns via patterns.db
  4. Duplicate storage - Storing similar data in two systems

Recommendation

Short Term: Document Current Behavior

Status: AgentDB is the primary pattern storage. patterns.db is legacy/unused.

Long Term: Choose One Storage System

Option A: Use AgentDB exclusively (recommended)

  • Remove patterns.db references
  • Consolidate all pattern storage in AgentDB
  • Single source of truth

Option B: Fix QEReasoningBank database initialization

  • Ensure database is always provided
  • Maintain dual storage for different purposes
  • More complexity but clearer separation

Conclusion

You are 100% correct - patterns.db is NOT being updated.

Why: QEReasoningBank is initialized without a database, so patterns are stored in memory only.

Solution: Either fix the initialization to provide a database, or consolidate all pattern storage in AgentDB.

Current Impact: Low - learning works via AgentDB, but test pattern library (patterns.db) is stale.