Prechádzať zdrojové kódy

docs: plan composed schema fallback fix

Problem: unrelated required errors inside anyOf/oneOf can trigger costly fallback for complete-invalid input, while defensive deepcopy failures can escape or be reported as definition errors.

Risk: branch classification must stay conservative without suppressing genuinely missing viable input; snapshot normalization must preserve ordinary JSON audit isolation.
zhenyu.hu 2 týždňov pred
rodič
commit
b0aaa5f8bc

+ 61 - 0
docs/plans/todo-45.5-composed-schema-and-copy-failures.md

@@ -0,0 +1,61 @@
+# Todo 45.5 Composed Schema and Copy Failures Plan
+
+**Status:** in_progress
+
+## Goal
+
+Restore the cost-sensitive fallback contract for composed schemas and ensure argument isolation cannot leak copy exceptions or misclassify input failures as plugin-definition failures.
+
+## Scope
+
+- Classify `anyOf`/`oneOf` branches so a missing field in an unrelated branch cannot make complete-invalid input eligible for fallback.
+- Preserve fallback for a viable branch that fails only because required data is missing.
+- Replace exposed/deep-copied `ValidationError` values with registry-owned immutable validation summaries needed by the kernel.
+- Normalize strict JSON snapshot failures for deterministic resolver and provider-resolved arguments in both async and sync paths.
+
+## Boundaries
+
+- Prefer a conservative fallback decision: no LLM call when branch viability is ambiguous or any candidate failure is substantive rather than missing-only.
+- Do not implement a general JSON Schema inference engine or discriminator extension.
+- Non-JSON and uncopyable values are invalid event arguments/resolution data; do not coerce them.
+- Preserve the four already verified Todo 45.4 behaviors.
+
+## Files
+
+- Modify: `src/agent_lab/application/events/kernel.py`
+- Modify: `src/agent_lab/application/events/registry.py`
+- Modify: `tests/test_event_kernel.py`
+- Modify: `tests/test_event_agent.py` only if EventAgent integration needs a regression
+
+## Requirement Execution Loop
+
+### Plan
+
+1. Add RED tests for discriminated `anyOf` and `oneOf`: target branch complete-but-wrong-type, unrelated branch missing fields, fallback count zero.
+2. Add RED tests proving a matching/viable branch with only required fields missing can still call fallback once.
+3. Add RED tests for argument objects whose `__deepcopy__` raises in resolver and provider-resolved inputs; assert no exception escapes and no `DEFINITION_ERROR` misclassification.
+4. Introduce immutable validation issue summaries and branch-aware missing-only classification.
+5. Use strict JSON snapshots at argument isolation boundaries and normalize failures consistently across sync/async execution.
+
+### Act
+
+- Cover both `anyOf` and `oneOf` with discriminator-like `const` branches.
+- Verify complete-invalid input returns `INVALID_ARGUMENTS`, `used_fallback=False`, fallback calls `0`.
+- Verify a matching branch missing only its required value invokes fallback exactly once; fully ambiguous invalid input remains no-fallback.
+- Prove validation summaries cannot mutate registry behavior and do not retain caller-owned instances or schema objects.
+- Preserve handler/result mutation isolation for ordinary nested JSON values.
+
+### Observe
+
+Confirm the LLM fallback count now reflects genuinely missing information, and malformed argument objects are contained as stable user/resolution failures rather than exceptions or definition errors.
+
+### Update
+
+- Re-run Todo 45 specification and quality reviews over the full range.
+- Mark Todos 45 through 45.5 done only after fresh verification.
+
+## Verification
+
+- `UV_CACHE_DIR=.uv-cache uv run pytest tests/test_event_kernel.py tests/test_event_agent.py -q`
+- `UV_CACHE_DIR=.uv-cache uv run pytest`
+- `git diff --check`

+ 1 - 0
docs/plans/todos.md

@@ -79,6 +79,7 @@
 | 45.2 | in_progress | `docs/plans/todo-45.2-event-fallback-semantics.md` | Restrict fallback to incomplete resolution, enforce JSON-type-sensitive raw consistency, and distinguish definition failures. | Complete-invalid arguments skip LLM; raw/parsed mismatch and broken schema references produce stable non-user-error results. |
 | 45.3 | in_progress | `docs/plans/todo-45.3-sync-resolution-completeness.md` | Make synchronous kernel execution reject explicitly incomplete deterministic resolution instead of invoking the handler. | A structured incomplete result with an optional-only schema returns `INVALID_ARGUMENTS`; the handler is not called and async behavior remains aligned. |
 | 45.4 | in_progress | `docs/plans/todo-45.4-event-kernel-quality-boundaries.md` | Close reviewed configuration, composed-schema fallback, mutation isolation, registry encapsulation, and payload-serialization gaps. | Default EventAgent config survives omitted overrides; nested required errors can fall back; handlers and callers cannot corrupt audit arguments; validators stay private; non-JSON payloads become `HANDLER_ERROR`. |
+| 45.5 | in_progress | `docs/plans/todo-45.5-composed-schema-and-copy-failures.md` | Prevent unrelated composed-schema branches from triggering fallback and normalize argument snapshot failures without exposing validator internals. | Complete-invalid discriminated unions never call fallback; missing viable branches still can; uncopyable/non-JSON resolver and provider arguments return stable results instead of raising or becoming definition errors. |
 | 46 | pending | `docs/plans/todo-46-configurable-tool-invocation-mode.md` | Add `dual_agent` and `chat_agent_tools` runtime modes on the shared event kernel. | Runtime tests prove mode-specific requests, direct execution, valid provider history, and dual-mode regression safety. |
 | 47 | pending | `docs/plans/todo-47-built-in-event-plugins.md` | Add terminate-session, device-volume, schedule, and web-search as built-in plugins on the generic event kernel. | Plugin contract tests cover valid, ambiguous, invalid, idempotent, and failure results for all four events. |
 | 48 | pending | `docs/plans/todo-48-parallel-event-batches.md` | Execute multiple flat events with bounded parallelism, failure isolation, aggregation, and a terminal barrier. | Runtime tests prove independent concurrency, stable result order, isolated failures, and termination after sibling completion or timeout. |