Skip to content

Add EventStreamPosition envelope extension#148

Merged
jmalloc merged 3 commits into
mainfrom
event-stream-position-extension
May 16, 2026
Merged

Add EventStreamPosition envelope extension#148
jmalloc merged 3 commits into
mainfrom
event-stream-position-extension

Conversation

@jmalloc
Copy link
Copy Markdown
Member

@jmalloc jmalloc commented May 12, 2026

Summary

  • Adds envelopepb.EventStreamPosition, a canonical extension message carrying stream_id + offset, so event store implementations no longer need ad-hoc encodings (e.g. wrapperspb.UInt64Value or fabricated anypb.Any type URLs) to attach a stream position to an envelope after recording.
  • Adds generic envelopepb.SetExtension[T] / GetExtension[T] and symmetric SetBaggage[T] / GetBaggage[T] for post-pack mutation of extension/baggage values on an envelopepb.Body. Previously only the pack-time WithExtension / WithBaggage options were exported.
  • Closes Add a stream position extension message to envelopepb #147.

Test plan

  • `make precommit` passes locally
  • CI green

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a canonical envelopepb.EventStreamPosition protobuf message for recording stream ID + offset as an envelope extension, and adds post-pack mutation/access helpers for Body extensions and baggage.

Changes:

  • Added EventStreamPosition message (plus generated Go/primo code) to standardize stream position encoding in Body.Extensions.
  • Added generic SetExtension/GetExtension and SetBaggage/GetBaggage helpers, with accompanying tests.
  • Updated CHANGELOG.md to document the new APIs and message type.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
protobuf/envelopepb/packer.go Moves flattenAnyValues() into packer to support normalization logic.
protobuf/envelopepb/extensions.proto Defines EventStreamPosition extension message.
protobuf/envelopepb/extensions.pb.go Generated Go code for EventStreamPosition.
protobuf/envelopepb/extensions_primo.pb.go Generated primo builder/helpers for EventStreamPosition.
protobuf/envelopepb/extensions.go Adds SetExtension/GetExtension helpers for Body.Extensions.
protobuf/envelopepb/extensions_test.go Tests for the new extension helpers.
protobuf/envelopepb/baggage.go Adds SetBaggage/GetBaggage helpers for Body.Baggage.
protobuf/envelopepb/baggage_test.go Tests for the new baggage helpers.
CHANGELOG.md Documents the new helpers and EventStreamPosition.
Files not reviewed (2)
  • protobuf/envelopepb/extensions.pb.go: Language not supported
  • protobuf/envelopepb/extensions_primo.pb.go: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread protobuf/envelopepb/extensions.go Outdated
Comment thread protobuf/envelopepb/extensions.go
Comment thread protobuf/envelopepb/baggage.go Outdated
Comment thread protobuf/envelopepb/baggage.go
jmalloc added a commit that referenced this pull request May 12, 2026
Changed the parameter type from proto.Message to the generic type argument T,
so the runtime type and the type argument cannot disagree at compile time.
Go can now infer T from the value at most call sites, removing the explicit
type annotation. A direct nil check on the typed parameter now catches
typed-nil pointers that previously slipped past marshalAsAny's interface-nil
check.

Updated GetExtension/GetBaggage doc comments to match the implementation:
the bool return value indicates whether an extension/baggage value of the
matching type was present; the error return value carries the unmarshal
outcome separately.

Addresses Copilot review feedback on #148.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jmalloc and others added 3 commits May 16, 2026 13:52
Adds envelopepb.EventStreamPosition — a canonical extension message that
identifies the stream from which an event was obtained and its offset within
that stream — so event store implementations no longer have to invent ad-hoc
encodings (e.g. wrapperspb.UInt64Value or fabricated anypb.Any TypeUrls) to
attach the position to an envelope after recording.

Adds generic envelopepb.SetExtension[T] / GetExtension[T] and the symmetric
SetBaggage[T] / GetBaggage[T] for attaching and reading extensions and
baggage values on an envelopepb.Body after packing. Previously only the
pack-time WithExtension / WithBaggage options were exported.

Closes #147.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Changed the parameter type from proto.Message to the generic type argument T,
so the runtime type and the type argument cannot disagree at compile time.
Go can now infer T from the value at most call sites, removing the explicit
type annotation. A direct nil check on the typed parameter now catches
typed-nil pointers that previously slipped past marshalAsAny's interface-nil
check.

Updated GetExtension/GetBaggage doc comments to match the implementation:
the bool return value indicates whether an extension/baggage value of the
matching type was present; the error return value carries the unmarshal
outcome separately.

Addresses Copilot review feedback on #148.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Use SetExtension[*Type](body, nil) instead of the more verbose
SetExtension(body, (*Type)(nil)). With T specified explicitly the nil
literal takes on the parameter's typed-nil interpretation, which is
exactly the case the panic check is designed to catch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jmalloc jmalloc force-pushed the event-stream-position-extension branch from a57f9bd to 33be67e Compare May 16, 2026 03:53
@jmalloc jmalloc enabled auto-merge May 16, 2026 03:54
@jmalloc jmalloc merged commit f5661e2 into main May 16, 2026
11 checks passed
@jmalloc jmalloc deleted the event-stream-position-extension branch May 16, 2026 03:55
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.

Add a stream position extension message to envelopepb

2 participants