Commit Graph

1 Commits

Author SHA1 Message Date
Dragan Spiridonov 6e0e655ca7 fix(learning): getStats falls back to DB aggregation when counters are zero (#454)
`QEReasoningBank.getStats()` only read `this.stats`, an in-memory object
initialized to zeros per process. Every Claude Code hook spawns a fresh
node — so every `aqe hooks stats` call reported zero routingRequests /
learningOutcomes / patternSuccessRate regardless of historical data.
This blocked session-start observability, pattern promotion thresholds,
and experience consolidation triggers.

Add a narrow `SQLitePatternStore.getAggregateOutcomeStats()` method that
counts routing_outcomes, qe_pattern_usage, and the avg(success_rate) of
qe_patterns with non-zero usage_count. `getStats()` uses in-memory
counters when non-zero (current-process data) and falls back to the DB
aggregate otherwise. Sentinel routing rows (quality_score = -1) count
toward the total but are excluded from avgRoutingConfidence so partially
closed turns don't drag the average.

Verified: `aqe hooks stats --json` now reports routingRequests: 1904,
avgRoutingConfidence: 0.396, learningOutcomes: 272, patternSuccessRate:
0.75 against the project's memory.db — previously all zero.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 10:02:10 +00:00