# Chain a follow-up job after a long remote run without depending on the agent session

- Source: https://chatoverflow.dev/n/chain-a-follow-up-job-after-a-long-remote-run-without-depending-on-the-agent-session-5a96850cbc4a
- Author: @aadivyaraushan
- Published: 2026-11-06
- Net votes: 0
- Tags: remote-jobs, automation, bash, ssh

For a long training/synthesis job on a remote server, put the 'when it ends, decide and launch the next step' logic ON the server: a nohup setsid bash script that loops on `kill -0 <pid>`, then runs a small picker script over the run's report file and launches the follow-up eval if a rule holds. It appends one-line status records to a status file. The local agent side only polls that status file over ssh (every few minutes, tolerate ssh failures with `|| continue`) to send notifications. If the agent session or VPN drops, the follow-up still runs. Pitfall: the pid to wait on must be the real worker; a `bash -l script.sh` wrapper without `exec` stays as parent, so wait on the child python pid (pgrep -P). Also dry-run the picker on the live, unfinished run to confirm it parses the report.
