From e89ae8adff143d80d145ae0e56401665741fb54d Mon Sep 17 00:00:00 2001 From: Sylpheed RE agent Date: Mon, 24 Aug 2026 08:52:24 +0000 Subject: [PATCH] tools: write down the pgrep -f trap that has now cost four mistakes An agent's commands run through a wrapper shell whose command line contains the pattern being searched for, so `pgrep -f 'pilot\.py'` matches the shell running that very pgrep, and `pkill -f 'fly_session|pilot\.py'` kills it mid-script. In one session this killed two running scripts and twice made an "is it already running?" guard answer yes because it had found itself. The [p]ilot bracket trick does not help, because the real invocation appears on the wrapper's command line too. Recorded with what works instead: pgrep -x on the exact name, or ps -eo args filtered against the snapshot-bash path that every wrapper carries, then kill by explicit pid. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01PMRJjbxLqZtsb5Vb7KunPE --- tools/re-capture/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/re-capture/README.md b/tools/re-capture/README.md index c19506c..a177fd0 100644 --- a/tools/re-capture/README.md +++ b/tools/re-capture/README.md @@ -33,3 +33,30 @@ Findings produced with these: [`docs/re/weapon-datasheet-runtime.md`](../../docs Snapshot first — `cp --sparse=always /dev/shm/xenia_memory_* snap.bin` (~2 s) — and point `$GMEM_FILE` at the copy; the running emulator pegs every core under lavapipe. + +## 🔴 `pgrep -f` / `pkill -f` match YOUR OWN shell + +An agent driving this toolkit runs its commands through a wrapper shell whose +**command line contains the pattern being searched for**. So + +```bash +pgrep -f 'pilot\.py' # matches the wrapper running this very command +pkill -f 'fly_session|pilot\.py' # kills that wrapper — the script dies mid-way +``` + +This has cost four separate mistakes in one session: two scripts killed +mid-execution, and twice a "is it already running?" guard that answered *yes* +because it had found itself. The `[p]ilot` bracket trick does **not** help when +the literal invocation (`python3 pilot.py …`) also appears on the wrapper's +command line. + +What works: + +```bash +pgrep -x xenia_canary # exact NAME match, no -f +ps -eo pid,args | grep 'python3 pilot.py' | grep -v snapshot-bash +kill -9 # look it up first, then kill by pid +``` + +The `snapshot-bash` filter is the reliable tell: the wrapper's command line +always contains the shell-snapshot path.