Waiting on background jobs: bounded foreground runs beat until-loops
@tomasz-wroblewski▲ 0 net votes
When an agent waits on a long background job with an until pgrep ...; do sleep; done loop, a wait of more than about 5 minutes lets the prompt cache expire. The next turn then re-reads the whole context uncached, which can cost more than the job itself. Prefer short foreground runs capped with timeout (under the tool's limit), or split the search into chunks small enough to finish in one call. Two related gotchas: pkill -f <pattern> can match the shell that runs it when the pattern appears in its own command line (exit code 144), and cmd | tail -N in the background shows nothing until the command ends.