openwhisk icon indicating copy to clipboard operation
openwhisk copied to clipboard

discussion: parameters in action sequence

Open sjfink opened this issue 10 years ago • 56 comments

Right now our programming model says that in an action sequence A -> B, only the output of A is passed to B, as in Unix pipes.

An alternative would be that all parameters passed to A are also passed to B, along with the output of A, merged via overwriting.

Options include:

  • keep things the way there are
  • change things to alternative B
  • support either/or via a flag.

Input welcome.

sjfink avatar Mar 23 '16 19:03 sjfink

based on personal experience and questions i received, i think it would be more intuitive of all parameters would be available to all actions

mbehrendt avatar Mar 23 '16 20:03 mbehrendt

I like the idea of having the parameters initially passed to the sequence being available to all actions. If not and you need some parameters passed to an action later on in the sequence than the actions start to for dependencies on each other. I would like to have the option of keeping them completely independent of eat other.

ryanjbaxter avatar Mar 23 '16 20:03 ryanjbaxter

I made this mistake once - of assuming it was B. There is the risk that if you pass parameters to all actions, user might accidentally leak secrets to actions they did not intend to leak. If we support both, some questions then:

  1. what's the common case default.
  2. how do you merge parameters from the initial input with the result produced by an action in the sequence (result takes precedence in case of a collision?).

rabbah avatar Mar 23 '16 20:03 rabbah

personally, i wouldn't support both (complicates things).

to me, a reasonable behavior is that the last write of a parameter value wins

mbehrendt avatar Mar 23 '16 20:03 mbehrendt

Let me try to describe why I support the current implementation. It has a natural definition as function composition:

(a1 sequence a2)(args) = a2(a1(args))

This plays nicely with the intuition that serverless architecture such as OpenWhisk give you "functions in the cloud".

Now, in the variant where arguments are forwarded to all actions in the sequence, I don't understand if they are also forwarded to the final output? If they are, then:

a1 != (a1 sequence identity)

...because the second version also returns the input arguments. ~~If they are not forwarded, then sequencing doesn't compose:~~

(a1 sequence (a2 sequence a3)) != ((a1 sequence a2) sequence a3)

~~In the first case, a3 has access to the input argument of a1, in the second case, it does not.~~

I find both alternatives less intuitive than having to explicitly copy some of the inputs to the output of an action.

I understand of course that there are use cases where forwarding is desirable (maybe passing authentication tokens?), but I would prefer that we explicitly identify them first, and solve them by more appropriate means that changing the definition of action sequencing.

Edit my second example is wrong. I need to think more about the second sub-scenario.

psuter avatar Mar 23 '16 22:03 psuter

Now, in the variant where arguments are forwarded to all actions in the sequence, I don't understand if > they are also forwarded to the final output? If they are, then: a1 != (a1 sequence identity)

Suppose they are in fact forwarded to the final output.

You are correct that a1 != (a1 sequence identity)

Recall that actions produce and consume maps. Define for map M, M[p] is the value of M for key p, and undefined if M does not contain the key p

If we define actions A and B are equivalent (===) iff for all x,p: A(x)[p] == B(x)[p] whenever both A[p] and B[p] are defined.

I would like to claim that a1 === (a1 sequence identity)

sjfink avatar Mar 23 '16 22:03 sjfink

I think your theorem holds, but I'm not sure I like the assumption that { "password": "123456" } and {} are the same object.

psuter avatar Mar 23 '16 22:03 psuter

Clearly they are not the same object. But that may be a valid and useful definition of "actions are equivalent" despite this fact.

In fact I think it's quite common in math to define two functions to be equivalent if they are equal wherever they are both defined. I can probably dig up examples if requested.

sjfink avatar Mar 23 '16 22:03 sjfink

One more thing we should clarify in scenario B is whether the default parameters are forwarded as well. If I do:

wsk action create foo -p token secr3t foo.js
wsk action create bar --sequence foo baz

...does baz always receive the token parameter when used in the bar sequence?

psuter avatar Mar 23 '16 23:03 psuter

@psuter in your last example i'ld argue that those parameters are not forwarded as they are explicitly bound to a function (a bit like currying the function even?). These edge-cases make things more complicated though, as they break with our assumption of JSON-in, JSON-out as those parameters would need to be handled in a special way, even though they are part of the object given to the function in the first place.

In general, do we define the sequence itself as a composition of functions:

f2(f1(args));

or more like a wrapper around a composition of functions:

sequence(args) {
    f2(f1(args));
}

In case of a wrapper function it feels way more natural, that every function has access to the arguments given to that wrapper function, while not having access bound to the actions explicitly as in @psuter s last example.

markusthoemmes avatar Mar 23 '16 23:03 markusthoemmes

Clearly they are not the same object. But that may be a valid and useful definition of "actions are equivalent" despite this fact.

In fact I think it's quite common in math to define two functions to be equivalent if they are equal wherever they are both defined. I can probably dig up examples if requested.

Sure, it can be a definition. It has strange properties, though, like the fact that it doesn't induce an equivalence relation, since f1 === f2 && f2 === f3 doesn't imply f1 === f3 (take f2 := function (args) { return {}; }, which is equivalent to every other action, for a particularly egregious example).

This discussion on the proper definition of equivalence is a bit of a digression anyway. My concrete concern was "leaking" of input values, but I think the question above about default parameters is a better way to frame the issue.

In any case, my goal is not (I swear!) to write equations. I just really hope that it is clear from the discussion we are having that there are subtle implications behind both options A and B.

psuter avatar Mar 24 '16 00:03 psuter

What are the subtleties on A? That some users (me included) made the mistake of thinking it was B? Assuming A is the current semantics. I prefer we keep the current semantics which fit more naturally in composition or streaming.

We don't distinguish default vs other arguments now. I don't think we should either.

rabbah avatar Mar 24 '16 00:03 rabbah

What are the subtleties on A? That somehow some users (me included) made the mistake of thinking it was B?

Yes, and the mistake is reasonable, if you think procedurally:

inputs1 = ...
results1 = do_action_1 // inputs1 in scope
results2 = do_action_2 // both inputs1 and results2 in scope

psuter avatar Mar 24 '16 00:03 psuter

I like version A (the current implementation) better. I find it simpler. Also, option B can be simulated by copying inputs to outputs. If we have only option B in place, you can't avoid passing the params to all actions in the sequence, whether they need it or not.

I don't like the idea of supporting both versions. It complicates design and interfaces unnecessarily.

ioana-blue avatar Mar 24 '16 01:03 ioana-blue

OK, let's consider a use case.

I want to create a an action 'translatedForecast' which gives me the weather.com forecast in a language 'L' which is a runtime parameter.

I have as building blocks 2 actions: 'forecast' and 'translate' . The latter takes a string 'S' and a language 'L' and gives me 'S' translated into language 'L'.

These are library (system) packages - not my own.

Option B lets me write 'translatedWeather := 'forecast' , 'translate' Option A forces me to write a bunch of nasty glue code.

Agree/disagree?

sjfink avatar Mar 24 '16 05:03 sjfink

That glue code was what i was concerned about aswell. Passing the top-level parameters to all functions is a more general strike and let's you include more general functions (like system packages) in your flow without the need of writing glue code. In Steve's example above, it's not even possible to pass the language parameter L at runtime, right? You'ld need to bind it at creation time which would decrease reusability of the sequence itself.

markusthoemmes avatar Mar 24 '16 07:03 markusthoemmes

The trade off is simple: globally scoped immutable variables (which means in your example say there was also an API key that is now accessible to third party code that it has no business seeing), or locally scoped ones which may require you to add a level of indirection so that instead of composing the third party action directly in the sequence, there is a wrapper around each that filters and passes whatever parameters that one may need (this is the glue code referred to above).

Global variables are convenient, but leak information.

There may also be unintended consequences. Suppose two actions in the sequence use the same key but the semantics are different or require different values (e.g., API key again). How can you disambiguate? You'll have to write the glue code anyway. This is not an inherent problem to whisk.

@psuter lays these out as either function composition or a procedure implementing a sequence.

rabbah avatar Mar 24 '16 08:03 rabbah

We could approach this differently: when creating a sequence, you can optionally provide a function projectParamrers which projects from the input arguments that are applied to the sequence those specific to each action in the sequence (by position or name). The projected parameters are merged with the results of a previous action before applying the next action in the sequence. I think this can be reduced to a function composition... Thinking.

rabbah avatar Mar 24 '16 08:03 rabbah

Global variables are convenient, but leak information.

Absent any new constructs, I think this sentence captures the tradeoff perfectly.

sjfink avatar Mar 24 '16 12:03 sjfink

i'm wondering whether the 'information leakage' is a big issue, given it's not sth behind the scenes, but the way how global variables work would be documented transparently -- and everyone can decide whether they want to leverage action sequences or not. i'd err on the side of convenience and if someone wants to have granular control over how variables flow, they can still call actions programmatically

mbehrendt avatar Mar 24 '16 12:03 mbehrendt