First of all, I think the Lua error was triggered by CHDK calling resume() without a yield().
This should not be possible. It would mean either that multiple tasks were running the action stack, or that something within a lua C function called lua_script_run.
However, you could test what happens if you call resume without a yield by adding code to force that.
I think this happened because the action stack cleared abnormally before action_stack_AS_LUA_WAIT_CLICK() was finished.
I don't understand how this could happen. kbd_task isn't going to run another iteration until the call returns, which means that lua has yielded. The entire kbd_task including all the lua code and action stack functions run sequentially. Once lua has been entered, action stack processing does not happen again until lua has yielded or exited. The only way to get back into lua is if action_stack_AS_SCRIPT_RUN is on top of the stack.
Perhaps I don't understand what you are trying to say.
So do you think this could be happening?
No.
Is action stack called from a different task?
Not unless something is very badly wrong, and if it did, it would lead to near instant corruption of the lua state, which would very quickly cause crashes and other bad behavior. The exact nature of the bad behavior would be highly dependent on timing and memory organization, so it would be exceedingly unlikely to show the exact same symptom across different builds, cameras and scripts.
Looking at your debug code:
If action_stack_AS_LUA_WAIT_CLICK() returns 0, then you can yield with labser1 == -9
lua_yield will eventually make lua_resume return, so it's quite possible that the error occurs after that yield.
You could add new lapser1 value right before the return 0 to check for this.