todo-47.1-plugin-normalization-and-validation.md 3.2 KB

Todo 47.1 Plugin Normalization and Validation Plan

Status: done

Result

Added generic deterministic normalizers shared by text and provider sources, standard/custom format checking, strict blank/invalid input rejection, safe volume parsing, and canonical adapter cache keys while preserving provider raw arguments and no-fallback behavior.

Goal

Close review-confirmed plugin safety gaps while preserving the generic kernel and identical built-in behavior across dual_agent and chat_agent_tools.

Scope

  • Add an optional generic event argument normalizer that runs after text-event resolution and on provider-resolved arguments, before validation and execution.
  • Keep provider-resolved arguments ineligible for EventAgent LLM fallback; normalization is deterministic only.
  • Move canonical volume/search structured normalization into this shared hook.
  • Treat negated volume commands as incomplete/invalid and capture full numeric tokens so values such as 1000 are rejected rather than truncated to 100.
  • Enforce real RFC3339 date-time validity and real IANA timezone validity through generic JSON Schema format checking.
  • Reject blank/whitespace-only search queries and blank schedule titles.
  • Prevent in-memory adapters from returning stale results when short parser event IDs collide with different normalized arguments.

Idempotency Decision

The lab adapters will cache by event ID plus canonical normalized arguments, not event ID alone. This preserves same-call replay behavior while preventing event_1 with a different operation from returning an earlier result. Runtime-scoped deduplication and production session/turn idempotency remain Todo 48/service integration responsibilities.

Files

  • Modify: src/agent_lab/application/events/models.py
  • Modify: src/agent_lab/application/events/kernel.py
  • Modify: src/agent_lab/application/events/registry.py
  • Modify: src/agent_lab/application/events/__init__.py
  • Modify: src/agent_lab/application/events/builtin_plugins.py
  • Modify: src/agent_lab/application/tools.py only to preserve ToolDefinition compatibility with the new optional normalizer
  • Modify: tests/test_event_kernel.py
  • Modify: tests/test_builtin_event_plugins.py

Requirement Execution Loop

Plan

  1. Add RED generic-kernel tests proving normalizers run for both sources, preserve provider raw arguments, and never enable provider LLM fallback.
  2. Add RED plugin parity tests for canonicalization through text and provider sources.
  3. Add RED safety tests for English/Chinese negation, 1000, invalid dates, invalid IANA zones, blank query/title, and no port calls.
  4. Add RED adapter tests for same short ID with different arguments and replay with identical arguments.
  5. Implement generic format checking and the smallest plugin normalizers/validators.
  6. Run focused/full verification and renewed reviews.

Observe / Update

Close Todo 47 only when all four plugins reject unsafe inputs before ports, both invocation modes share deterministic normalization, and no event-name logic enters generic orchestration.

Verification

  • UV_CACHE_DIR=.uv-cache uv run pytest tests/test_event_kernel.py tests/test_builtin_event_plugins.py -q
  • UV_CACHE_DIR=.uv-cache uv run pytest
  • git diff --check