feat(context,memory): persist ContextFidelity per message for cross-turn floor invariant (#4550)#4615
Merged
Merged
Conversation
d39ac12 to
ca757d0
Compare
…urn floor invariant (#4550) CAM Phase 2-B: fidelity levels are now written to SQLite after each scoring pass and reloaded into Message::metadata.fidelity_tag on the next turn. - db (migration 095): add fidelity_tag INTEGER NOT NULL DEFAULT 0 to messages table (SQLite additive ALTER TABLE; PostgreSQL SMALLINT NOT NULL DEFAULT 0) - zeph-common: ContextFidelity::from_u8 — DB integer → enum; unknown → Full (safe default) - zeph-memory: MessageStore::update_fidelity_tags batch-writes in a single transaction; load_history / load_history_filtered populate fidelity_tag; 0 → None sentinel avoids false floor on pre-CAM rows; 4 new round-trip tests - zeph-context: score_and_apply gains allow_upgrade: bool — false enforces floor (Compressed cannot upgrade to Full; Placeholder cannot upgrade at all); true bypasses floor on the proactive regrade path; more_restrictive() propagates floor through tool-use/tool-result atomicity pairs; 8 new floor invariant tests; truncate_to_tokens uses str::floor_char_boundary (stable since 1.91) - zeph-agent-context: persist_fidelity_tags private helper batch-writes after normal scoring and after prograde path so floor constraints survive to the next turn Closes #4550
b0a4b98 to
d939f16
Compare
This was referenced May 29, 2026
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
CAM Phase 2-B: fidelity levels are now persisted to SQLite after each scoring pass and reloaded on the next turn, enforcing the floor invariant across conversation turns.
zeph-db): additiveALTER TABLE messages ADD COLUMN fidelity_tag INTEGER NOT NULL DEFAULT 0(SQLite ≥ 3.37 O(1); PostgreSQLSMALLINT NOT NULL DEFAULT 0)ContextFidelity::from_u8(zeph-common): converts DB integer → enum; unknown values →Full(safe default);0→Nonesentinel avoids false floor on pre-CAM rowsMessageStore::update_fidelity_tags(zeph-memory): batch-writes(MessageId, u8)pairs in a single transaction; no-op when slice is empty;load_history/load_history_filterednow populatefidelity_tagfrom DBzeph-context):score_and_applygainsallow_upgrade: bool—falseenforces floor (Compressed cannot upgrade to Full; Placeholder cannot upgrade at all);truebypasses floor on the proactive regrade path;more_restrictive()propagates floor through tool-use / tool-result atomicity pairspersist_fidelity_tags(zeph-agent-context): private helper that batch-writes after normal scoring and after regrade path, so floor constraints survive to the next turntruncate_to_tokens(zeph-context): manualis_char_boundarybackward scan replaced withstr::floor_char_boundary(stable since Rust 1.91)Test plan
zeph-memory(update_fidelity_tags_round_trip,placeholder_round_trip,zero_maps_to_none,empty_is_noop) — all passzeph-context— all passzeph-common,zeph-context,zeph-memorypassCloses #4550