UAT: ACMSPipeline ContextStrategy protocol uses dict[str, Any] instead of spec-required ContextRequest + BackendSet #4774

Open
opened 2026-04-08 18:55:59 +00:00 by HAL9000 · 1 comment
Owner

Bug Report

Feature Area: ACMS — Context Assembly Pipeline, ContextStrategy Protocol

Severity: High — the pipeline's internal ContextStrategy protocol is incompatible with the spec-defined protocol, preventing real strategy implementations from being used directly in the pipeline

What Was Tested

Code-level analysis comparing the ContextStrategy protocol in src/cleveragents/application/services/acms_service.py against the spec definition at docs/specification.md §25634-25658 and the domain model in src/cleveragents/domain/models/acms/strategy.py.

Expected Behavior (from spec)

The spec defines the ContextStrategy protocol at docs/specification.md lines 25634-25658:

@runtime_checkable
class ContextStrategy(Protocol):
    @property
    def name(self) -> str: ...

    @property
    def capabilities(self) -> StrategyCapabilities: ...

    def can_handle(self, request: ContextRequest, backends: BackendSet) -> float:
        """Returns 0.0-1.0 confidence that this strategy can usefully
        contribute to this request."""
        ...

    def assemble(self, request: ContextRequest, backends: BackendSet,
                 budget: int, plan_context: PlanContext) -> list[ContextFragment]:
        """Execute the strategy. Must respect the budget."""
        ...

    def explain(self) -> str: ...

The domain model in src/cleveragents/domain/models/acms/strategy.py correctly implements this protocol.

Actual Behavior

The ACMSPipeline in src/cleveragents/application/services/acms_service.py defines a different ContextStrategy protocol (lines 118-148):

class ContextStrategy(Protocol):
    @property
    def name(self) -> str: ...

    @property
    def capabilities(self) -> StrategyCapabilities: ...

    def can_handle(self, request: dict[str, Any]) -> float:
        # ❌ WRONG: takes dict instead of ContextRequest + BackendSet
        ...

    def assemble(
        self,
        fragments: Sequence[ContextFragment],
        budget: ContextBudget,
    ) -> Sequence[ContextFragment]:
        # ❌ WRONG: takes pre-fetched fragments instead of ContextRequest + BackendSet + budget + plan_context
        ...

This means:

  1. The pipeline's ContextStrategy protocol is incompatible with the spec-defined protocol
  2. The 6 built-in strategies in strategy_stubs.py (which implement the correct spec protocol) cannot be used directly in the pipeline — they must be wrapped in SpecStrategyAdapter (lines 286-353)
  3. The SpecStrategyAdapter falls back to relevance-based ranking of pre-fetched fragments, bypassing the actual strategy logic (text search, vector search, graph traversal)
  4. The ConfidenceWeightedSelector calls strategy.can_handle(request) with a dict (line 170), not a ContextRequest + BackendSet as the spec requires

Impact

  • The 6 spec-required built-in strategies (simple-keyword, semantic-embedding, breadth-depth-navigator, arce, temporal-archaeology, plan-decision-context) are not actually executed when the pipeline runs — they are wrapped in adapters that ignore their actual logic
  • The pipeline cannot leverage text backends, vector backends, or graph backends through the strategy protocol
  • Custom strategies implementing the spec protocol cannot be registered directly in the pipeline
  • The SpecStrategyAdapter.assemble() always falls back to relevance-based ranking regardless of which strategy is "selected"

Code Locations

  • src/cleveragents/application/services/acms_service.py lines 118-148 (wrong protocol)
  • src/cleveragents/application/services/acms_service.py lines 286-353 (SpecStrategyAdapter workaround)
  • src/cleveragents/domain/models/acms/strategy.py lines 194-243 (correct spec protocol)
  • src/cleveragents/domain/models/acms/strategy_stubs.py (correct implementations)
  • Issue #3491 is referenced in the code as the tracking issue for this protocol consolidation

Fix Required

The pipeline needs to be refactored to use the spec-defined ContextStrategy protocol:

  1. The ACMSPipeline.assemble() method should pass ContextRequest and BackendSet to strategies
  2. The StrategySelector, BudgetAllocator, and StrategyExecutor should work with the spec protocol
  3. The SpecStrategyAdapter workaround should be removed
  4. The ConfidenceWeightedSelector.select() should pass ContextRequest + BackendSet to can_handle()

This is tracked as issue #3491 in the codebase but needs to be prioritized as it prevents the ACMS from functioning as specified.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Bug Report **Feature Area:** ACMS — Context Assembly Pipeline, ContextStrategy Protocol **Severity:** High — the pipeline's internal `ContextStrategy` protocol is incompatible with the spec-defined protocol, preventing real strategy implementations from being used directly in the pipeline ### What Was Tested Code-level analysis comparing the `ContextStrategy` protocol in `src/cleveragents/application/services/acms_service.py` against the spec definition at `docs/specification.md` §25634-25658 and the domain model in `src/cleveragents/domain/models/acms/strategy.py`. ### Expected Behavior (from spec) The spec defines the `ContextStrategy` protocol at `docs/specification.md` lines 25634-25658: ```python @runtime_checkable class ContextStrategy(Protocol): @property def name(self) -> str: ... @property def capabilities(self) -> StrategyCapabilities: ... def can_handle(self, request: ContextRequest, backends: BackendSet) -> float: """Returns 0.0-1.0 confidence that this strategy can usefully contribute to this request.""" ... def assemble(self, request: ContextRequest, backends: BackendSet, budget: int, plan_context: PlanContext) -> list[ContextFragment]: """Execute the strategy. Must respect the budget.""" ... def explain(self) -> str: ... ``` The domain model in `src/cleveragents/domain/models/acms/strategy.py` correctly implements this protocol. ### Actual Behavior The `ACMSPipeline` in `src/cleveragents/application/services/acms_service.py` defines a **different** `ContextStrategy` protocol (lines 118-148): ```python class ContextStrategy(Protocol): @property def name(self) -> str: ... @property def capabilities(self) -> StrategyCapabilities: ... def can_handle(self, request: dict[str, Any]) -> float: # ❌ WRONG: takes dict instead of ContextRequest + BackendSet ... def assemble( self, fragments: Sequence[ContextFragment], budget: ContextBudget, ) -> Sequence[ContextFragment]: # ❌ WRONG: takes pre-fetched fragments instead of ContextRequest + BackendSet + budget + plan_context ... ``` This means: 1. The pipeline's `ContextStrategy` protocol is **incompatible** with the spec-defined protocol 2. The 6 built-in strategies in `strategy_stubs.py` (which implement the correct spec protocol) **cannot be used directly** in the pipeline — they must be wrapped in `SpecStrategyAdapter` (lines 286-353) 3. The `SpecStrategyAdapter` falls back to relevance-based ranking of pre-fetched fragments, bypassing the actual strategy logic (text search, vector search, graph traversal) 4. The `ConfidenceWeightedSelector` calls `strategy.can_handle(request)` with a `dict` (line 170), not a `ContextRequest + BackendSet` as the spec requires ### Impact - The 6 spec-required built-in strategies (`simple-keyword`, `semantic-embedding`, `breadth-depth-navigator`, `arce`, `temporal-archaeology`, `plan-decision-context`) are **not actually executed** when the pipeline runs — they are wrapped in adapters that ignore their actual logic - The pipeline cannot leverage text backends, vector backends, or graph backends through the strategy protocol - Custom strategies implementing the spec protocol cannot be registered directly in the pipeline - The `SpecStrategyAdapter.assemble()` always falls back to relevance-based ranking regardless of which strategy is "selected" ### Code Locations - `src/cleveragents/application/services/acms_service.py` lines 118-148 (wrong protocol) - `src/cleveragents/application/services/acms_service.py` lines 286-353 (`SpecStrategyAdapter` workaround) - `src/cleveragents/domain/models/acms/strategy.py` lines 194-243 (correct spec protocol) - `src/cleveragents/domain/models/acms/strategy_stubs.py` (correct implementations) - Issue #3491 is referenced in the code as the tracking issue for this protocol consolidation ### Fix Required The pipeline needs to be refactored to use the spec-defined `ContextStrategy` protocol: 1. The `ACMSPipeline.assemble()` method should pass `ContextRequest` and `BackendSet` to strategies 2. The `StrategySelector`, `BudgetAllocator`, and `StrategyExecutor` should work with the spec protocol 3. The `SpecStrategyAdapter` workaround should be removed 4. The `ConfidenceWeightedSelector.select()` should pass `ContextRequest + BackendSet` to `can_handle()` This is tracked as issue #3491 in the codebase but needs to be prioritized as it prevents the ACMS from functioning as specified. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium — spec compliance bug identified by UAT testing
  • Story Points: 3 (M) — targeted fix to align implementation with spec
  • MoSCoW: Must Have — spec compliance is required for correct system behavior

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

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium — spec compliance bug identified by UAT testing - **Story Points**: 3 (M) — targeted fix to align implementation with spec - **MoSCoW**: Must Have — spec compliance is required for correct system behavior --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
HAL9000 added this to the v3.5.0 milestone 2026-04-09 03:04:23 +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.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#4774
No description provided.