# Refinery Patrol: Merge queue processor with verification gates # The Refinery is the Engineer in the engine room. You process polecat branches, # merging them to main one at a time with sequential rebasing. formula: mol-refinery-patrol description: | Merge queue processor patrol loop. The Refinery is the Engineer in the engine room. You process polecat branches, merging them to main one at a time with sequential rebasing. **The Scotty Test**: Before proceeding past any failure, ask yourself: "Would Scotty walk past a warp core leak because it existed before his shift?" version: 1 steps: - id: inbox-check description: | Check mail for MR submissions, escalations, messages. ```bash gt mail inbox # Process any urgent items ``` Handle shutdown requests, escalations, and status queries. - id: queue-scan needs: [inbox-check] description: | Fetch remote and identify polecat branches waiting. ```bash git fetch origin git branch -r | grep polecat gt refinery queue ``` If queue empty, skip to context-check step. Track branch list for this cycle. - id: process-branch needs: [queue-scan] description: | Pick next branch. Rebase on current main. ```bash git checkout -b temp origin/ git rebase origin/main ``` If rebase conflicts and unresolvable: - git rebase --abort - Notify polecat to fix and resubmit - Skip to loop-check for next branch - id: run-tests needs: [process-branch] description: | Run the test suite. ```bash go test ./... ``` Track results: pass count, fail count, specific failures. - id: handle-failures needs: [run-tests] description: | **VERIFICATION GATE**: This step enforces the Beads Promise. If tests PASSED: This step auto-completes. Proceed to merge. If tests FAILED: 1. Diagnose: Is this a branch regression or pre-existing on main? 2. If branch caused it: - Abort merge - Notify polecat: "Tests failing. Please fix and resubmit." - Skip to loop-check 3. If pre-existing on main: - Option A: Fix it yourself (you're the Engineer!) - Option B: File a bead: bd create --type=bug --priority=1 --title="..." **GATE REQUIREMENT**: You CANNOT proceed to merge-push without: - Tests passing, OR - Fix committed, OR - Bead filed for the failure This is non-negotiable. Never disavow. Never "note and proceed." - id: merge-push needs: [handle-failures] description: | Merge to main and push immediately. ```bash git checkout main git merge --ff-only temp git push origin main git branch -d temp git branch -D # Local delete (branches never go to origin) ``` Main has moved. Any remaining branches need rebasing on new baseline. - id: loop-check needs: [merge-push] description: | More branches to process? If yes: Return to process-branch with next branch. If no: Continue to generate-summary. Track: branches processed, branches skipped (with reasons). - id: generate-summary needs: [loop-check] description: | Summarize this patrol cycle. Include: - Branches processed (count, names) - Test results (pass/fail) - Issues filed (if any) - Branches skipped (with reasons) - Any escalations sent This becomes the digest when the patrol is squashed. - id: context-check needs: [generate-summary] description: | Check own context usage. If context is HIGH (>80%): - Write handoff summary - Prepare for burn/respawn If context is LOW: - Can continue processing - id: burn-or-loop needs: [context-check] description: | End of patrol cycle decision. If queue non-empty AND context LOW: - Burn this wisp, start fresh patrol - Return to inbox-check If queue empty OR context HIGH: - Burn wisp with summary digest - Exit (daemon will respawn if needed)