refactor(acms): unify ContextFragment model hierarchies by extending CRP base types #598

Merged
freemo merged 1 commits from refactor/unify-context-fragment-models into master 2026-03-05 21:43:55 +00:00
Owner

Summary

Core domain types (FragmentProvenance, ContextFragment, ContextBudget, ContextPayload) now extend their CRP counterparts via Pydantic v2 inheritance, ensuring isinstance compatibility across the model hierarchy. This eliminates the duplicate model hierarchies that existed between the CRP layer and the core domain layer.

Changes

  • CRP base types made frozen=True: FragmentProvenance, ContextFragment, ContextBudget, AssembledContext — validated that no CRP consumer mutates these instances
  • CRP AssembledContext fields: fragments and strategies_used changed from list to tuple for frozen-model consistency
  • Core types extend CRP bases: FragmentProvenance(CRPFragmentProvenance), ContextFragment(CRPContextFragment), ContextBudget(CRPContextBudget), ContextPayload(CRPAssembledContext)
  • Removed duplicate ContextFragment dataclass from skeleton_compressor.py; service now uses core.context_fragment.ContextFragment
  • Updated project_context.py to pass tuples to frozen AssembledContext
  • Updated skeleton_compressor tests to handle model-level validation (Pydantic now rejects invalid fragments at construction time)
  • Added Behave tests (10 scenarios in unified_context_models.feature)
  • Added Robot integration tests (3 test cases in unified_context_models.robot)
  • Added ASV benchmarks for unified model construction and isinstance-check throughput
  • Updated Known Limitations table in docs/reference/acms.md

Verification

  • nox -s lint — passed
  • nox -s typecheck — 0 errors, 0 warnings (Pyright standard mode)
  • nox -s unit_tests — 266 features, 8510 scenarios, 32865 steps — all passed
  • nox -s integration_tests — 1197 tests — all passed
  • nox -s coverage_report — 97% coverage (meets threshold)

ISSUES CLOSED: #569

## Summary Core domain types (`FragmentProvenance`, `ContextFragment`, `ContextBudget`, `ContextPayload`) now extend their CRP counterparts via Pydantic v2 inheritance, ensuring `isinstance` compatibility across the model hierarchy. This eliminates the duplicate model hierarchies that existed between the CRP layer and the core domain layer. ## Changes - **CRP base types made `frozen=True`**: `FragmentProvenance`, `ContextFragment`, `ContextBudget`, `AssembledContext` — validated that no CRP consumer mutates these instances - **CRP `AssembledContext` fields**: `fragments` and `strategies_used` changed from `list` to `tuple` for frozen-model consistency - **Core types extend CRP bases**: `FragmentProvenance(CRPFragmentProvenance)`, `ContextFragment(CRPContextFragment)`, `ContextBudget(CRPContextBudget)`, `ContextPayload(CRPAssembledContext)` - **Removed duplicate `ContextFragment` dataclass** from `skeleton_compressor.py`; service now uses `core.context_fragment.ContextFragment` - **Updated `project_context.py`** to pass tuples to frozen `AssembledContext` - **Updated skeleton_compressor tests** to handle model-level validation (Pydantic now rejects invalid fragments at construction time) - **Added Behave tests** (10 scenarios in `unified_context_models.feature`) - **Added Robot integration tests** (3 test cases in `unified_context_models.robot`) - **Added ASV benchmarks** for unified model construction and isinstance-check throughput - **Updated Known Limitations table** in `docs/reference/acms.md` ## Verification - `nox -s lint` — passed - `nox -s typecheck` — 0 errors, 0 warnings (Pyright standard mode) - `nox -s unit_tests` — 266 features, 8510 scenarios, 32865 steps — all passed - `nox -s integration_tests` — 1197 tests — all passed - `nox -s coverage_report` — 97% coverage (meets threshold) ISSUES CLOSED: #569
freemo force-pushed refactor/unify-context-fragment-models from 56e8d2194f to f6045c9027 2026-03-05 16:31:26 +00:00 Compare
freemo force-pushed refactor/unify-context-fragment-models from f6045c9027 to b7771d56b0 2026-03-05 16:41:22 +00:00 Compare
freemo force-pushed refactor/unify-context-fragment-models from b7771d56b0 to 2b23f5496a 2026-03-05 16:47:57 +00:00 Compare
freemo force-pushed refactor/unify-context-fragment-models from 2b23f5496a to c6e7b56052 2026-03-05 18:40:49 +00:00 Compare
freemo force-pushed refactor/unify-context-fragment-models from c6e7b56052 to 5761902aff 2026-03-05 20:11:05 +00:00 Compare
freemo scheduled this pull request to auto merge when all checks succeed 2026-03-05 20:11:17 +00:00
freemo force-pushed refactor/unify-context-fragment-models from 5761902aff to fae438a7a7 2026-03-05 21:38:56 +00:00 Compare
freemo merged commit fae438a7a7 into master 2026-03-05 21:43:55 +00:00
freemo deleted branch refactor/unify-context-fragment-models 2026-03-05 21:43:55 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cleveragents/cleveragents-core#598