Skip to content

fix(patrol): harden triage feedback loop safeguards#997

Merged
jrf0110 merged 5 commits intomainfrom
965-triage-loop
Mar 11, 2026
Merged

fix(patrol): harden triage feedback loop safeguards#997
jrf0110 merged 5 commits intomainfrom
965-triage-loop

Conversation

@jrf0110
Copy link
Copy Markdown
Contributor

@jrf0110 jrf0110 commented Mar 10, 2026

Summary

Follow-up to #988, which merged the initial triage feedback loop fix. This PR addresses review feedback and additional edge cases found during code review:

  • Batch-bead-based dispatch cooldown: Replaced the ineffective last_activity_at update with a guard that checks for recently-failed gt:triage batch beads (updated_at > cooldownCutoff), giving a real DISPATCH_COOLDOWN_MS backoff between retry attempts.
  • Stable crash-loop exclusion: Fixed detectCrashLoops to use two complementary NOT EXISTS checks — one on the failed bead's labels (stable after unhook) and one on the agent's current hook — preventing both triage batch bead failures and triage resolution actions (e.g. CLOSE_BEAD) from triggering crash-loop detection.
  • Escalation-aware global cap: Exempted escalation-type triage requests from the MAX_OPEN_TRIAGE_REQUESTS gate and count, so escalation backlog doesn't suppress patrol's automatic detections and low-severity escalations always get triage follow-up.
  • Remove triage from public AgentRole enum: The triage role is only a container dispatch-time signal — keeping it in the public enum would let external API callers create agents that skip repo clone.

Verification

  • pnpm typecheck — passes

Visual Changes

N/A

Reviewer Notes

Comment thread cloudflare-gastown/src/dos/Town.do.ts Outdated
Comment thread cloudflare-gastown/src/dos/town/patrol.ts
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Mar 10, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • cloudflare-gastown/src/dos/Town.do.ts
  • cloudflare-gastown/src/dos/town/patrol.ts
  • cloudflare-gastown/src/types.ts

Reviewed by gpt-5.4-20260305 · 809,228 tokens

Comment thread cloudflare-gastown/src/dos/town/patrol.ts Outdated
Comment thread cloudflare-gastown/src/types.ts Outdated
Comment thread cloudflare-gastown/src/dos/town/patrol.ts
Comment thread cloudflare-gastown/src/dos/town/patrol.ts
Comment thread cloudflare-gastown/src/dos/town/patrol.ts
Comment thread cloudflare-gastown/src/types.ts
Comment thread cloudflare-gastown/src/dos/Town.do.ts
jrf0110 added 3 commits March 11, 2026 09:23
…p exclusion

- Replace ineffective last_activity_at cooldown with a batch-bead-based
  cooldown: maybeDispatchTriageAgent now skips dispatch when a failed
  gt:triage batch bead exists within DISPATCH_COOLDOWN_MS.
- Fix crash-loop exclusion to check the failed bead's labels instead of
  current_hook_bead_id (which is NULL after unhook), preventing unhooked
  triage agents from slipping through detection.
Escalations are agent/user-initiated and must not be silently dropped
by the global cap, which exists to prevent feedback loops from patrol's
automatic detections. Without this, low-severity escalations that don't
notify the mayor would sit unprocessed with no triage follow-up.
The triage role is only used as a container dispatch-time signal by
maybeDispatchTriageAgent, not as a user-facing role. Including it in
AgentRole exposed it via the public API (POST /agents, POST
/get-or-create-agent), allowing external callers to create agents that
skip repo clone and cannot work normal coding beads.
… filter

- Exclude escalation-type triage requests from the global cap COUNT
  query so escalation backlog doesn't suppress patrol's automatic
  detections (crash_loop, stuck_agent, etc.).
- Add second NOT EXISTS clause to detectCrashLoops that checks if the
  agent is currently hooked to a triage-labeled bead — covers the case
  where resolveTriage CLOSE_BEAD fails an ordinary bead with the triage
  agent as the actor.
@jrf0110 jrf0110 changed the title fix(patrol): break triage agent feedback loop fix(patrol): harden triage feedback loop safeguards Mar 11, 2026
@jrf0110 jrf0110 enabled auto-merge (squash) March 11, 2026 14:43
@jrf0110 jrf0110 merged commit da92234 into main Mar 11, 2026
18 checks passed
@jrf0110 jrf0110 deleted the 965-triage-loop branch March 11, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants