Worker loop

From fritzprix/libr-agent · View interactive version

Worker loop is an AI agent skill from the GitHub repository fritzprix/libr-agent. Autonomous worker loop for LibrAgent. Each tick fixes open PRs that need action; if PRs require no action (even while waiting for CI or gatekeeper approval), continuously implements remaining `approved` issues in one PR as long as any remain. Never merges. Use when the user types "/worker-loop", "/w

How to use this skill

Skill file

Worker Loop

The approved label is the only approval. Do the whole issue, including src-tauri/ and .github/workflows/. Do not look for other approval.

[!IMPORTANT]

Keep working on remaining issues when PRs need no action:

Even if open PRs are pending CI runs, waiting for Gatekeeper review/approval, or awaiting maintainer escalation, they require no immediate worker action. Never idle, stall, or stop the loop while actionable approved issues remain. The worker MUST proceed directly to Step 4 and implement the next available issue.

Commands

| Command | Behavior |

| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| /worker-loop | Run one tick. |

| /worker-loop 10m | Arm a recurring tick (see references/scheduling.md), then run one tick. |

| /worker-loop status | Print scripts/worker_state.py status (every worker and schedule; orphaned lists slots whose run died with current work), then the open owner questions: gh issue list --label needs-owner and gh pr list --label needs-owner. Do no work. |

| /worker-loop stop | Disarm every recurring tick listed by worker_state.py scheduler clear. |

Setup

Three separate things, which fail separately:

| Concept | Answers | Lives in | Conflict means |

| ----------- | ------------------------------------------------- | ------------------------------------ | ----------------------------------------- |

| Worker slot | Who owns worker, worker-2, … and its worktree | checkins.json, worker_slots.py | BUSY reason=slot-held or no-free-slot |

| Tick lock | Is a tick running in this slot | <worker>/tick.lock, tick_lock.py | BUSY reason=lock-held |

| Item claim | Which issue or PR a worker is on | claims.json, worker_claims.py | claim exit 1 |

Read the printed reason. BUSY reason=same-session means this session already has a tick, not that another worker exists. A claim conflict names one item's holder and says nothing else about that worker.

LR means python3 .agents/skills/worker-loop/scripts/lease_run.py --worker NAME --token TOKEN --. It checks the lease before starting, renews it during the command, and terminates the command if the lease is lost.

Local validation

Before you push, run the checks that cover your change, from $WT, each through LR. CI runs the whole suite on the PR, so do not repeat all of it locally. Choose the checks with references/verification.md:

All the checks you chose must pass before you push. In the PR test plan, list what you ran, and list what you left to CI.

Rust builds take a machine-wide slot, so a command may wait behind another worktree's build; that is normal. Never run raw cargo test/build/clippy: it skips that limit. Never run bare pnpm test (it starts watch mode) — use pnpm vitest run. pnpm audit is advisory in CI (continue-on-error): do not run it for a change that leaves dependencies alone.

[!CAUTION]

Skipped local checks do not waive CI ownership — see Tick step 3 CI failed.

Tick

  1. python3 .agents/skills/worker-loop/scripts/tick_gate.py --lock
  1. git -C "$MAIN" fetch origin --prune. If current is set, continue it: in $WT, LR git rebase origin/<base> before you push or open its PR (the base may have moved since the work started). Else python3 .agents/skills/worker-loop/scripts/worker_worktree.py reset --worker NAME --token TOKEN --wt "$WT". Never run reset --hard or clean yourself. RESCUED <sha> means an earlier run's uncommitted changes were saved in a stash; mention it in your report.
  1. Fix PRs first. Run scripts/pr_status.py --worker NAME. Ignore drafts and PRs claimed by other workers. Take the first PR that needs action and claim pr:M. Then get its head branch with worker_worktree.py switch --worker NAME --token TOKEN --wt "$WT" --branch <head>: BRANCH BUSY means another run needs it, so release the claim and take the next PR; DETACHED prints the push command to use; SWITCHED with unpushed commits saved at <ref> means the local branch was reset to the remote and its old commits are at that ref, so mention it in your report. Commit and push only through LR. On the head branch:

When no PR needs action:

If every open PR has nextAction wait-gatekeeper, wait-human, wait-owner, wait-ci, or none (use each entry's turnReport), do NOT idle before step 4. As long as approved issues remain, implement the next issue.

_(Only skip directly to step 6 if a PR was fixed and pushed in this tick, respecting the one-push-per-tick rule, or if no candidate issues exist.)_

  1. Else pick an issue (continue work on remaining issues). Run scripts/issue_candidates.py --worker NAME. Whenever no PR required fixes in step 3, you MUST proceed here as long as any candidate issues remain. Take the first candidate you can claim: claim exit 1 means try the next one. Then gh issue edit N --add-assignee @me. If the candidate has ownerAnswer, gh issue edit N --remove-label needs-owner and follow that answer. issue_candidates.py already leaves out issues that wait on the owner (needs-owner without an answer) and issues whose Depends on #X / Blocked by #X is still open (only a plain list such as Depends on #1, #2, and #3 is read; a list stops at the first item that is not #N); list each of the latter in your report as "approved but dependency #X still open", and do not comment or add labels for it. Do not stack PRs.
  2. Implement the whole issue in one PR.
  1. Report with links. Include one turnReport line per open PR. If current is clear, LR git -C "$WT" switch --detach, so the branch is free for other workers. Then unlock:

A wrapper may own the lease for a whole tick: lease_run.py --acquire -- <agent command>. Inside it, --lock reuses the wrapper's lease and --unlock prints LOCK KEPT; run the same commands either way.

Owner questions

GitHub is the record of every question for the owner. Ask only when the issue is unclear, contradicts itself, or a required decision is missing (or for the CI case in step 3). Do not ask because of paths, size, risk, or inability to push directly to dev/* — open a PR targeting the issue's Target branch (or default dev base) instead.

  1. Post one comment on the issue or PR. Start it with <!-- worker-loop: needs-owner -->, with no round= field (so it never counts as a response to a gatekeeper round). Say what is blocked, the question, the options as (a)/(b)/(c), and your recommendation.
  2. gh issue edit N --add-label needs-owner (or gh pr edit M --add-label needs-owner). If GitHub reports that the label does not exist, stop and report it; do not create labels.
  3. Release your claim (worker_state.py release), clear current with worker_state.py clear-current if it was this item, and go to the next item.

The owner and the workers may share one GitHub account. The owner's answer is the first comment after the question that does not start with a worker-loop or gatekeeper-loop marker, written by that account or by a repository owner, member, or collaborator. Until it exists, issue_candidates.py leaves the issue out and pr_status.py reports wait-owner: do not ask again. When it exists, they report it as ownerAnswer: remove the label and follow the answer.

Do not put needs-owner on a PR labelled gatekeeper:escalated; it already waits on the owner. gatekeeper:needs-human is the gatekeeper's request for a human merge review, not an owner question.

Machine safety

The running GUI on the default profile is the user's app (#2824). These rules bind every tick, including smoke and hidden-WebView checks:

  1. Never kill a process this tick did not start. No Stop-Process, taskkill, kill, or pkill selected by the image name libragent or libragent-tui. Cleanup stops only PIDs (and their children) recorded when this tick started them.
  2. Tests use an isolated profile. Set LIBRAGENT_DATA_DIR (and LIBRAGENT_PROFILE / LIBRAGENT_DB_PATH when the test needs them). Do not share the user's database, port file, log, or WebView data. A same-profile coexistence test starts its own GUI; it does not reuse or kill the user's.
  3. When acceptance depends on a defect or design gap outside the issue, stop. File or link the blocker, comment on the issue, release the claim, and take the next item. Do not loop on workarounds.
  4. Readiness comes from a marker written by this run, or from log lines written after the run started. The shared app log is not proof.
  5. Evidence for a specific code path must force that path and assert it. A default path that happens to succeed is not evidence for the path under test.
  6. Prefer a debug or incremental build. Another release rebuild that adds no new information is a stop signal.
  7. An owner stop or no-push note ends that item immediately.

Hard rules

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.