UAT: ProvenancePreambleGenerator crashes with AttributeError when passed CRP ContextFragment instances #2086

Open
opened 2026-04-03 03:56:30 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/acms-preamble-generator-crp-fragment-compat
  • Commit Message: fix(acms): make ProvenancePreambleGenerator compatible with CRP ContextFragment
  • Milestone: v3.7.0
  • Parent Epic: #396

Summary

ProvenancePreambleGenerator.generate() in acms_phase3.py accesses frag.strategy_source and frag.provenance.resource_type on line 215, but these attributes only exist on the core ContextFragment and FragmentProvenance (from domain/models/core/context_fragment.py), NOT on the CRP ContextFragment and FragmentProvenance (from domain/models/acms/crp.py).

The PreambleGenerator Protocol in acms_service.py accepts Sequence[ContextFragment] where ContextFragment is the core type. However, since the core type inherits from the CRP type, any code that passes CRP fragments directly (without the extended fields) would cause an AttributeError.

Expected Behavior

ProvenancePreambleGenerator.generate() should work correctly with any ContextFragment that satisfies the PreambleGenerator protocol, using safe attribute access with fallbacks for optional fields.

Actual Behavior

If frag.strategy_source is accessed on a CRP ContextFragment instance (which lacks this attribute), an AttributeError is raised:

AttributeError: 'ContextFragment' object has no attribute 'strategy_source'

Similarly, frag.provenance.resource_type would fail on CRP FragmentProvenance instances.

Code Location

File: src/cleveragents/application/services/acms_phase3.py, line 215:

source = frag.strategy_source or frag.provenance.resource_type or "unknown"

strategy_source is defined in src/cleveragents/domain/models/core/context_fragment.py (line 107) but NOT in src/cleveragents/domain/models/acms/crp.py.

resource_type is defined in src/cleveragents/domain/models/core/context_fragment.py FragmentProvenance (line 57) but NOT in src/cleveragents/domain/models/acms/crp.py FragmentProvenance.

Steps to Reproduce

from cleveragents.domain.models.acms.crp import ContextFragment, FragmentProvenance
from cleveragents.application.services.acms_phase3 import ProvenancePreambleGenerator

frag = ContextFragment(
    uko_node="project://app/main.py",
    content="hello",
    detail_depth=0,
    token_count=10,
    relevance_score=0.5,
    provenance=FragmentProvenance(resource_uri="project://app/main.py"),
)

gen = ProvenancePreambleGenerator()
# This will raise AttributeError: 'ContextFragment' object has no attribute 'strategy_source'
gen.generate([frag])

Impact

  • Medium severity: The ProvenancePreambleGenerator is a production Phase 3 component. If any caller passes CRP-typed fragments (e.g., from _simulate_context_assembly in project_context.py), the pipeline will crash.
  • The _simulate_context_assembly function in project_context.py creates crp.ContextFragment instances and could trigger this if wired to use ProvenancePreambleGenerator.

Fix

Use getattr with fallbacks:

source = (
    getattr(frag, "strategy_source", None)
    or getattr(frag.provenance, "resource_type", None)
    or "unknown"
)

Subtasks

  • Fix ProvenancePreambleGenerator.generate() to use safe attribute access
  • Add a BDD scenario testing ProvenancePreambleGenerator with CRP ContextFragment instances
  • Verify no other Phase 2/3 components have similar issues

Definition of Done

  • ProvenancePreambleGenerator.generate() works with both CRP and core ContextFragment instances
  • BDD test added and passing
  • No regressions
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/acms-preamble-generator-crp-fragment-compat` - **Commit Message**: `fix(acms): make ProvenancePreambleGenerator compatible with CRP ContextFragment` - **Milestone**: v3.7.0 - **Parent Epic**: #396 ## Summary `ProvenancePreambleGenerator.generate()` in `acms_phase3.py` accesses `frag.strategy_source` and `frag.provenance.resource_type` on line 215, but these attributes only exist on the **core** `ContextFragment` and `FragmentProvenance` (from `domain/models/core/context_fragment.py`), NOT on the **CRP** `ContextFragment` and `FragmentProvenance` (from `domain/models/acms/crp.py`). The `PreambleGenerator` Protocol in `acms_service.py` accepts `Sequence[ContextFragment]` where `ContextFragment` is the core type. However, since the core type inherits from the CRP type, any code that passes CRP fragments directly (without the extended fields) would cause an `AttributeError`. ## Expected Behavior `ProvenancePreambleGenerator.generate()` should work correctly with any `ContextFragment` that satisfies the `PreambleGenerator` protocol, using safe attribute access with fallbacks for optional fields. ## Actual Behavior If `frag.strategy_source` is accessed on a CRP `ContextFragment` instance (which lacks this attribute), an `AttributeError` is raised: ``` AttributeError: 'ContextFragment' object has no attribute 'strategy_source' ``` Similarly, `frag.provenance.resource_type` would fail on CRP `FragmentProvenance` instances. ## Code Location **File**: `src/cleveragents/application/services/acms_phase3.py`, line 215: ```python source = frag.strategy_source or frag.provenance.resource_type or "unknown" ``` `strategy_source` is defined in `src/cleveragents/domain/models/core/context_fragment.py` (line 107) but NOT in `src/cleveragents/domain/models/acms/crp.py`. `resource_type` is defined in `src/cleveragents/domain/models/core/context_fragment.py` `FragmentProvenance` (line 57) but NOT in `src/cleveragents/domain/models/acms/crp.py` `FragmentProvenance`. ## Steps to Reproduce ```python from cleveragents.domain.models.acms.crp import ContextFragment, FragmentProvenance from cleveragents.application.services.acms_phase3 import ProvenancePreambleGenerator frag = ContextFragment( uko_node="project://app/main.py", content="hello", detail_depth=0, token_count=10, relevance_score=0.5, provenance=FragmentProvenance(resource_uri="project://app/main.py"), ) gen = ProvenancePreambleGenerator() # This will raise AttributeError: 'ContextFragment' object has no attribute 'strategy_source' gen.generate([frag]) ``` ## Impact - Medium severity: The `ProvenancePreambleGenerator` is a production Phase 3 component. If any caller passes CRP-typed fragments (e.g., from `_simulate_context_assembly` in `project_context.py`), the pipeline will crash. - The `_simulate_context_assembly` function in `project_context.py` creates `crp.ContextFragment` instances and could trigger this if wired to use `ProvenancePreambleGenerator`. ## Fix Use `getattr` with fallbacks: ```python source = ( getattr(frag, "strategy_source", None) or getattr(frag.provenance, "resource_type", None) or "unknown" ) ``` ## Subtasks - [ ] Fix `ProvenancePreambleGenerator.generate()` to use safe attribute access - [ ] Add a BDD scenario testing `ProvenancePreambleGenerator` with CRP `ContextFragment` instances - [ ] Verify no other Phase 2/3 components have similar issues ## Definition of Done - [ ] `ProvenancePreambleGenerator.generate()` works with both CRP and core `ContextFragment` instances - [ ] BDD test added and passing - [ ] No regressions - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.7.0 milestone 2026-04-03 03:56:34 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium — Consider elevating to High. This is a runtime crash (AttributeError) in a production Phase 3 ACMS component. If any caller passes CRP-typed fragments, the pipeline crashes. The fix is simple (use getattr with fallbacks) but the impact is a hard crash in the context assembly pipeline.
  • Milestone: v3.7.0 (confirmed — part of the ACMS/Context Epic #396)
  • MoSCoW: Should Have — A crash in the context assembly pipeline is a significant issue. While the specific code path may not be commonly triggered today, it represents a type-safety gap that could surface during hierarchical plan execution with ACMS context.
  • Parent Epic: #396 (confirmed correct)

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium — **Consider elevating to High.** This is a runtime crash (AttributeError) in a production Phase 3 ACMS component. If any caller passes CRP-typed fragments, the pipeline crashes. The fix is simple (use `getattr` with fallbacks) but the impact is a hard crash in the context assembly pipeline. - **Milestone**: v3.7.0 (confirmed — part of the ACMS/Context Epic #396) - **MoSCoW**: Should Have — A crash in the context assembly pipeline is a significant issue. While the specific code path may not be commonly triggered today, it represents a type-safety gap that could surface during hierarchical plan execution with ACMS context. - **Parent Epic**: #396 (confirmed correct) --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
freemo self-assigned this 2026-04-03 16:58:09 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#396 Epic: ACMS Context Pipeline
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#2086
No description provided.