a2a: Use of Any and # type: ignore for services in A2aLocalFacade #9075

Open
opened 2026-04-14 07:08:52 +00:00 by HAL9000 · 2 comments
Owner

Metadata

  • Commit Message: fix(a2a): replace dict[str, Any] with TypedDict and remove type: ignore in A2aLocalFacade
  • Branch: fix/a2a-facade-typed-services-dict

Background and Context

The A2aLocalFacade in src/cleveragents/a2a/facade.py uses dict[str, Any] to store its service dependencies and # type: ignore comments in every service accessor property. This directly violates the project's type safety rules, which explicitly state:

No Suppression: When a static type checker is in use, never disable it via configuration files and never use inline comments or annotations to suppress individual type checking errors (e.g., no type: ignore, noinspection, @SuppressWarnings, or equivalent directives).

Code Evidence:

# Constructor — untyped services dict
def __init__(self, services: dict[str, Any] | None = None) -> None:
    self._services: dict[str, Any] = dict(services) if services else {}
    self._handler_map: dict[str, Any] | None = None

# Service accessors — all use # type: ignore
@property
def _session_service(self) -> SessionService | None:
    return self._services.get("session_service")  # type: ignore[return-value]

@property
def _plan_lifecycle_service(self) -> PlanLifecycleService | None:
    svc: object | None = self._services.get("plan_lifecycle_service")
    return svc  # type: ignore[return-value]

@property
def _tool_registry(self) -> ToolRegistry | None:
    return self._services.get("tool_registry")  # type: ignore[return-value]

@property
def _resource_registry_service(self) -> ResourceRegistryService | None:
    svc: object | None = self._services.get("resource_registry_service")
    return svc  # type: ignore[return-value]

@property
def _event_queue(self) -> A2aEventQueue | None:
    return self._services.get("event_queue")  # type: ignore[return-value]

The # type: ignore comments are present because dict[str, Any].get() returns Any, which cannot be narrowed to the specific service type without a cast or a typed container. The root cause is the use of dict[str, Any] rather than a properly typed structure.

Code Reference: cleveragents.a2a.facade.A2aLocalFacade.__init__ and all five service accessor properties.

Expected Behavior

The _services container is typed using a TypedDict (e.g., _A2aServices) that maps each known service key to its precise optional type. The service accessor properties return the correct type directly from the typed dict without requiring any # type: ignore suppression. Pyright strict mode passes with no errors or suppressions in facade.py.

Acceptance Criteria

  • A TypedDict (e.g., _A2aServices) is defined with all five service keys (session_service, plan_lifecycle_service, tool_registry, resource_registry_service, event_queue) mapped to their correct optional types.
  • A2aLocalFacade.__init__ accepts _A2aServices | None (or a compatible typed mapping) instead of dict[str, Any] | None.
  • self._services is typed as _A2aServices, not dict[str, Any].
  • All five service accessor properties (_session_service, _plan_lifecycle_service, _tool_registry, _resource_registry_service, _event_queue) return the correct type without any # type: ignore comment.
  • self._handler_map is typed as dict[str, Callable[[dict[str, Any]], dict[str, Any]]] | None (or equivalent) instead of dict[str, Any] | None.
  • register_service is updated to accept only valid service keys (or remains flexible with appropriate typing that does not require # type: ignore).
  • nox -s typecheck passes with no errors or suppressions in facade.py.
  • All existing BDD scenarios for A2aLocalFacade continue to pass.
  • Test coverage remains ≥ 97%.
  • nox (all default sessions) passes with no errors.

Subtasks

  • Define _A2aServices as a TypedDict in src/cleveragents/a2a/facade.py (or a dedicated _types.py module in the same package) with all five service keys typed as their correct optional service types.
  • Update A2aLocalFacade.__init__ to accept _A2aServices | None and store self._services as _A2aServices.
  • Update self._handler_map type annotation to use a precise callable type instead of dict[str, Any].
  • Remove all five # type: ignore comments from the service accessor properties.
  • Update register_service signature/implementation to remain compatible with the new typed dict (e.g., use Literal key type or a typed overload).
  • Tests (Behave): Add/update BDD scenarios to verify that passing a correctly typed services dict works and that passing an incorrectly typed value raises TypeError.
  • Verify nox -s typecheck passes with zero suppressions in facade.py.
  • Verify coverage ≥ 97% via nox -s 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.
  • src/cleveragents/a2a/facade.py contains no # type: ignore comments and no dict[str, Any] usage for the services container or handler map.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly (fix(a2a): replace dict[str, Any] with TypedDict and remove type: ignore in A2aLocalFacade), 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/a2a-facade-typed-services-dict).
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All CI checks pass (tests, linting, type checking, security, coverage ≥ 97%).

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `fix(a2a): replace dict[str, Any] with TypedDict and remove type: ignore in A2aLocalFacade` - **Branch**: `fix/a2a-facade-typed-services-dict` ## Background and Context The `A2aLocalFacade` in `src/cleveragents/a2a/facade.py` uses `dict[str, Any]` to store its service dependencies and `# type: ignore` comments in every service accessor property. This directly violates the project's type safety rules, which explicitly state: > **No Suppression:** When a static type checker is in use, never disable it via configuration files and never use inline comments or annotations to suppress individual type checking errors (e.g., no `type: ignore`, `noinspection`, `@SuppressWarnings`, or equivalent directives). **Code Evidence:** ```python # Constructor — untyped services dict def __init__(self, services: dict[str, Any] | None = None) -> None: self._services: dict[str, Any] = dict(services) if services else {} self._handler_map: dict[str, Any] | None = None # Service accessors — all use # type: ignore @property def _session_service(self) -> SessionService | None: return self._services.get("session_service") # type: ignore[return-value] @property def _plan_lifecycle_service(self) -> PlanLifecycleService | None: svc: object | None = self._services.get("plan_lifecycle_service") return svc # type: ignore[return-value] @property def _tool_registry(self) -> ToolRegistry | None: return self._services.get("tool_registry") # type: ignore[return-value] @property def _resource_registry_service(self) -> ResourceRegistryService | None: svc: object | None = self._services.get("resource_registry_service") return svc # type: ignore[return-value] @property def _event_queue(self) -> A2aEventQueue | None: return self._services.get("event_queue") # type: ignore[return-value] ``` The `# type: ignore` comments are present because `dict[str, Any].get()` returns `Any`, which cannot be narrowed to the specific service type without a cast or a typed container. The root cause is the use of `dict[str, Any]` rather than a properly typed structure. **Code Reference:** `cleveragents.a2a.facade.A2aLocalFacade.__init__` and all five service accessor properties. ## Expected Behavior The `_services` container is typed using a `TypedDict` (e.g., `_A2aServices`) that maps each known service key to its precise optional type. The service accessor properties return the correct type directly from the typed dict without requiring any `# type: ignore` suppression. Pyright strict mode passes with no errors or suppressions in `facade.py`. ## Acceptance Criteria - [ ] A `TypedDict` (e.g., `_A2aServices`) is defined with all five service keys (`session_service`, `plan_lifecycle_service`, `tool_registry`, `resource_registry_service`, `event_queue`) mapped to their correct optional types. - [ ] `A2aLocalFacade.__init__` accepts `_A2aServices | None` (or a compatible typed mapping) instead of `dict[str, Any] | None`. - [ ] `self._services` is typed as `_A2aServices`, not `dict[str, Any]`. - [ ] All five service accessor properties (`_session_service`, `_plan_lifecycle_service`, `_tool_registry`, `_resource_registry_service`, `_event_queue`) return the correct type without any `# type: ignore` comment. - [ ] `self._handler_map` is typed as `dict[str, Callable[[dict[str, Any]], dict[str, Any]]] | None` (or equivalent) instead of `dict[str, Any] | None`. - [ ] `register_service` is updated to accept only valid service keys (or remains flexible with appropriate typing that does not require `# type: ignore`). - [ ] `nox -s typecheck` passes with no errors or suppressions in `facade.py`. - [ ] All existing BDD scenarios for `A2aLocalFacade` continue to pass. - [ ] Test coverage remains ≥ 97%. - [ ] `nox` (all default sessions) passes with no errors. ## Subtasks - [ ] Define `_A2aServices` as a `TypedDict` in `src/cleveragents/a2a/facade.py` (or a dedicated `_types.py` module in the same package) with all five service keys typed as their correct optional service types. - [ ] Update `A2aLocalFacade.__init__` to accept `_A2aServices | None` and store `self._services` as `_A2aServices`. - [ ] Update `self._handler_map` type annotation to use a precise callable type instead of `dict[str, Any]`. - [ ] Remove all five `# type: ignore` comments from the service accessor properties. - [ ] Update `register_service` signature/implementation to remain compatible with the new typed dict (e.g., use `Literal` key type or a typed overload). - [ ] Tests (Behave): Add/update BDD scenarios to verify that passing a correctly typed services dict works and that passing an incorrectly typed value raises `TypeError`. - [ ] Verify `nox -s typecheck` passes with zero suppressions in `facade.py`. - [ ] Verify coverage ≥ 97% via `nox -s 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. - `src/cleveragents/a2a/facade.py` contains no `# type: ignore` comments and no `dict[str, Any]` usage for the services container or handler map. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly (`fix(a2a): replace dict[str, Any] with TypedDict and remove type: ignore in A2aLocalFacade`), 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/a2a-facade-typed-services-dict`). - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All CI checks pass (tests, linting, type checking, security, coverage ≥ 97%). --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.5.0 milestone 2026-04-14 07:37:27 +00:00
Author
Owner

🔍 Triage Decision — [AUTO-OWNR-2]

Status: VERIFIED

MoSCoW: Should have
Priority: Medium
Milestone: v3.5.0

Reasoning: Use of Any types and # type: ignore comments in A2aLocalFacade violates the project's strict typing requirements from CONTRIBUTING.md. Should be fixed to maintain type safety across the codebase.


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

## 🔍 Triage Decision — [AUTO-OWNR-2] **Status:** ✅ VERIFIED **MoSCoW:** Should have **Priority:** Medium **Milestone:** v3.5.0 **Reasoning:** Use of `Any` types and `# type: ignore` comments in `A2aLocalFacade` violates the project's strict typing requirements from CONTRIBUTING.md. Should be fixed to maintain type safety across the codebase. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Triage: Verified [AUTO-OWNR-1]

Valid bug: A2aLocalFacade uses Any types and # type: ignore comments for services, violating the project's type safety requirements (CONTRIBUTING.md prohibits # type: ignore).

Assigning to v3.5.0 (Autonomy Hardening) as A2A facade is a core M6 component. Priority Medium — type safety violation.

MoSCoW: Should Have — type safety compliance is required by CONTRIBUTING.md.


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

✅ **Triage: Verified** [AUTO-OWNR-1] Valid bug: `A2aLocalFacade` uses `Any` types and `# type: ignore` comments for services, violating the project's type safety requirements (CONTRIBUTING.md prohibits `# type: ignore`). Assigning to **v3.5.0** (Autonomy Hardening) as A2A facade is a core M6 component. Priority **Medium** — type safety violation. MoSCoW: **Should Have** — type safety compliance is required by CONTRIBUTING.md. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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#9075
No description provided.