--- id: ACTIVITY-WP-0011 type: workplan title: "Event Payload Context Resolver" domain: custodian repo: activity-core status: finished owner: codex topic_slug: custodian created: "2026-06-18" updated: "2026-06-18" state_hub_workstream_id: "4efe4bcf-2148-4489-b57c-87f6039d4ed5" --- # ACTIVITY-WP-0011 - Event Payload Context Resolver ## Context State Hub message `d561ebd7-ba01-4dc6-8ffc-fe87d45304ee` from `kaizen-agentic` handed off an urgent blocker for LOOP-WP-0002: event-triggered definitions can receive the triggering EventEnvelope JSON, but activity-core did not bind `source.type: event-payload` into the context snapshot. The immediate customer is the disabled `coulomb-low-success-rate-review` ActivityDefinition, whose `flag-low-success-rate` rule needs to evaluate `context.metrics.summary.success_rate`. This is in activity-core scope because the repo owns ActivityDefinition context resolution and the Event Bridge workflow boundary. The remaining event type registry and live NATS smoke evidence are cross-repo/operator gates and should wait in State Hub rather than depending on local kubectl or ad hoc live cluster access from this repo. ## Implement Event Payload Resolver ```task id: ACTIVITY-WP-0011-T01 status: done priority: high state_hub_task_id: "5c87ce0b-3bd0-4a44-aae5-10d7586c939e" ``` Register resolver type `event-payload` so event-triggered definitions can bind the triggering EventEnvelope attributes into `context.*`. Done when: - `activity_core.context_resolvers` imports and registers an `event-payload` resolver. - `resolve_context` parses `event_envelope_json` once and passes the parsed envelope to registered resolvers. - `source.type: event-payload` extracts envelope `attributes`. - `bind_to: context.metrics` strips the `context.` prefix and unwraps a single-key `{"metrics": ...}` attributes payload into `snapshot["metrics"]`. - Missing or malformed envelopes fail required sources visibly and bind `{}` for optional sources. 2026-06-18: Completed in `src/activity_core/activities.py` and `src/activity_core/context_resolvers/event_payload.py`. ## Cover Binding And Rule Evaluation ```task id: ACTIVITY-WP-0011-T02 status: done priority: high state_hub_task_id: "c6f7dea6-9adc-4997-a22e-4bf2e94dc05a" ``` Add focused tests for the handoff acceptance contract. Done when: - sample `kaizen.metrics.recorded` envelope attributes resolve to: `{"metrics": {"agent": "coach", "project": "kaizen-agentic", "summary": ...}}`; - `flag-low-success-rate` evaluates `context.metrics.summary.success_rate < 0.8`; - optional missing envelopes bind `{}`; - required missing envelopes raise a visible activity failure. 2026-06-18: Completed in `tests/test_resolve_context_binding.py`. Focused tests passed: `.venv/bin/python -m pytest tests/test_resolve_context_binding.py tests/test_rule_evaluation_activity.py` reported 8 passed, and adjacent rule tests `.venv/bin/python -m pytest tests/rules/test_evaluator.py tests/rules/test_actions.py` reported 55 passed. ## Wait For Event Type Registry ```task id: ACTIVITY-WP-0011-T03 status: done priority: high state_hub_task_id: "a4f277de-eb83-41bc-860e-b26586c72495" ``` Confirm that `kaizen.metrics.recorded` is registered in the shared event type catalog through the owning State Hub / producer workflow. Done when: - State Hub or the producer-owned event catalog exposes `kaizen.metrics.recorded` with an attributes schema covering `metrics.agent`, `metrics.project`, and `metrics.summary.success_rate`; - the registry decision names the owning repo for future schema changes; - activity-core has no local-only event type drift from the producer contract. Registry ownership: the event type is producer/catalog owned. Activity-core accepted State Hub-backed registry confirmation before closing the workplan. 2026-06-18: Closed from State Hub acknowledgement `3efb56d8-c3d6-4308-82ea-76eaaa172255` from `kaizen-agentic`. The producer registered `kaizen.metrics.recorded` in `kaizen-agentic/event-types/` with status `active`, publisher `kaizen-agentic`, and schema fields `agent`, `project`, `summary.success_rate`, `summary.execution_count`, and `summary.avg_quality`. The sync command reported was `ACTIVITY_DEFINITION_DIRS=~/coulomb-loop:~/kaizen-agentic make sync-event-types`. ## Wait For Live Event Smoke ```task id: ACTIVITY-WP-0011-T04 status: done priority: high state_hub_task_id: "3b636d5e-8f93-49b4-ae53-3da4f736a4d9" ``` After T03, run the live event-triggered path without relying on local kubectl from activity-core. Done when State Hub records non-secret evidence that: - a sample `kaizen.metrics.recorded` envelope was published on the expected NATS subject; - activity-core triggered `coulomb-low-success-rate-review`; - the resolved context snapshot contained `context.metrics.summary.success_rate`; - `flag-low-success-rate` matched and produced the expected task/report output; - any disabled-definition or operator-controlled enablement state was recorded. Execution ownership: this cross-repo/live-runtime smoke was owned by the event producer, customer definition owner, and cluster/operator path. Activity-core accepted the non-secret evidence from State Hub. 2026-06-18: Closed from State Hub acknowledgement `68bfcd0d-7c47-4b42-85fc-64d63f38a909` from `kaizen-agentic`. Supplier confirms R1 acceptance criteria met and LOOP-WP-0002 closed. Evidence: NATS `activity.kaizen.metrics.recorded` triggered `coulomb-low-success-rate-review` (`da7a9af7`), run `e61554c6-1e67-5fa1-b34e-478d154a188e`, `tasks_spawned=1`, with `metrics.summary.success_rate=0.75`. ## Close Handoff ```task id: ACTIVITY-WP-0011-T05 status: done priority: medium state_hub_task_id: "5169d8c5-769f-4272-97cf-c25b31087601" ``` Close the urgent R1/live-smoke handoff once State Hub has acknowledgement that the resolver-side blocker is removed. The broader workplan remains blocked only on T03 event-type registry confirmation. Done when: - State Hub message `d561ebd7-ba01-4dc6-8ffc-fe87d45304ee` is answered or linked to this workplan; - `kaizen-agentic` / LOOP-WP-0002 can proceed without an activity-core code blocker; - this workplan has no remaining activity-core code or live-smoke blocker. 2026-06-18: Closed from State Hub acknowledgement `68bfcd0d-7c47-4b42-85fc-64d63f38a909`. The original handoff message `d561ebd7-ba01-4dc6-8ffc-fe87d45304ee` was answered, and the live smoke evidence in T04 unblocks LOOP-WP-0002. 2026-06-18: Workplan finished. T03 registry confirmation, T04 live event smoke, and T05 handoff closure are all done in State Hub.