#4630·gastown

AutoClose omits gt:agent from its protected-label list: agent registry beads are auto-closed on a 7-day updated_at clock that heartbeats do not reset

Author: blairsilverbergCreated Aug 1, 2026Updated Sep 25, 2026
Labelsstatus/needs-triage

Summary

AutoClose's protected-label list does not contain gt:agent — the label that defines an agent registry bead. Every agent registry bead is therefore an auto-close candidate on a 7-day updated_at clock, and heartbeats do not reset that clock because they write to the labels table and never touch issues.updated_at.

In our deployment this silently closed 5 agent registry beads at 13–15 days stale before anyone noticed.

All source references below were read from main at the time of filing (raw.githubusercontent.com, HTTP 200), not inferred from behaviour.

The predicate

internal/reaper/reaper.go, AutoClose:

i.status IN ('open','in_progress')
AND i.updated_at < NOW() - <staleAge>
AND i.priority > 1                       -- P0/P1 exempt
AND i.issue_type NOT IN ('epic','convoy')
AND i.id NOT IN (SELECT ... FROM labels l
                 WHERE l.label IN ('gt:standing-orders', 'gt:keep', 'gt:role', 'gt:rig'))
AND <no open dependency in either direction>
  • internal/reaper/reaper.go:741 — the four-label list above.
  • internal/daemon/wisp_reaper.go:30 — defaultStaleIssueAge = 7 * 24 * time.Hour, passed at wisp_reaper.go:310.
  • grep -c 'gt:agent' internal/reaper/reaper.go → 0. Positive control in the same run: grep -c 'gt:keep' → 1, so the probe can express presence.

The same four labels are duplicated in internal/beads/beads.go:295, ProtectedIssueLabel:

go
func ProtectedIssueLabel(label string) bool {
	switch strings.ToLower(strings.TrimSpace(label)) {
	case "gt:standing-orders", "gt:keep", "gt:role", "gt:rig":
		return true
	default:
		return false
	}
}

which is what IsProtectedBead (beads.go:338) delegates to, and which documents itself as guarding "AutoClose, unassign on polecat removal, etc."

Meanwhile IsAgentBead (beads.go:323) identifies agent beads primarily by the label:

go
func IsAgentBead(issue *Issue) bool {
	if issue == nil {
		return false
	}
	// Check legacy type field first for backward compatibility
	if issue.Type == "agent" {
		return true
	}
	// Check for gt:agent label (current standard)
	return HasLabel(issue, "gt:agent")
}

So the codebase has one concept of "this is an agent bead" and a second, disjoint concept of "this bead is protected", and agent beads are absent from the second.

Why heartbeats don't save them

Heartbeats write heartbeat:<epoch> / idle:<n> rows into the labels table. They never write a column on issues, so updated_at reflects only real column writes and a continuously-live agent can look arbitrarily stale to the reaper.

Demonstrated from a single AutoClose batch in our deployment, two independent instances, no waiting required:

registry bead heartbeat label last written outcome
op-openclaw-witness 2 days before the batch closed
cap-capital-witness 5 days before the batch closed

If heartbeat writes touched updated_at, neither could have satisfied updated_at < NOW() - 7d. Both did.

The two survivors in that batch are also explained by updated_at alone: one was the only registry bead carrying notes (i.e. real column writes), the other was created inside the 7-day window. Note for anyone reproducing this: started_at is a correlate, not a cause — it appears nowhere in the predicate. A started bead gets worked, and being worked bumps updated_at. We initially mis-attributed the survivorship to started_at and it does not hold up.

Impact

Beyond losing the registry row: gt agents resolve matches only open beads. When a registry bead closes, resolution returns null, the patrol loop-or-exit step loses its idle signal, and the patrol runs at full effort instead of backing off — for every affected role in every rig. That is a recurring token-cost multiplier with no visible cause, which is why we'd rate this above a tidiness bug.

Population in our (single) deployment: 60 gt:agent beads, none carrying any protected label before we intervened; 5 already closed; a further ~39 within 1–2 days of the line.

Prior art, and why the earlier approach would not work today

PRs #3848 / #3849 ("fix: exclude agent beads from AutoClose to prevent polecat state deletion") targeted this exact function and failure class and were both closed unmerged. They fixed it with a type predicate, i.issue_type != 'agent'.

That predicate would be a no-op on current main: per IsAgentBead above, the type field is explicitly "legacy … for backward compatibility" and the gt:agent label is "current standard", so a type filter no longer matches a newly-created agent bead. We mention this only so the earlier attempt isn't revived as-is.

Possibly related, not duplicates as far as we can tell: #4397, #4535, #4513 (closed by #4530), #1035.

Suggested fix

Add 'gt:agent' to both copies of the protected-label list:

  • internal/reaper/reaper.go:741 — the AutoClose whereClause label list
  • internal/beads/beads.go:295 — ProtectedIssueLabel

Separately worth considering, but a wider behaviour change that we'd suggest not bundling: whether a heartbeat should touch issues.updated_at. That arguably fixes the root cause rather than the symptom, but it changes staleness semantics for everything that reads updated_at.

Suggested acceptance test

A stored count won't work here, because the population moves — "the registry is all open" passes on a broken guard. We'd suggest a two-arm behavioural test in one run:

  • a freshly created gt:agent bead with no gt:keep label and updated_at forced past the stale cutoff is refused by AutoClose; and
  • a non-agent P2 bead of the same age in the same run is taken.

A guard that cannot say SAFE isn't a guard; a guard that cannot say TAKEN isn't being exercised.

Workaround for anyone hitting this now

Add gt:keep to existing gt:agent beads. Two caveats: the label write itself bumps updated_at, which destroys the staleness evidence the diagnosis rests on (snapshot first if you want to confirm), and beads created afterwards are unprotected from birth.