Skip to content

Improve CloudEvent defaults for emitted events (#1554)#1568

Closed
anuragpaul602-netizen wants to merge 1 commit into
open-workflow-specification:mainfrom
anuragpaul602-netizen:cloudevent-emit-defaults-1554
Closed

Improve CloudEvent defaults for emitted events (#1554)#1568
anuragpaul602-netizen wants to merge 1 commit into
open-workflow-specification:mainfrom
anuragpaul602-netizen:cloudevent-emit-defaults-1554

Conversation

@anuragpaul602-netizen

Copy link
Copy Markdown

What & why

Fixes #1554.

Emitted CloudEvents (emit.event.with) were under-specified relative to the spec, which requires id, source, and type:

Field Before After
id auto UUID — good unchanged
type throws if missing — correct unchanged
source falls back to reference-impl — no traceability derived from workflow identity / configurable
time omitted entirely defaults to OffsetDateTime.now()

How

  • source — when an emit declares no source, derive it from the emitting workflow's identity, namespace:name:version, via a new CloudEventUtils.source(WorkflowDefinitionId). EmitExecutor.buildCloudEvent already has the WorkflowContext, so no new plumbing is needed. The no-arg static fallback changes from reference-impl to urn:serverlessworkflow:sdk-java.
  • time — in EmitExecutor, when the timeFilter is empty, set withTime(OffsetDateTime.now()) instead of omitting the attribute. Explicit literal/expression time is untouched.
  • Application-level default source — new WorkflowApplication.Builder#withDefaultEventSource(URI|String) lets an application set one source for all emitted events.
  • Resolution order (highest wins): explicit per-emit source → application-level default → workflow-identity-derived → static fallback.

Validation

EventProperties is deliberately left without @NotNull/@NotBlank annotations: it is shared between the emit and filter contexts, where required-ness differs, so annotating it would break filter use. With id, source, and time now all defaulted, type remains the only required emit attribute and EmitExecutor already throws when it is missing — runtime enforcement remains the correct approach.

Compatibility note

Changing the default source from reference-impl is a behavioral change; downstream consumers that filtered or asserted on source == "reference-impl" will need to update. This seems acceptable pre-1.0 but is called out here for release notes.

Testing

EmitCloudEventDefaultsTest (new) registers a capturing EventPublisher and asserts:

  • an emit with no source gets source == namespace:name:version and a time close to now;
  • an application-level default source overrides the identity-derived one;
  • an explicit per-emit source overrides the application default.

Full impl/test + impl/lifecycleevent suites pass (239 tests), confirming no regression in lifecycle-event or correlation behavior.

Downstream

Quarkus Flow tracks the DSL-ergonomics side in quarkiverse/quarkus-flow#776.

🤖 Generated with Claude Code

Fixes open-workflow-specification#1554

Emitted CloudEvents were under-specified: `source` fell back to the
opaque `reference-impl` and `time` was omitted entirely.

- Derive `source` from the emitting workflow's identity
  (`namespace:name:version`) via `CloudEventUtils.source(WorkflowDefinitionId)`
  when no source is supplied; change the static fallback from
  `reference-impl` to `urn:serverlessworkflow:sdk-java`.
- Default `time` to `OffsetDateTime.now()` in `EmitExecutor` when no time
  filter is present, instead of leaving it unset.
- Add an application-level default source
  (`WorkflowApplication.Builder#withDefaultEventSource`). Resolution order:
  explicit per-emit source, application default, workflow identity, static
  fallback.

`EventProperties` is intentionally left without bean-validation
annotations: it is shared between emit and filter contexts, so runtime
enforcement in `EmitExecutor` (type still required) remains the correct
approach.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@fjtirado

Copy link
Copy Markdown
Collaborator

This is a duplicate of #1556

@fjtirado fjtirado closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve CloudEvent defaults and validation for emit events

2 participants