Skip to content

[Nexus/CHASM] Use token instead of storing batch ID for event load#10154

Open
bergundy wants to merge 2 commits intotemporalio:mainfrom
bergundy:nexus-chasm-event-load-token
Open

[Nexus/CHASM] Use token instead of storing batch ID for event load#10154
bergundy wants to merge 2 commits intotemporalio:mainfrom
bergundy:nexus-chasm-event-load-token

Conversation

@bergundy
Copy link
Copy Markdown
Member

@bergundy bergundy commented May 1, 2026

What changed?

Added a method to generate an event load token in:

  • MutableState
  • MutableStateImpl
  • chasm.NodeBackend
  • chasm.MSPointer
  • workflow.Workflow

Why?

This was pointed out during the initial implementation but was not addressed. The point of having a token is to avoid exposing the persistence concept of event batches to the application.

@bergundy bergundy requested review from a team as code owners May 1, 2026 19:59
@bergundy bergundy changed the title Use token instead of storing batch ID for event load [Nexus/CHASM] Use token instead of storing batch ID for event load May 1, 2026
Copy link
Copy Markdown
Contributor

@chrsmith chrsmith left a comment

Choose a reason for hiding this comment

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

This all LGTM, assuming that modifying the proto is safe to do.

// Batch ID of the NEXUS_OPERATION_SCHEDULED event.
int64 scheduled_event_batch_id = 2;
// Token for loading the NEXUS_OPERATION_SCHEDULED event.
bytes scheduled_event_token = 2;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With this being a breaking change to the proto, is this going to cause problems for existing workflows/operations in the wild? Or if the frontend and history services differ in which version of the code they are running?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This isn't enabled yet, which is why it was important to make this change now.

func (ms *MutableStateImpl) GenerateEventLoadToken(event *historypb.HistoryEvent) ([]byte, error) {
attrs := reflect.ValueOf(event.Attributes).Elem()

// Attributes is always a struct with a single field (e.g: HistoryEvent_NexusOperationScheduledEventAttributes)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: If that was true, then we wouldn't need this check 😄

Suggested change
// Attributes is always a struct with a single field (e.g: HistoryEvent_NexusOperationScheduledEventAttributes)
// Attributes are expected to be a struct with a single field (e.g: HistoryEvent_NexusOperationScheduledEventAttributes)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's true and will always be true. This is just a sanity check.

@stephanos stephanos self-requested a review May 1, 2026 21:08
@bergundy bergundy force-pushed the nexus-chasm-event-load-token branch from 5cdebf1 to 73d99e3 Compare May 1, 2026 21:46
f := attrs.Field(0).Interface()

var eventBatchID int64
if getter, ok := f.(interface{ GetWorkflowTaskCompletedEventId() int64 }); ok {
Copy link
Copy Markdown
Member

@yycptt yycptt May 2, 2026

Choose a reason for hiding this comment

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

this will no longer be true when we support commands pagination and support workflow task returning combined command size > 4MB.

cc @simvlad plz work with nexus crew on this.

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.

4 participants