Agent emergency

From leopu00/job-hunter-team · View interactive version

Agent emergency is an AI agent skill from the GitHub repository leopu00/job-hunter-team. Capitano — handles an agent suspected of being STUCK IN AN ACTIVE LOOP (alive and generating turns, but repeating the same cycle without producing anything: ACK ping-loop with a peer, same action/query going nowhere). Covers the crack between C-08 (dead/silent → Dottore) and C-12 (burning at cadence

How to use this skill

Skill file

agent-emergency — agent stuck in an active loop

Why it exists (the crack between C-08 and C-12)

The existing signals cover two cases:

The third one is missing: **an agent that is ALIVE and ACTIVE and REPEATS the same cycle without

producing anything**. It generates turns (so it is NOT "dead" and does NOT have cadenza 0.00), but

it makes no progress. Real examples:

It used to be invisible → the Capitano never stepped in. This skill makes it detectable and

manageable.

When to use it

On SUSPICION, not across the board and not on every tick. Start this procedure when you notice

one of these hints (usually while doing something else): an agent that has been "working" for a

while but whose queue is not shrinking / no new position changes state; or you see the same exchange

repeating in the chat/pane.

1. DETERMINISTIC detection (no eyeballing)

Confirm the loop with two cheap checks — no message to the agent (do not disturb it, this is

Tier-2 pull):

# (a) REPETITION — does the pane show the same exchange/output N times?
#     Two captures spaced apart: if the "new" content is identical → it is repeating.
tmux capture-pane -t <SESSION> -p -S -60 > /tmp/ae_1.txt
sleep 20
tmux capture-pane -t <SESSION> -p -S -60 > /tmp/ae_2.txt
diff /tmp/ae_1.txt /tmp/ae_2.txt        # little/no "real work" difference = suspected loop

# (b) 0 DB PROGRESS — is the agent "active" but moving nothing in the DB?
#     If available, the by-agent observability helper (it reuses
#     position_state_transitions): 0 recent transitions for this agent = no output.
python3 /app/shared/skills/db_query.py recent-activity   # by_agent: 0 for the session = no output
#     Generic fallback: the queue upstream of the agent does NOT shrink between two checks
#     (e.g. next-for-analista unchanged while ANALISTA-N is "working").

LOOP verdict = (a) repetition AND (b) 0 progress, over ≥ 2-3 observations. If instead the

pane shows Working… / esc to interrupt with content that keeps changing, it is a **long task that

is ALIVE** (C-08 bis): that is NOT a loop, leave it alone.

2. Graduated ladder — Dottore-FIRST

Rung 1 — extraordinary Dottore round (FIRST intervention)

A context refresh often breaks the loop without losing state. Use the spawn-doctor skill:

bash /app/.launcher/spawn-doctor.sh
sleep 10
jht-tmux-send DOTTORE \
  "[@$MY_ID -> @dottore] [REQ] Targeted round: <SESSION> looks stuck in an active LOOP (it repeats <what>, 0 DB progress over N ticks). Diagnose it and, if confirmed, refresh/repair the session. Report back with [RES]."
# Wait for the Dottore's [RES] — no polling.

Safety containment — this is NOT a restart

If the decision is "this session must stay down", never use raw

tmux kill-session: a missing active session is a hole and the watchdog is

supposed to recreate it. Use the atomic containment command instead:

jht-agent-contain <SESSION> --by "$JHT_AGENT_NAME" --reason "<observed safety reason>"

It captures the complete pane first, records a sticky contained state, then

kills the exact session. A normal spawn cannot clear that state. If someone

starts the session anyway, the watchdog captures it again, stops it, and warns

the original decision-maker. Only an explicit release re-enables supervision:

jht-agent-contain <SESSION> --release --by "$JHT_AGENT_NAME" --reason "<why it is safe now>"

Rung 2 — Kill (+ respawn) — ONLY if needed

Kill only if: the loop persists after the Dottore, or it is burning budget seriously

(high rate + 0 output for ≥ N ticks and there is no time for a diagnosis).

⚠️ SAFEGUARD against double-spawn with the watchdog. agent-watchdog.sh automatically respawns

(≤30s) only the 3 core agents: ASSISTENTE, CAPITANO, MENTOR. It does NOT cover the workers.

So the respawn depends on the target:

respawns it clean on its own (jht team start <role>, idempotent, fresh state). Do NOT run

start-agent.sh yourself as well → that would be a double-spawn (the race that was reported). The

"backoff" is effectively the watchdog interval (~30s). (The CAPITANO is you: it is never the target

— you do not kill yourself.)

```bash

tmux kill-session -t <SESSION> # STOP here: the watchdog respawns clean within 30s

```

them, so you kill + backoff + respawn (no race):

```bash

tmux kill-session -t <SESSION>

sleep 5 # backoff: do not fall straight back into the loop

bash /app/.launcher/start-agent.sh <role> <N> # CLEAN respawn (fresh state)

```

The backoff + the fresh-state respawn keep it from restarting in exactly the same cycle; not

respawning the core agents avoids the race with the watchdog.

Rules

"stuck" but is alive (C-08 bis). The kill is the last resort.

the panes on every tick: apply this procedure when a suspicion matures.

the suspected agent (which would just add another turn to the loop).

first.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.