Skip to content

feat(context,common,config): Context-Adaptive Memory Phase 1 MVP#4586

Merged
bug-ops merged 2 commits into
mainfrom
cam-phase-1-mvp
May 28, 2026
Merged

feat(context,common,config): Context-Adaptive Memory Phase 1 MVP#4586
bug-ops merged 2 commits into
mainfrom
cam-phase-1-mvp

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented May 28, 2026

Summary

Implements Context-Adaptive Memory (CAM) Phase 1 MVP per spec specs/062-context-adaptive-memory/ and issue #4547.

Replaces the current binary keep/discard compaction with a three-level fidelity model (Full / Compressed / Placeholder) that reduces token usage 40–60% in long sessions while preserving structural coherence.

  • ContextFidelity enum + PlannedToolHint struct in zeph-common (shared by zeph-llm and zeph-context)
  • FidelityScorer::score_and_apply() — heuristic scorer: temporal decay, role importance, keyword overlap, plan-tool relevance; weight-normalized; tool-pair atomic downgrade (INV-03); consecutive same-role Placeholder merge (INV-04)
  • Proactive AgeMem regrade trigger in maybe_compact() with regraded_this_turn guard (INV-06)
  • Placeholder exclusion from hard compaction summarizer input (INV-02)
  • FidelityConfig::validate() checks threshold ordering at config load
  • [context.fidelity] config section; enabled = false default — no behavioral change when disabled (AC-10)
  • Criterion benchmark fidelity_score_and_apply_500 for AC-11 (<2ms / 500 messages)

Acceptance criteria

All 12 AC from spec §11 addressed:

  • AC-01: ≥10 unit tests in zeph-context -E 'test(fidelity)'
  • AC-02: Scoring after apply_prepared_context() returns (INV-01)
  • AC-03..AC-05: Score range, tool pair atomicity, no consecutive same-role Placeholders
  • AC-06: Placeholder exclusion from compaction input
  • AC-07..AC-08: regraded_this_turn reset + double-regrade prevention
  • AC-09: memory_first == true bypass tested
  • AC-10: enabled = false is a true no-op
  • AC-11: Criterion benchmark added
  • AC-12: inserted_count incremental across all 11 insertion paths, tested

Test plan

  • cargo nextest run -p zeph-context -E 'test(fidelity)' — all fidelity unit tests
  • cargo nextest run --workspace --lib --bins — 10150 tests pass
  • RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --locked — clean
  • Live session with context.fidelity.enabled = true in .local/config/testing.toml per playbook .local/testing/playbooks/context-adaptive-memory.md

Closes #4547

@bug-ops bug-ops added enhancement New feature or request memory zeph-memory crate (SQLite) P2 High value, medium complexity context Context management and message handling labels May 28, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes core zeph-core crate dependencies Dependency updates config Configuration file changes size/XL Extra large PR (500+ lines) labels May 28, 2026
@bug-ops bug-ops enabled auto-merge (squash) May 28, 2026 22:22
@bug-ops bug-ops force-pushed the cam-phase-1-mvp branch from c1715a0 to 4e375af Compare May 28, 2026 22:22
bug-ops added 2 commits May 29, 2026 00:40
…1 MVP

Three-level fidelity scoring (Full/Compressed/Placeholder) for context
messages via a heuristic FidelityScorer combining temporal decay, role
importance, keyword overlap, and plan-tool relevance signals. Weight
normalization over active signals ensures scores stay in [0.0, 1.0].

Key components:
- ContextFidelity enum and PlannedToolHint struct in zeph-common
- FidelityScorer::score_and_apply() in zeph-context with 10+ unit tests
  covering all AC-01..AC-12 cases including tool pair atomicity (INV-03),
  consecutive same-role Placeholder merge (INV-04), and exempt message set
  (INV-07..INV-10)
- Proactive AgeMem regrade in maybe_compact() with regraded_this_turn guard
  (INV-06) to prevent double-regrade within a turn
- Placeholder exclusion from hard compaction summarizer input (INV-02)
- FidelityConfig::validate() checking threshold ordering
- [context.fidelity] config section; enabled=false default (no behavioral
  change when disabled)
- Criterion benchmark fidelity_score_and_apply_500 for AC-11 (<2ms target)

Closes #4547
PlannedToolHint is #[non_exhaustive] so struct literal syntax in doc-tests
is rejected (external context). Add PlannedToolHint::new() constructor and
update the doc-test to use it.

Fix advance_turn() doc-test that accessed the private regraded_this_turn
field directly; rewrite using set_regraded_this_turn() and
should_proactively_regrade() which are the public API.

Fix needless_raw_string_hashes lint in FidelityConfig test.
Fix useless vec! lint in compaction Placeholder exclusion test.
Fix doc_markdown lint in fidelity_scorer benchmark.
@bug-ops bug-ops force-pushed the cam-phase-1-mvp branch from 9791ce3 to 5a934cf Compare May 28, 2026 22:40
@bug-ops bug-ops merged commit da3d096 into main May 28, 2026
32 checks passed
@bug-ops bug-ops deleted the cam-phase-1-mvp branch May 28, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Configuration file changes context Context management and message handling core zeph-core crate dependencies Dependency updates documentation Improvements or additions to documentation enhancement New feature or request llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) P2 High value, medium complexity rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement: Context-Adaptive Memory (CAM) — Phase 1 MVP

1 participant