Skip to content

enhancement(core): implement functional LearningEngine (#1913)#1929

Merged
bug-ops merged 3 commits intomainfrom
learning-engine-impl
Mar 16, 2026
Merged

enhancement(core): implement functional LearningEngine (#1913)#1929
bug-ops merged 3 commits intomainfrom
learning-engine-impl

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 16, 2026

Summary

Replaces the LearningEngine stub with real behavioral learning from interaction history.

  • New SQLite table learned_preferences (migration 036) for cross-session preference persistence
  • Incremental user_corrections scanning via watermark (every 5 turns when correction_detection is enabled)
  • Regex-based preference inference (verbosity, format, language) with word-boundary anchors to prevent false positives
  • High-confidence preferences injected into the volatile system prompt block (after <!-- cache:volatile -->, preserving prompt caching)
  • Injected values sanitized (strip \n/\r) with length caps (key ≤ 128 B, value ≤ 256 B)
  • Gated on LearningConfig::correction_detection, independent of LearningConfig::enabled
  • 40 new unit and integration tests; total: 6072 passed

Closes #1913

Test plan

  • cargo +nightly fmt --check — clean
  • cargo clippy --workspace --features full -- -D warnings — clean
  • cargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins — 6072 passed, 12 skipped
  • Architecture reviewed (rust-architect + rust-critic)
  • Implementation reviewed (rust-code-reviewer, approved after fixes)
  • Security audited (no critical/high findings)

bug-ops added 2 commits March 16, 2026 20:20
Replace the stub LearningEngine with real behavioral learning:

- Add SQLite table `learned_preferences` (migration 036) for cross-session
  preference persistence with UPSERT semantics
- Add `sqlite/preferences.rs` with upsert, load, and watermark-based load
  functions; enforces key ≤ 128 B / value ≤ 256 B with warn! on truncation
- Implement `LearningEngine::tick()`, `should_analyze()`, `mark_analyzed()`
  to trigger incremental analysis every 5 turns
- Implement `Agent::analyze_and_learn()`: reads new `user_corrections` rows
  since last watermark, runs regex-based preference inference, persists
  high-confidence facts (Wilson score threshold) to `learned_preferences`
- Implement `Agent::inject_learned_preferences()`: loads up to 3 highest-
  confidence preferences, sanitizes values (strip \\n/\\r), appends to the
  volatile system prompt block (after <!-- cache:volatile --> to preserve
  prompt caching, closes #1082 regression risk)
- Gate analysis on `LearningConfig::correction_detection` (independent of
  `LearningConfig::enabled` which controls skill auto-improvement)
- Preference inference uses word-boundary anchors to avoid false positives;
  covers verbosity, format, and language categories
- 40 new unit and integration tests; total test count: 6072
@bug-ops bug-ops enabled auto-merge (squash) March 16, 2026 19:22
@github-actions github-actions bot added documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes core zeph-core crate size/XL Extra large PR (500+ lines) labels Mar 16, 2026
@bug-ops bug-ops merged commit 109d2c0 into main Mar 16, 2026
20 checks passed
@bug-ops bug-ops deleted the learning-engine-impl branch March 16, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate documentation Improvements or additions to documentation memory zeph-memory crate (SQLite) rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enhancement(core): LearningEngine is a stub — no actual behavioral learning from interaction patterns

1 participant