command-lifetime
Diagnose a shell command refused or flagged for having no bound on its lifetime — an unbounded while/until loop, an unbounded background launch, or a long-running command with no timeout.
- License 许可
- MIT
- 所属仓库
- muratovv/ai-hats
- 最近更新
- 2026-11-05
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- command-lifetime
- ai_hats
- { "type": "skill", "schema_version": 1 }
- license
- MIT
- description
- Diagnose a shell command refused or flagged for having no bound on its lifetime — an unbounded while/until loop, an unbounded background launch, or a long-running command with no timeout.
02 资源文件 3
- 脚本hooks/bypass_journal.py35 B
- 脚本hooks/bypass_journal.sh35 B
- 脚本hooks/pre_bash_lifetime_guard.sh11.7 KB
03 SKILL.md 正文
Command Lifetime
Nothing bounds how long a shell command launched on the agent's behalf stays alive. This skill carries the one guard that does.
Why the obvious bounds don't cover it
Two mechanisms look like they already solve this, and neither fires where the problem is:
- The Bash tool's
timeoutbounds the call, not the process. A foreground command that exceeds its budget is moved to the background, not stopped. bounded_proc_shutdown(src/ai_hats/pty_shutdown.py) reaps the provider's process group — when the session ends.
Both are correct. Both are absent from a long-lived session, which is the
session a person is sitting in front of. Field evidence: three wait-loops alive
21 h 25 m, 83 minutes of CPU between them, found by hand in ps.
What the guard does
| Shape | Verdict |
|---|---|
while / until with no timeout, no read-until-EOF, no counter |
deny |
run_in_background: true with no timeout |
deny |
install / fetch / image pull with no timeout |
nudge |
| everything else | silent |
The split is not severity, it is whether advice has anything to appeal to. An unbounded loop cannot terminate on its own; a long command finishes. A deny on the third row would fire on routine work, and a gate that cries wolf gets switched off — worth less than the nudge it replaced.
Diagnosing a refusal
The refusal names the bounded spelling. Take it literally:
# refused — nothing stops this
until grep -q done /tmp/run.log; do :; done
# bounded by wall-clock; 124 tells you the bound was hit
timeout 300 bash -c 'until grep -q done /tmp/run.log; do sleep 5; done'
# or don't write the loop — Monitor is built for waiting on a condition
Three shapes are allowed without a timeout, because each already ends:
while read … done < file (EOF), a loop carrying a counter (++, +=,
=$((), and any for … in <list> (the guard never looks at those).
Deliberately long-lived processes
AI_HATS_LIFETIME_ACK=1 relaxes the refusal. It must be in the environment that
launched the agent — this hook runs before the command it judges is a
process, so AI_HATS_LIFETIME_ACK=1 <command> never reaches it. Taking the
hatch is recorded in the bypass journal. It is the supervisor's to set, not the
agent's.
Why the guard does not add the timeout itself
It could — updatedInput is a real capability here; safety_gate.py already
answers ask plus a rewrite in one reply. The guard refuses instead, so the
number in timeout N is one the agent chose. A bound nobody picked produces an
exit 124 nobody can interpret.
Anti-Patterns
- Reading this skill to decide whether to write a loop — it is infrastructure; the guard speaks when it needs to.
- Adding a second nudge here for test runners —
tool-call-hygienealready owns that surface, and two nudges about onepytestrun is how a channel gets tuned out. - Setting
AI_HATS_LIFETIME_ACKto get past a refusal. The hatch answers a supervisor's deliberate long-lived process; the refusal usually means the bound is genuinely missing.
04 同仓库更多 Skills
tool-evaluation-protocol
Time-bounded protocol for evaluating new tools, libraries, or methodologies before adoption. Use when evaluating a candidate dependency for the project, researching a methodology (e.g. ML/LLM frameworks, testing approaches), or following up on a hype-driven recommendation.
systematic-debugging
4-phase bug-fix protocol (evidence, pattern, hypothesis, verify). Use when investigating any error, failure, or unexpected behavior, handling bug reports from users or monitoring, or diagnosing test failures with non-obvious causes.
skill-template
Canonical template and validation guide for ai-hats skills. Use when creating a new skill, reviewing an existing one for structural compliance, or deciding which pattern fits a new behavior.
skill-optimization
Audit and refactor library components to eliminate redundancy and staleness. Use during periodic library maintenance, after adding multiple new skills or rules, when a role's token budget is too high, or after retrospectives identify component issues.
silent-fallback-gate
PreToolUse hook — refuses an Edit or Write that adds an inert broad except. Use when a Python edit was blocked for a silent fallback.
retro-to-framework
Convert an observation about agent behavior — from a retrospective or from a single incident — into a framework-level change (hook, rule, skill, skill update). Use after a retrospective identifies problems that are not project-specific, after an incident where an agent misapplied a component it had read, when CLAUDE.md band-aids accumulate (more than 3 per-project rules that could be generic), or when the same problem recurs across multiple projects.