iwf icon indicating copy to clipboard operation
iwf copied to clipboard

Support consuming N messages from channel in one command

Open pradhankukiran opened this issue 8 months ago • 3 comments

Description

Implements server-side support for AtLeast/AtMost fields on InterStateChannelCommand (fields already exist in IDL but were unused). Enables three consumption modes:

  • Exact N: AtLeast=N, AtMost=N — wait for exactly N, consume exactly N
  • OneToAll: AtLeast=1 (no AtMost) — wait for at least 1, consume all available
  • ZeroToAll: AtLeast=0 (no AtMost) — don't wait, consume all available

Messages are consumed atomically. Gated behind global version 11 for backward compat with existing workflows.

Note: The Values field on InterStateChannelResult was added manually to the generated model. A corresponding update to iwf-idl/iwf.yaml is needed so make idl-code-gen produces the same result.

Checklist

  • [x] Code compiles correctly
  • [x] Tests for the changes have been added
  • [x] All tests passing
  • [x] This PR change is backwards-compatible
  • [ ] This PR CONTAINS a (planned) breaking change (it is not backwards compatible)

Related Issue

Closes #301

pradhankukiran avatar Mar 17 '26 20:03 pradhankukiran

thanks for contribution. Can you add test to make sure it works?

longquanzheng avatar Mar 18 '26 19:03 longquanzheng

Codecov Report

:x: Patch coverage is 88.49558% with 13 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 65.13%. Comparing base (0c659fb) to head (747f4d9).

Files with missing lines Patch % Lines
service/interpreter/workflowImpl.go 79.62% 5 Missing and 6 partials :warning:
service/interpreter/deciderTriggerer.go 88.88% 1 Missing and 1 partial :warning:

:x: Your patch check has failed because the patch coverage (88.49%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #600      +/-   ##
==========================================
+ Coverage   64.74%   65.13%   +0.39%     
==========================================
  Files          64       64              
  Lines        6595     6695     +100     
==========================================
+ Hits         4270     4361      +91     
- Misses       1997     2002       +5     
- Partials      328      332       +4     
Files with missing lines Coverage Δ
service/interfaces.go 85.71% <ø> (ø)
service/interpreter/InternalChannel.go 81.35% <100.00%> (-12.93%) :arrow_down:
service/interpreter/activityImpl.go 65.20% <100.00%> (+0.78%) :arrow_up:
service/interpreter/continueAsNewer.go 87.16% <100.00%> (+0.08%) :arrow_up:
service/interpreter/globalVersioner.go 89.47% <100.00%> (+0.58%) :arrow_up:
service/interpreter/deciderTriggerer.go 92.30% <88.88%> (+5.82%) :arrow_up:
service/interpreter/workflowImpl.go 86.31% <79.62%> (-0.51%) :arrow_down:

... and 1 file with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Mar 18 '26 19:03 codecov[bot]

@longquanzheng added integration tests covering all 4 consumption modes (ExactN, OneToAll, ZeroToAll, AtMostOnly) across both Temporal and Cadence backends, with and without ContinueAsNew.

Also fixed a bug where AtLeast=0, AtMost=1 would panic on an empty channel, Retrieve() doesn't handle empty channels, so the code now routes through the safe RetrieveUpToN path when atLeast == 0.

pradhankukiran avatar Mar 28 '26 12:03 pradhankukiran

I am adding a follow-up commit. Plain is to keep CompletedInterStateChannelCommands as-is for continue-as-new compatibility, add InterStateChannelResult.values through IDL/codegen, validate invalid atLeast/atMost, and add focused unit coverage for the new channel/decider paths. I’ll update generated Go from the IDL locally, but the canonical iwf-idl change may need a separate PR/update in the IDL repo.

pradhankukiran avatar May 29 '26 13:05 pradhankukiran

I am adding a follow-up commit. Plain is to keep CompletedInterStateChannelCommands as-is for continue-as-new compatibility, add InterStateChannelResult.values through IDL/codegen, validate invalid atLeast/atMost, and add focused unit coverage for the new channel/decider paths. I’ll update generated Go from the IDL locally, but the canonical iwf-idl change may need a separate PR/update in the IDL repo.

yes, please open a separate PR in idl repo and merge in that first.

longquanzheng avatar Jun 01 '26 17:06 longquanzheng

@longquanzheng Opened the IDL PR here: https://github.com/indeedeng/iwf-idl/pull/91

pradhankukiran avatar Jun 02 '26 11:06 pradhankukiran

Good point. Removed the retry loop and the comment. Since workflow goroutines are cooperative, once Await returns this thread runs the synchronous retrieval without another command thread interleaving first, so a single consume path is enough.

pradhankukiran avatar Jun 11 '26 20:06 pradhankukiran

@longquanzheng Opened the IDL PR here: indeedeng/iwf-idl#91

oh , you also need to do it for iwf-sdk.yaml https://github.com/indeedeng/iwf-idl/blob/main/iwf-sdk.yaml

longquanzheng avatar Jun 12 '26 22:06 longquanzheng