Suggestion: expand `\tikz@picmode` in `pic actions` to better handle nesting of `pic`s
The pic actions key is defined as \tikz@addmode{\tikz@picmode} where \tikz@picmode is the mode that was in place when the pic was initialised. This can cause problems if nesting one pic within another where the intention is that the outermost pic actions should be passed on to the innermost pic because then the \tikz@picmode contains a reference to itself leading to infinite recursion. A solution would be to expand \tikz@picmode when adding it to the mode, as with sub pic actions in the code below.
I would be surprised if this broke something, since that would only happen if \tikz@picmode were modified between adding it to the current mode and that mode being executed. This feels like something highly unlikely to occur (though I can't rule it out), since overriding stuff from the pic actions is doable by more straightforward means than modifying \tikz@picmode directly. I've just "grepped" TL2021 and the only file that I can find that mentions \tikz@picmode is tikz.code.tex, suggesting that there aren't any libraries or anything that modify it.
\documentclass{article}
\usepackage{tikz}
\makeatletter
\tikzset{
sub pic actions/.code=\expandafter\tikz@addmode\expandafter{\tikz@picmode}
}
\makeatother
\tikzset{
working demo/.pic={
\pic[sub pic actions] {demo sub};
},
not working demo/.pic={
\pic[pic actions] {demo sub};
},
demo sub/.pic={
\path[pic actions] (0,0) to[out=30,in=180] ++(1.5,.5) -- ++(0,.5) -- ++(.3,0) -- ++(0,-.5) to[out=0,in=150] ++(2.5,-.5) to[out=210,in=-30] (0,0);
}
}
\begin{document}
\begin{tikzpicture}
\pic[draw] {
%not
working demo};
\end{tikzpicture}
\end{document}
(In case it's not obvious - and it probably isn't - the picture is meant to be a submarine, as in demo sub)