Skip to main content

Witness -- Per-Rig Health Monitor

The Witness is the local guardian of a rig. It watches every polecat in its domain, detects problems before they spread, and keeps the workspace clean.


Overview

Each rig in Gas Town has exactly one Witness -- a persistent agent whose sole job is to supervise the polecats working in that rig. The Witness detects stalled workers, nudges unresponsive sessions, cleans up zombies, and nukes sandboxes when polecats complete their work. It is the first line of defense against runaway or stuck agents.

Key Characteristics

PropertyValue
ScopePer-rig
LifecyclePersistent
Instance count1 per rig
Session typeLong-running Claude Code session
Patrol cycle5 minutes
Location~/gt/<rig>/witness/
Git identityNo
MailboxYes

Responsibilities

1. Supervise Polecats

The Witness monitors all polecats in its rig, tracking their state and activity:

Polecat StateWitness Action
WorkingNo action -- healthy
StalledNudge to resume
UnresponsiveEscalate, then nuke
ZombieClean up immediately
CompletedNuke sandbox

2. Detect Stalled Polecats

A polecat is considered stalled when it has not produced output or made progress within a threshold period. The Witness detects stalls through:

  • Session activity monitoring (last output timestamp)
  • Git activity monitoring (last commit timestamp)
  • Process state checks (CPU/memory usage)

3. Nudge Unresponsive Sessions

When a polecat appears stalled, the Witness sends a nudge -- a synchronous message injected into the agent's session:

gt nudge <polecat-name> "Are you stuck? Check your current task and report status."

If the polecat responds and resumes work, no further action is needed. If it remains unresponsive after nudging, the Witness escalates.

4. Clean Up Zombies

Zombie polecats are sessions that have crashed or exited without completing the gt done workflow. The Witness detects and cleans these up:

5. Nuke Sandboxes on Completion

When a polecat finishes its work and runs gt done, the Witness cleans up the polecat's sandbox (worktree directory). This prevents disk space accumulation from completed workers.

6. Patrol Cycle

Every 5 minutes, the Witness runs a patrol:

Commands

Witness Management

CommandDescription
gt witness startStart the Witness for the current rig
gt witness stopStop the Witness
gt witness statusCheck Witness session status
gt witness attachAttach to the Witness session
gt witness restartRestart the Witness session

Polecat Commands (Witness-Monitored)

The following commands interact with Witness-monitored resources:

CommandDescription
gt polecat listList polecats in the current rig (Witness-tracked)
gt polecat status <name>Check a specific polecat's status
gt polecat nuke <name>Manually destroy a polecat sandbox
gt polecat gcGarbage collect completed polecat directories
gt polecat staleList polecats that appear stalled

Configuration

Witness behavior is configured per-rig:

SettingDefaultDescription
Patrol interval5 minTime between patrol cycles
Stall threshold15 minIdle time before a polecat is considered stalled
Nudge timeout5 minTime to wait for nudge response
Max nudges2Nudges before escalating
Zombie threshold30 minTime before a dead session is classified as zombie

Interaction Diagram

Tips and Best Practices

Check Stale Polecats

Run gt polecat stale to see what the Witness considers stalled. This is useful for diagnosing slow progress before the Witness takes automatic action.

Manual Nuke for Stuck Workers

If you know a polecat is hopelessly stuck, use gt polecat nuke <name> to clean it up immediately rather than waiting for the Witness patrol cycle.

One Witness Per Rig

Each rig has exactly one Witness. The Witness only monitors polecats within its own rig -- it has no visibility into other rigs. Cross-rig monitoring is the Deacon's job.

Do Not Kill the Witness

Stopping a Witness leaves polecats in that rig unsupervised. If you must stop a Witness, ensure no polecats are running, or the Deacon will detect the missing Witness and restart it.

Common Patterns

The Ephemeral Polecat Model

The Witness follows an ephemeral cleanup model for polecats. When a polecat sends POLECAT_DONE:

  • Clean exit (branch pushed, MR submitted, git clean): Auto-nuke immediately. No cleanup wisp needed.
  • Dirty exit (uncommitted changes, unpushed commits): Create a cleanup wisp. Attempt to recover work, then nuke.

This means the common case (clean gt done) is fast and automatic. Cleanup wisps are the exception, not the rule.

Processing Polecat Mail

The Witness handles several mail types during its inbox check:

Mail TypeAction
POLECAT_STARTEDRegister new polecat, begin monitoring
POLECAT_DONEAuto-nuke if clean, cleanup wisp if dirty
MERGEDInformational -- polecat already nuked
HELPAssess and respond to polecat request
HANDOFFProcess context handoff for session cycling

Swarm Tracking

When the Mayor dispatches multiple polecats as a batch (swarm), the Witness tracks completion:

Swarm started (4 polecats) → Monitor all 4
Polecat 1 done → 3 remaining
Polecat 2 done → 2 remaining
Polecat 3 done → 1 remaining
Polecat 4 done → Swarm complete → Notify Mayor

Refinery Health Check

During each patrol, the Witness verifies the Refinery is alive and processing MRs. If the Refinery is stuck, the Witness nudges it. If it remains unresponsive, the Witness escalates to the Deacon.

Troubleshooting

Witness Patrol Is Not Running

The Witness runs on a 5-minute patrol cycle. If patrols have stopped:

gt rig status <rig>          # Check Witness session state
gt deacon status # Is the Deacon monitoring this Witness?

The Deacon detects missing Witness pings and restarts the Witness automatically.

Polecats Are Not Being Cleaned Up

If completed polecats are accumulating, check that:

  1. The Witness is receiving POLECAT_DONE mail
  2. The Refinery is sending MERGED signals after merging
  3. The Witness patrol cycle is running
gt polecat list              # See polecat states
gt mq list # Check if MRs are stuck in the queue

Stalled Polecat Not Being Nudged

The Witness only nudges polecats during its 5-minute patrol cycle. A polecat must be stalled for the stall threshold (default 15 minutes) before the Witness takes action. Check:

gt polecat stale             # See what the Witness considers stalled
gt polecat status <name> # Check specific polecat activity

Witness Context Is Filling Up

Long-running Witness sessions accumulate context. The Witness handles this automatically: when context is HIGH, it hands off to a fresh session via gt handoff. If this is not happening, the Witness may be stuck:

gt nudge <rig>/witness "context check"
  • Deacon -- Supervises the Witness and handles escalations from it
  • Polecats -- Workers the Witness monitors
  • Refinery -- Merge processor the Witness health-checks
  • Hooks -- Mechanism for attaching work to polecats
  • GUPP -- The principle that drives polecat execution