feat(context,common,config): Context-Adaptive Memory Phase 1 MVP#4586
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.ContextFidelityenum +PlannedToolHintstruct inzeph-common(shared byzeph-llmandzeph-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)maybe_compact()withregraded_this_turnguard (INV-06)FidelityConfig::validate()checks threshold ordering at config load[context.fidelity]config section;enabled = falsedefault — no behavioral change when disabled (AC-10)fidelity_score_and_apply_500for AC-11 (<2ms / 500 messages)Acceptance criteria
All 12 AC from spec §11 addressed:
zeph-context -E 'test(fidelity)'apply_prepared_context()returns (INV-01)regraded_this_turnreset + double-regrade preventionmemory_first == truebypass testedenabled = falseis a true no-opinserted_countincremental across all 11 insertion paths, testedTest plan
cargo nextest run -p zeph-context -E 'test(fidelity)'— all fidelity unit testscargo nextest run --workspace --lib --bins— 10150 tests passRUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --locked— cleancontext.fidelity.enabled = truein.local/config/testing.tomlper playbook.local/testing/playbooks/context-adaptive-memory.mdCloses #4547