AGENT SKILL

detach

worktrail-detach — supervised out-of-harness launch with log/pid/exit sentinel so long-running runs survive the Claude Code background-task reaper

License 许可
MIT
最近更新
2026-11-14
Stars
★ 0
Forks
0

01 前言 Front Matter

name
detach
triggers
{ "files": [ "src/worktrail/runtime/detach.py", "tests/runtime/test_detach.py", "skills/worktrail-go/references/subagent-prompts.md" ], "keywords": [ "worktrail-detach", "detach", "run_in_background", "supervise", "exit sentinel", "full-real", "Monitor" ] }
description
worktrail-detach — supervised out-of-harness launch with log/pid/exit sentinel so long-running runs survive the Claude Code background-task reaper

03 SKILL.md 正文

You are working on worktrail-detach, the primitive that runs a long-running command outside the agent harness's tracked process tree (src/worktrail/runtime/detach.py, console script worktrail-detach).

Domain purpose

Claude Code's Bash tool run_in_background registers the child as a harness-tracked task, and on this fleet's WSL host the harness periodically reaps all of its own tracked background tasks (bare [killed], no exit code, no traceback, session survives). Every worktrail-live full-real, worktrail-preflight run, and headless worktrail-skill-dispatch launched that way died mid-run (some within 10–25 s), while the identical command launched detached ran to a clean exit every time (~/.devops/background-kill-hypotheses.md H9, confirmed 2026-08-29; 27 logged incidents through 2026-09-01). No cgroup/OOM is involved and no setting disables the reap — the fix is to never hand the harness a handle. worktrail-detach makes that a testable primitive instead of a hand-typed nohup … & disown each agent had to remember (and got wrong: nohup inside a run_in_background call is still tracked).

Business rules / invariants

  • launch is a plain foreground Bash call that returns immediately with a JSON handle (name, pid, supervisor_pid, log, pid_file, exit_file, cwd, wait_cmd). Never wrap it in run_in_background, nohup … &, setsid, or a trailing &.
  • Supervisor runs in its own session (subprocess.Popen(start_new_session=True), re-invoking python -m worktrail.runtime.detach _supervise); the real command is its child. Tests assert os.getsid/os.getpgid differ from the launcher's.
  • State per handle lives under $WORKTRAIL_HOME/detached/ (default ~/.worktrail/detached, overridable via --state-dir): <name>.log (stdout+stderr, appended, bracketed by [worktrail-detach] started … / exit rc=N lines), <name>.pid (child pid), <name>.exit (return code sentinel, written only after the child exits). A spawn failure writes 127.
  • --name must match ^[A-Za-z0-9][A-Za-z0-9._-]{0,120}$ — it becomes a filename; path escapes are rejected with SystemExit.
  • launch refuses to clobber a still-running handle of the same name (returns {"error": "already-running"}, exit code 3) unless --force. Stale pid/exit files are unlinked on relaunch.
  • Signals forward to the child: the supervisor traps SIGTERM/SIGINT/SIGHUP and re-sends them to the child, so killing the supervisor pid stops the run cleanly.
  • status states: exited (sentinel present) > unknown (no pid file; exit code 2) > running (pid alive) > gone (pid dead, no sentinel — read the log).
  • wait is the single source of truth for completion: follows the log from the current end (--from-start replays), prints only lines matching --match regex (default: none), then [worktrail-detach] exited rc=N, and exits with the run's own rc. A pid that dies without a sentinel yields exit 1 (gone without exit sentinel); --timeout yields 124.

Non-obvious behaviors

  • launch polls up to 5 s for the supervisor to write the pid file so the handle's pid is usually populated; pid may be null on a very slow host — status will still resolve it.
  • wait gives the supervisor one --interval after the child pid disappears before declaring it gone, since the sentinel lands a beat after the child exits.
  • The log's started cmd=[...] header contains the command's own text, so a --match pattern can match its own invocation line — tests put scripts in files for that reason.

How the skill docs use it

skills/worktrail-go/references/subagent-prompts.md #orchestrator launches full-real as worktrail-detach launch --name "orch-<repo>-<spec>" --cwd "$SPEC_ROOT" -- worktrail-live full-real …, confirms health with worktrail-detach status, then arms one Monitor on the handle's wait_cmd with a --match covering progress and failure signatures (pull/[0-9]+|MERGED|quarantin|escalat|FAILED|Traceback|circuit|blocked). Never sleep (harness blocks it) and never tail -f the log yourself. #openspec-propose long spawns use the same pattern with worktrail-skill-dispatch.

Critical files

  • src/worktrail/runtime/detach.py — launch / supervise / status / wait and the CLI
  • tests/runtime/test_detach.py — spawns real subprocesses (session placement and sentinel bookkeeping cannot be asserted with a mocked Popen)

Critical Rules

  • Any new long-running console-script invocation documented in a skill must use worktrail-detach launch from a foreground call — never run_in_background.
  • worktrail-detach is a [project.scripts] entry; tests/test_plugin_surface.py requires every skill-doc mention to match it exactly.

Last Updated: 2026-09-02

04 同仓库更多 Skills

behindthedash
behindthedash/worktrail

worktrail-sdd-workflow

Internal SDD workflow executor invoked by /go only. Do not call directly. Executes classified routes A–J: feature planning, implementation (parallel orchestration, PR generation), defect repair, refactoring, spec changes, investigation, and workflow evolution.

★ 0
behindthedash
behindthedash/worktrail

worktrail-routing-config

Configure Worktrail's agent routing table (`~/.worktrail/routing.yaml`, or a repo-local `routing:` policy block) — which harness/model executes each role and tier, and how fallback between them works. Use when the operator wants to add or remove a harness/adapter (claude/codex/opencode), add a model to an existing harness (e.g. adding a DeepSeek model to opencode), pin or change who does code review, add a new tier or purpose mapping, change the default tier, or is confused about which harness actually served a spawn (e.g. "why did this use Codex when I only configured Claude"). Trigger phrases: "routing.yaml", "add a harness", "disable a harness", "add an adapter", "remove an adapter", "add a model", "add deepseek to opencode", "change the reviewer", "pin the reviewer", "routing tiers", "routing targets", "default_tier", "independent reviewer", "why did codex get called". This skill is about *editing the config file*; it does not cover `/go`'s own dispatch mechanics (see `worktrail-go`'s SKILL.md Phase 7 for how `tier_for()`/`select_cell()` resolve it at runtime).

★ 0
behindthedash
behindthedash/worktrail

worktrail-repo-init

Bootstrap a new repo, or migrate an existing single-branch repo, onto the workspace's repo-standards doctrine (~/rules/CLAUDE.repo.md): the AGENTS.md-is-truth/CLAUDE.md-imports-it split, a dev/prd, dev/stg/prd, or main-only (trunk) branch model with matching GitHub rulesets, an OpenSpec scaffold, an auto-merge workflow, and a seeded .worktrail/policy.yaml. Trigger phrases: "onboard this repo", "apply repo standards", "initialize repo standards", "set up this repo like the rest of the fleet", "bring this repo into line with the repo standards doctrine".

★ 0
behindthedash
behindthedash/worktrail

worktrail-help

Show the Worktrail front-door commands and accepted positional arguments. Use when the user asks how to invoke worktrail-go, wants the available handoff, spec, pr, repo, or route forms, invokes worktrail-go with help or with a bare noun, or asks how to answer a filed product decision (worktrail-decision).

★ 0
behindthedash
behindthedash/worktrail

worktrail-handoff

Capture a discovered problem, gap, tech debt, or deferred work into a local work queue so a future agent session can pick it up cold. Use mid-session whenever you set work aside instead of doing it now — a fix you judge out of scope for this PR, work that belongs in a follow-up or a separate/later PR, an item you're deferring, or something worth fixing you won't tackle now — so the outstanding item isn't lost without derailing current work; can be called multiple times per session. Trigger phrases: "defer this", "item deferred", "out of scope for this PR", "follow-up work", "leave for another PR", "capture for later", "outstanding item". This skill captures only. Picking a brief back up is the front door's job: worktrail-go <brief-id>.

★ 0
behindthedash
behindthedash/worktrail

worktrail-go

Use when the user invokes worktrail-go, asks to pick up queued work, resume active specs, implement or fix a spec, route engineering work, or orient across repositories. Renders the orientation dashboard, classifies free-text requests, claims/resumes handoff briefs, and dispatches SDD work without requiring the user to know sdd-workflow. Grammar: worktrail-go [REPO] <noun> <verb>, nouns handoff / spec / pr / decision. Triggers: worktrail-go, worktrail-go help, worktrail-go spec fix, worktrail-go spec implement, worktrail-go spec route F, worktrail-go handoff new, worktrail-go handoff auto, worktrail-go decision answer, worktrail-go BRIEF-ID, bare worktrail-go, multi-repo orientation.

★ 0