For control mode, begin/end are sent around all commands. Are these guaranteed to be ended before a new begin starts? Can they be interleaved? Show source code for evidence.
Control mode begin/end command interleaving behavior
Yes, they are guaranteed to be non-interleaved. Here's the evidence:
Looking at cmd-queue.c:
Commands are processed sequentially in
cmdq_next()(line 730-807). The queue processes one item at a time in afor(;;)loop.Begin/end are synchronous within
cmdq_fire_command()(lines 596-681):- Line 619:
cmdq_guard(item, "begin", flags);is called immediately before execution - Line 677-679: Either
"error"or"end"is called at the function's exit via theout:label
- Line 619:
Commands that wait (return
CMD_RETURN_WAIT) don't interleave because:- The wait happens after the command has already completed and emitted its
%end(line 679) - The
CMDQ_WAITINGflag (line 761-762, 793-794) just pauses the queue—no new command can fire
- The wait happens after the command has already completed and emitted its
Each client has its own queue (via
cmdq_get(c)), so cross-client interleaving doesn't apply to a single control client's stream.
The pattern guarantees: %begin → output → %end (or %error) for each command, never interleaved.