refactor(epic-1974): improve type safety - CompactionState, BoxFuture, schema helper#2014
Merged
refactor(epic-1974): improve type safety - CompactionState, BoxFuture, schema helper#2014
Conversation
…oxFuture consolidation, and schema helper
- TYPE-02: Consolidate BoxFuture type alias from 3 files into single pub(crate) definition in vector_store.rs
- Remove duplicate from sqlite_vector_store.rs
- Replace 8 inline Pin<Box<dyn Future>> in qdrant_ops.rs with alias
- Net: -25 LOC
- TYPE-06: Replace 4 boolean/u8 fields with CompactionState enum in ContextManager
- Enum variants: Ready, CompactedThisTurn{cooldown}, Cooling{turns_remaining}, Exhausted{warned}
- Makes invalid state combinations unrepresentable by type system
- All 12 mutation sites converted with explicit transition rules
- advance_turn() ordering documented and tested (S1 from critic)
- Transition map confirms Cooling→Exhausted impossible (S2 from critic)
- Proactive compression included in map (M5 from critic)
- 14 new unit tests for state transitions
- TYPE-03: Extract schema_type_name helper in LlmProvider
- Consolidate 3 duplicate type_name() patterns across providers
- New unit tests for schema generation
Test results:
- 5427/5427 tests passing (+15 new tests for state transitions)
- Clippy: clean
- Format: compliant
- Security audit: APPROVED (no unsafe code, no security issues)
- Performance: NEUTRAL (enum smaller than original booleans)
Closes #1974 (partial - TYPE-02, TYPE-03, TYPE-06 complete; TYPE-01 deferred)
This was
linked to
issues
Mar 19, 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
Implement type safety improvements from epic #1974 audit. Three changes improve maintainability and leverage Rust's type system:
BoxFuturefrom 3 definitions → 1 sharedpub(crate)alias (-25 LOC)CompactionStateenum (invalid states unrepresentable by type)Validation
Key Changes
TYPE-02: BoxFuture Consolidation
vector_store.rs: Definepub(crate) type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>sqlite_vector_store.rs: Remove duplicate, import from vector_store.rsqdrant_ops.rs: Replace 8 inlinePin<Box<dyn Future<...>>>with aliasTYPE-06: CompactionState Enum
compacted_this_turn,compaction_exhausted,exhaustion_warned,compaction_turns_sinceReady,CompactedThisTurn { cooldown },Cooling { turns_remaining },Exhausted { warned }advance_turn()ordering documented and testedCooling → ExhaustedimpossibleTYPE-03: Schema Helper
short_type_name<T>()inprovider.rsFiles Changed
Related Issues
.local/audit/002-type-safety-opportunities.mdChecklist