agentleFS
0xUrsanomics0xUrsanomics/utopia-os/skills/run-long-job-detached/SKILL.md

run-long-job-detached

Skill2 starsChanged 26 days agoMITView on GitHub

Run a script that takes longer than about 30 minutes so it survives session restarts and background-agent deaths, and still reports its result when it finishes.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Take a lock first: If a PID file exists and kill -0 <pid> succeeds, log "skip: previous run still alive" and exit 0.

    line 14
  2. Distinctive:

    If the job ends while the sender is dead, nothing is sent.

    line 23
  3. Very specific:

    Keep secrets out of the wrapper.

    line 24

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Run a long job detached, with a completion sender

Use when a job will outlive the session that starts it: a crawl, a backfill, a bulk render. Restarts kill background agents and the tmux session mid-task, so anything tied to the session or to an agent's Bash call is at risk. A two-hour crawl launched from an agent's Bash call will usually not finish.

Steps

  1. Do not run the job inside an agent or in the session's own Bash call. Start it from a small wrapper script that returns at once.
  2. Take a lock first. If a PID file exists and kill -0 <pid> succeeds, log "skip: previous run still alive" and exit 0. One run at a time, and a second launch is harmless.
  3. Launch with setsid nohup <cmd> >> <log> 2>&1 < /dev/null &, then write $! to the lock file. setsid gives the job its own session with PPID 1, so a tmux or agent kill does not reach it.
  4. Make the job resumable before you need it. Cache fetched pages or rows on disk with a TTL (24 hours is a sensible start for a crawl), so running the wrapper again continues instead of restarting.
  5. Report the result. Proven pattern: the job sends its own result as its last step (a --send flag on the job). Alternative, less tested: start a second detached script that waits on the job's PID, then sends the result (a digest to chat, the result file path) and drops a marker file. Wait on the PID with a kill -0 and sleep loop, not on pgrep -f <script name>: a process-kill guard may block pattern-based process matching, and a PID check is narrower.
  6. When it finishes, the sender writes one log line and the marker file. A later session checks the marker, not the live process.
  7. For a recurring run, put the wrapper in the scheduler as a shell task. It then costs no tokens and spawns no session.

Caveats

  • If the job ends while the sender is dead, nothing is sent. A missing marker file the next morning is the signal, not an error message.
  • Keep secrets out of the wrapper. The sender should read its bot token from the environment or a gitignored .env at run time.
  • Under about 10 minutes, a foreground run with an explicit timeout is simpler.

Output

The wrapper prints "launched pid N, log <path>". A finished job leaves four things: the log, the lock file (PID), the marker file and the result message.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.