feat(trigger-service): event normalizer (TS-IMPL-010)#663
Merged
Conversation
Add `custos_trigger.normalize`, converting the two platform-internal source shapes into the canonical `NormalizedEvent` envelope. - `normalize_manual_fire(...)`: manual `:fire` body -> `manual.fire` event; inputs become `data`; deterministic `eventId` from (subscription, occurredAt, inputs) so a redelivered fire collapses in dedup. - `normalize_workflow_event(envelope, ...)`: `custos.workflow.events` envelope -> `NormalizedEvent`. `kind` is taken from an explicit taxonomy-valid envelope `kind` when present, else derived from `status` via `workflow_kind_from_status` (succeeded->completed, queued/running->started). `domain` selects `workflow.*` (default) or `run.*`. `runId` is the subject; `eventId` is derived from (runId, kind, occurredAt) — the producer's dedup triple — so Dapr at-least-once redelivery collapses in dedup. - An internal status with no canonical mapping (e.g. `paused`) surfaces as `InvalidKindError` (taxonomy error); missing required envelope fields raise `EventNormalizationError`. - `generate_event_id(*parts)`: NUL-joined UUIDv5 under a fixed namespace. Closes #640
Contributor
There was a problem hiding this comment.
Pull request overview
Implements TS-IMPL-010 for Trigger Service by introducing an event normalizer that converts manual :fire requests and internal custos.workflow.events envelopes into the canonical NormalizedEvent shape consumed by the downstream Classify → Match → Dedup → Dispatch pipeline.
Changes:
- Added
custos_trigger.normalizewith helpers for canonical kind mapping and deterministic event ID generation. - Added a comprehensive unit test suite for manual-fire and workflow-envelope normalization behavior.
- Updated the trigger-service design TODO tracker to mark TS-IMPL-010 as complete.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/services/trigger-service/src/custos_trigger/normalize.py | New normalization module for manual and internal workflow events, including kind mapping and deterministic event_id generation. |
| src/services/trigger-service/tests/test_normalize.py | New unit tests covering event ID generation, kind mapping, and normalization behavior/error cases. |
| design/components/trigger-service/todos.md | Marks TS-IMPL-010 as completed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…rnal event_id Address Copilot review on PR #663: - normalize_manual_fire now requires a non-empty subscription_id (manual fire is subscription-scoped), so the subject is unambiguous and dedup keys cannot collide across subscriptions. - normalize_workflow_event derives event_id from (runId, kind, occurredAt) only; kind already embeds the domain, so dropping the extra domain part restores the stated 'same producer dedup triple' property. - Document stepId in the workflow-event envelope wire shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements TS-IMPL-010 — Event Normalizer (#640).
Adds
custos_trigger.normalize, which converts the two platform-internalsource shapes — a manual
:fireand an internalcustos.workflow.eventslifecycle envelope — into the canonical
NormalizedEventenvelope theClassify → Match → Dedup → Dispatchpipeline expects. (Connector-sourcedevents already arrive shaped as
NormalizedEventand do not pass through here.)What's included
normalize_manual_fire(...)— manual fire body →manual.fireevent;inputsbecomedata;subscriptionIdis the subject.normalize_workflow_event(envelope, ...)—custos.workflow.eventsenvelope →
NormalizedEvent.kindis taken from an explicit, taxonomy-validenvelope
kindwhen present, otherwise derived fromstatus.runIdis thesubject;
datacarriesworkflowVersionId/runId/workspace/statusplusoptional
outputs/stepId;raw.bodyretains the full envelope for audit.workflow_kind_from_status(status, *, domain="workflow")— maps theWorkflow Service wire
statusvocabulary onto canonical taxonomy kinds(
succeeded→completed,queued/running→started);domainselectsworkflow.*(default) orrun.*.generate_event_id(*parts)— deterministic, NUL-joined UUIDv5 under afixed namespace; internal events derive their id from the producer's
(runId, kind, occurredAt)dedup triple so at-least-once redelivery collapsesin the dedup store.
Acceptance criteria
canonical kinds.
eventIdgeneration; unknown source/status raises ataxonomy error (
InvalidKindError).normalize.py100%; suite 99.85%).ruff+mypyclean.Closes #640