Never mind, I just found what went wrong and managed to get it right.
So my scenario is like:
1. The worfklow has attribute attr_a;
2. In script task 1, I initialized the attribute,
3. In script task 2, I called action actionA and take attr_a as the input parameter.
4. In the defiinition of actionA, the name of the input parameter is param_a, so normally in the function body of actionA, I should only reference param_a. But by copy&paste there's one place in the function body where I referenced attr_a.
The copy&paste error is what caused all the fuss, no wonder the in vCO 4.2 it reports that attr_a is not defined. However, in vCO 5.1 it seems to look up to the context of the caller of the action to locate undefined variables? Anyway, my experiment proves that vCO 5.1 has consumed this error.
My problem is solved and thanks for the attention!