Skip to content

fix: preserve batch fast-path when non-add/remove messages are present - #299

Closed
Ouriel wants to merge 1 commit into
infiniticio:mainfrom
Ouriel:fix/batch-fastpath-mixed-messages
Closed

Ouriel wants to merge 1 commit into
infiniticio:mainfrom
Ouriel:fix/batch-fastpath-mixed-messages

Conversation

@Ouriel

@Ouriel Ouriel commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Refs #297 — Ensures AddTagToWorkflow/RemoveTagFromWorkflow messages always use the optimized bulk storage path, even when other message types are in the same batch.

Problem

batchProcess() has a fast-path (batchProcessAddRemoveOnly) that does a single bulk Redis read + single bulk Redis write (2 storage calls regardless of batch size). However, this fast-path only activates when all messages in the batch are add/remove.

When any other message type is present (e.g., ContinueWorkflowTagFanout, DispatchWorkflowByCustomId), the entire batch falls into the sequential fallback path where each message hits storage individually — O(N) calls.

Production metrics showed AddTagToWorkflow latency went from sub-ms to 6.5s because these messages were stuck in mixed batches.

Fix

Partition the batch: add/remove messages always go through the bulk path, other messages are processed separately per tag.

val (addRemove, others) = messages.partition { (message, _) ->
    message is AddTagToWorkflow || message is RemoveTagFromWorkflow
}
if (addRemove.isNotEmpty()) batchProcessAddRemoveOnly(addRemove)
if (others.isNotEmpty()) { /* process per tag */ }

What was tested

All 10 existing tests pass, including the batch equivalence test that verifies batch and one-by-one processing produce identical results.

Partition the batch so AddTagToWorkflow/RemoveTagFromWorkflow always
go through the optimized bulk path (2 storage calls), regardless of
what other message types are in the batch.

Previously, a single ContinueWorkflowTagFanout or other message type
in the batch would force ALL messages into the sequential fallback
path (O(N) storage calls).

Refs infiniticio#297
@Ouriel
Ouriel force-pushed the fix/batch-fastpath-mixed-messages branch from 44f5c0a to 173f01b Compare April 25, 2026 19:55
@geomagilles

Copy link
Copy Markdown
Collaborator

Redundant with 0.18.4

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.

2 participants