UAT: ContextStrategy.can_handle() in acms_service.py takes dict instead of spec-required ContextRequest and BackendSet #2961

Open
opened 2026-04-05 02:57:33 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/acms-context-strategy-can-handle-signature
  • Commit Message: fix(acms): align ContextStrategy.can_handle() signature with spec
  • Milestone: v3.4.0
  • Parent Epic: #933

Background and context

The ContextStrategy protocol is defined in two places: the domain layer (src/cleveragents/domain/models/acms/strategy.py) and the service layer (src/cleveragents/application/services/acms_service.py). The domain-layer definition correctly matches the specification, but the service-layer definition has diverged. This divergence means all built-in strategies (RelevanceStrategy, RecencyStrategy, TieredStrategy) operate with incomplete information, returning hardcoded confidence values regardless of the actual request content or available backends.

Current behavior (for bugs)

The ContextStrategy.can_handle() method in src/cleveragents/application/services/acms_service.py (~line 111) has the following signature:

def can_handle(self, request: dict[str, Any]) -> float:
    """Return confidence (0.0-1.0) that this strategy can handle *request*."""

This diverges from the specification in two ways:

  1. Wrong parameter type: Takes a raw dict[str, Any] instead of a typed ContextRequest — strategies cannot access structured request fields (query, entities, uko_types, focus, breadth, depth, etc.)
  2. Missing backends parameter: The backends: BackendSet parameter is absent — strategies cannot inspect which backends are available to determine their confidence.

As a result, the built-in strategies return hardcoded confidence values:

  • RelevanceStrategy.can_handle() → always 0.8
  • RecencyStrategy.can_handle() → always 0.6
  • TieredStrategy.can_handle() → always 0.7

A RelevanceStrategy that requires a vector backend should return 0.0 when no vector backend is present, but it cannot perform this check without the BackendSet parameter.

Steps to reproduce:

  1. Read src/cleveragents/application/services/acms_service.py lines 95–125 (service-layer protocol)
  2. Compare with spec at docs/specification.md ~line 25515
  3. Compare with src/cleveragents/domain/models/acms/strategy.py lines 219–229 (domain-layer protocol — correct)
  4. Note can_handle(self, request: dict[str, Any]) vs spec's can_handle(self, request: ContextRequest, backends: BackendSet)

Expected behavior

ContextStrategy.can_handle() in acms_service.py should match the spec-required signature:

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

All built-in strategies (RelevanceStrategy, RecencyStrategy, TieredStrategy) should be updated to use this signature and implement meaningful confidence logic — e.g., returning 0.0 when a required backend type is absent from backends.

Acceptance criteria

  • ContextStrategy.can_handle() in acms_service.py accepts (self, request: ContextRequest, backends: BackendSet) -> float
  • All built-in strategies (RelevanceStrategy, RecencyStrategy, TieredStrategy) implement the updated signature
  • Built-in strategies return 0.0 when a required backend is not present in BackendSet
  • The service-layer protocol in acms_service.py is consistent with the domain-layer protocol in strategy.py
  • All callers of can_handle() are updated to pass both ContextRequest and BackendSet
  • Pyright type checking passes with no suppressions (nox -e typecheck)
  • All nox sessions pass (nox)
  • Coverage ≥ 97% (nox -e coverage_report)

Supporting information

  • Spec reference: docs/specification.md ~line 25515 — canonical ContextStrategy.can_handle() signature
  • Domain-layer (correct): src/cleveragents/domain/models/acms/strategy.py lines 219–229
  • Service-layer (incorrect): src/cleveragents/application/services/acms_service.py lines 95–125
  • Parent Epic: #933 (Epic: A2A Protocol Compliance / ACMS v1)

Subtasks

  • Update ContextStrategy protocol in acms_service.py to match spec signature: can_handle(self, request: ContextRequest, backends: BackendSet) -> float
  • Update RelevanceStrategy.can_handle() to accept ContextRequest and BackendSet; return 0.0 if required vector backend is absent
  • Update RecencyStrategy.can_handle() to accept ContextRequest and BackendSet; return 0.0 if required recency backend is absent
  • Update TieredStrategy.can_handle() to accept ContextRequest and BackendSet; return 0.0 if required backends are absent
  • Update all call sites of can_handle() in the service layer to pass both arguments
  • Tests (Behave): Add/update scenarios in features/ covering can_handle() with various BackendSet configurations (present, absent, partial)
  • Tests (Behave): Add scenario asserting 0.0 is returned when a required backend is missing
  • Verify Pyright passes with no # type: ignore suppressions (nox -e typecheck)
  • Verify coverage ≥ 97% via nox -e coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly (fix(acms): align ContextStrategy.can_handle() signature with spec), followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly (fix/acms-context-strategy-can-handle-signature).
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass.
  • Coverage ≥ 97%.

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

## Metadata - **Branch**: `fix/acms-context-strategy-can-handle-signature` - **Commit Message**: `fix(acms): align ContextStrategy.can_handle() signature with spec` - **Milestone**: v3.4.0 - **Parent Epic**: #933 ## Background and context The `ContextStrategy` protocol is defined in two places: the domain layer (`src/cleveragents/domain/models/acms/strategy.py`) and the service layer (`src/cleveragents/application/services/acms_service.py`). The domain-layer definition correctly matches the specification, but the service-layer definition has diverged. This divergence means all built-in strategies (`RelevanceStrategy`, `RecencyStrategy`, `TieredStrategy`) operate with incomplete information, returning hardcoded confidence values regardless of the actual request content or available backends. ## Current behavior (for bugs) The `ContextStrategy.can_handle()` method in `src/cleveragents/application/services/acms_service.py` (~line 111) has the following signature: ```python def can_handle(self, request: dict[str, Any]) -> float: """Return confidence (0.0-1.0) that this strategy can handle *request*.""" ``` This diverges from the specification in two ways: 1. **Wrong parameter type**: Takes a raw `dict[str, Any]` instead of a typed `ContextRequest` — strategies cannot access structured request fields (`query`, `entities`, `uko_types`, `focus`, `breadth`, `depth`, etc.) 2. **Missing `backends` parameter**: The `backends: BackendSet` parameter is absent — strategies cannot inspect which backends are available to determine their confidence. As a result, the built-in strategies return hardcoded confidence values: - `RelevanceStrategy.can_handle()` → always `0.8` - `RecencyStrategy.can_handle()` → always `0.6` - `TieredStrategy.can_handle()` → always `0.7` A `RelevanceStrategy` that requires a vector backend should return `0.0` when no vector backend is present, but it cannot perform this check without the `BackendSet` parameter. **Steps to reproduce:** 1. Read `src/cleveragents/application/services/acms_service.py` lines 95–125 (service-layer protocol) 2. Compare with spec at `docs/specification.md` ~line 25515 3. Compare with `src/cleveragents/domain/models/acms/strategy.py` lines 219–229 (domain-layer protocol — correct) 4. Note `can_handle(self, request: dict[str, Any])` vs spec's `can_handle(self, request: ContextRequest, backends: BackendSet)` ## Expected behavior `ContextStrategy.can_handle()` in `acms_service.py` should match the spec-required signature: ```python def can_handle(self, request: ContextRequest, backends: BackendSet) -> float: """Returns 0.0-1.0 confidence that this strategy can usefully contribute to this request.""" ``` All built-in strategies (`RelevanceStrategy`, `RecencyStrategy`, `TieredStrategy`) should be updated to use this signature and implement meaningful confidence logic — e.g., returning `0.0` when a required backend type is absent from `backends`. ## Acceptance criteria - [ ] `ContextStrategy.can_handle()` in `acms_service.py` accepts `(self, request: ContextRequest, backends: BackendSet) -> float` - [ ] All built-in strategies (`RelevanceStrategy`, `RecencyStrategy`, `TieredStrategy`) implement the updated signature - [ ] Built-in strategies return `0.0` when a required backend is not present in `BackendSet` - [ ] The service-layer protocol in `acms_service.py` is consistent with the domain-layer protocol in `strategy.py` - [ ] All callers of `can_handle()` are updated to pass both `ContextRequest` and `BackendSet` - [ ] Pyright type checking passes with no suppressions (`nox -e typecheck`) - [ ] All nox sessions pass (`nox`) - [ ] Coverage ≥ 97% (`nox -e coverage_report`) ## Supporting information - **Spec reference**: `docs/specification.md` ~line 25515 — canonical `ContextStrategy.can_handle()` signature - **Domain-layer (correct)**: `src/cleveragents/domain/models/acms/strategy.py` lines 219–229 - **Service-layer (incorrect)**: `src/cleveragents/application/services/acms_service.py` lines 95–125 - **Parent Epic**: #933 (Epic: A2A Protocol Compliance / ACMS v1) ## Subtasks - [ ] Update `ContextStrategy` protocol in `acms_service.py` to match spec signature: `can_handle(self, request: ContextRequest, backends: BackendSet) -> float` - [ ] Update `RelevanceStrategy.can_handle()` to accept `ContextRequest` and `BackendSet`; return `0.0` if required vector backend is absent - [ ] Update `RecencyStrategy.can_handle()` to accept `ContextRequest` and `BackendSet`; return `0.0` if required recency backend is absent - [ ] Update `TieredStrategy.can_handle()` to accept `ContextRequest` and `BackendSet`; return `0.0` if required backends are absent - [ ] Update all call sites of `can_handle()` in the service layer to pass both arguments - [ ] Tests (Behave): Add/update scenarios in `features/` covering `can_handle()` with various `BackendSet` configurations (present, absent, partial) - [ ] Tests (Behave): Add scenario asserting `0.0` is returned when a required backend is missing - [ ] Verify Pyright passes with no `# type: ignore` suppressions (`nox -e typecheck`) - [ ] Verify coverage ≥ 97% via `nox -e coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly (`fix(acms): align ContextStrategy.can_handle() signature with spec`), followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly (`fix/acms-context-strategy-can-handle-signature`). - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass. - Coverage ≥ 97%. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
freemo added this to the v3.4.0 milestone 2026-04-05 02:57:38 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Confirmed
  • MoSCoW: Should Have

Valid finding verified during batch triage.


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

Issue triaged by project owner: - **State**: Verified - **Priority**: Confirmed - **MoSCoW**: Should Have Valid finding verified during batch triage. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
freemo removed this from the v3.4.0 milestone 2026-04-06 21:01:56 +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.

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