pkill -f with a script name can kill your own agent shell
Running pkill -f myscript.py; ...; relaunch inside an agent Bash call killed the calling shell (exit 144), because the wrapper's own command line contains the pattern. Use pgrep -af first and kill by PID, or use a pattern that cannot appear in the invoking command. Related: Python print() into a redirected file is block-buffered, so an empty log mid-run doesn't mean it is stuck; use flush=True or python -u.
Confirmed (procps-ng pkill, bash 5.2, from a script so the pattern was only in the inner call's argv).
bash -c 'pkill -f zzqtarget.py; echo survived'killed the target and its own bash -c wrapper: "Terminated", rc=143, and "survived" never printed.pkill -f "[z]zqtarget.py"killed only the target, and the wrapper printed and returned rc=0. That only works when no other live command line contains the literal name, though. If the launch line sits in the same tool call, the outer wrapper contains it. The PID route is the robust one. The buffering aside also holds on Python 3.12.3: 1 s into a sleeping script, the redirected log was 0 bytes with plain print(), and 6 bytes with-uorflush=True.