Skip to content

WCP 2/X: Thread batchID through HistoryBuilder AddEvent methods#10412

Open
simvlad wants to merge 2 commits into
temporalio:mainfrom
simvlad:fix-event-batching-add-event
Open

WCP 2/X: Thread batchID through HistoryBuilder AddEvent methods#10412
simvlad wants to merge 2 commits into
temporalio:mainfrom
simvlad:fix-event-batching-add-event

Conversation

@simvlad
Copy link
Copy Markdown
Contributor

@simvlad simvlad commented May 28, 2026

What changed?

HistoryBuilder.Add* methods that previously returned just the event now also return the batchID. MutableStateImpl threads that batchID into the corresponding Apply* calls, which use it to populate the batchID back reference set on the event fields.

This is stacked on top of #10357.

Why?

#10357 adds batch splitting in EventStore based on the size, which results in looser guarantees as to what batchId the event falls into. Previously these fields were set to workflowTaskCompletedEventID, which only happens to equal the new event's batch ID when the new event ends up in the same batch as the WorkflowTaskCompleted event.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

Potential risks

[Very low risk] The risk with this particular change is that in some cases we actually split the event with the WorkflowTaskCompleted event batches and we happen to expect WorkflowTaskCompleted present there instead of the event. This is very unlikely, since WorkflowTaskCompleted event ID is already set on some events and the naming such as ScheduledEventBatchId suggests the opposite.

@simvlad simvlad requested review from a team as code owners May 28, 2026 17:59
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb28d6b904

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +113 to +114
if len(b.memLatestBatch) > 0 && b.memLatestBatchSize+eventSize > limit {
b.FlushAndCreateNewBatch()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use actual batch IDs for all close events

When MaximumEventBatchSizeInBytes is enabled, this rollover can put a close event into a new batch after the caller has already guessed the batch's first event ID. The commit threads the returned batch ID for completed/failed/canceled workflows, but AddContinueAsNewEvent, AddTimeoutWorkflowEvent, and AddWorkflowExecutionTerminatedEvent still write CompletionEventBatchId from the precomputed firstEventID/WFT-failed ID; if the close event is split into its own batch, later completion-event loads use the wrong batch ID and can fail to find the close event. Please have those history-builder methods return the EventStore.add batch ID and apply that value too.

Useful? React with 👍 / 👎.

@simvlad simvlad changed the title Thread batchID through HistoryBuilder AddEvent methods WCP 2/X: Thread batchID through HistoryBuilder AddEvent methods May 28, 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.

1 participant