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
In this repository57 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- advisorSkill
- agent-dispatchSkill
- arenaSkill
- audit-pypi-model-packageSkill
- branching-workflowSkill
- code-reviewSkill
- criticSkill
- cron-child-oauth-auditSkill
- daily-forestSkill
- deep-researchSkill
- diagnose-cron-timeoutSkill
- dreamingSkill
- eod-summarySkill
- filingSkill
- forest-synthesisSkill
- goalsSkill
- graph-hygieneSkill
- ideaSkill
- inline-tagsSkill
- intel-analyzerSkill
- longformSkill
- loop-experimentSkill
- loop-librarySkill
- meta-memory-reviewSkill
- office-hoursSkill
- open-loopsSkill
- plan-ceo-reviewSkill
- plan-design-reviewSkill
- prdSkill
- progressive-disclosureSkill
- reality-feedback-createSkill
- reality-review-weeklySkill
- recallSkill
- reconcile-extractionSkill
- redactSkill
- repo-auditSkill
- research-digestSkill
- review-gateSkill
- saveSkill
- scopeSkill
- self-auditSkill
- shadow-test-local-classifierSkill
- signal-scorerSkill
- skill-auditSkill
- skill-chainingSkill
- spawn-agent-in-tenantSkill
- spawn-tenantSkill
- split-log-rows-by-session-kindSkill
- subagent-delegationSkill
- telegram-dump-routerSkill
- telegram-reply-toolSkill
- verify-stackSkill
- wave-planSkill
- weekly-retroSkill
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
- Very specific: line 14
Take a lock first: If a PID file exists and kill -0 <pid> succeeds, log "skip: previous run still alive" and exit 0.
- Distinctive: line 23
If the job ends while the sender is dead, nothing is sent.
- Very specific: line 24
Keep secrets out of the wrapper.
≈ “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.
Files
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
- 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.
- 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. - Launch with
setsid nohup <cmd> >> <log> 2>&1 < /dev/null &, then write$!to the lock file.setsidgives the job its own session with PPID 1, so a tmux or agent kill does not reach it. - 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.
- Report the result. Proven pattern: the job sends its own result as its last step (a
--sendflag 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 akill -0and sleep loop, not onpgrep -f <script name>: a process-kill guard may block pattern-based process matching, and a PID check is narrower. - When it finishes, the sender writes one log line and the marker file. A later session checks the marker, not the live process.
- 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
.envat 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.
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
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.

