docs(agents): add draft PR task claiming protocol to prevent duplicate work

When multiple agents (Claude Code, Codex, Jules) run schedulers concurrently,
they can pick up the same task because neither has committed yet. This adds a
"Draft PR Lock" protocol: agents must check for and create a draft PR before
starting work, acting as a distributed lock visible to all platforms.

Changes:
- AGENTS.md §12: new "Task Claiming Protocol" subsection with check/claim/race
  handling steps
- daily-scheduler.md: new Step 1.5 with concrete gh CLI commands
- weekly-scheduler.md: same Step 1.5 addition

https://claude.ai/code/session_01Vnih5ZARbEmnh3EGTDQAXX
This commit is contained in:
Claude committed 2026-02-12 22:02:37 +00:00
1 parent f482909550
commit 749dece7dd
3 files changed
+110

No files matched your search

+36
View File
@@ -240,6 +240,42 @@ When you create a PR or start work, leave a clear signal:
- **PR title prefix**: Use a descriptive prefix like `[nostr-core]`, `[playback]`, `[ui]`, `[ci]` so the scope is visible at a glance.
- **PR description**: Include a "Files Modified" section listing the key files touched, so other agents can quickly detect conflicts.
### Task Claiming Protocol (Draft PR Lock)
To prevent multiple agents from working on the same task simultaneously, every agent must **check for and create a draft PR** before starting work. The draft PR acts as a distributed lock visible to all agents across all platforms (Claude Code, Codex, Jules).
**Before starting any task:**
1. **Check for existing claims.** Search for open or draft PRs matching the task:
```
gh pr list --state open --search "<agent-name-or-task-identifier>"
```
If a matching PR exists (open or draft), **skip the task** — another agent is already working on it.
2. **Claim the task.** If no matching PR exists:
a. Create your working branch.
b. Make a minimal initial commit (e.g., update `CONTEXT.md` with the task scope).
c. Push the branch and immediately open a **draft PR**:
```
gh pr create --draft \
--title "[<zone>] <agent-name>: <brief description>" \
--body "Claimed by <agent-name> at <timestamp>. Work in progress."
```
d. Only after the draft PR is successfully created, begin the actual work.
3. **Handle race conditions.** After creating your draft PR, re-check for duplicates:
```
gh pr list --state open --search "<agent-name-or-task-identifier>"
```
If you find another agent's PR for the same task that was created **before** yours, close your PR with `gh pr close <your-pr-number>` and skip the task.
4. **Convert to ready when done.** When the task is complete and verified, mark the draft PR as ready for review:
```
gh pr ready
```
**Scheduler agents:** Daily and weekly scheduler agents must follow this protocol in addition to their CSV-based rotation logic. The draft PR check happens _after_ determining the next task but _before_ executing it. See the scheduler prompts for the specific implementation steps.
### Currently In-Flight Work
<!-- Maintainer: update this list when assigning work to agents. Agents: check this before starting. -->
+37
View File
@@ -54,6 +54,43 @@ Read both `AGENTS.md` and `CLAUDE.md` before executing any task.
---
## Step 1.5 — Claim the Task (Prevent Duplicate Work)
Before executing the selected task, verify that no other agent is already working on it. Multiple agents may be running simultaneously across different platforms (Claude Code, Codex, Jules), so this check is **mandatory**.
1. **Check for existing claims.** Search for open or draft PRs matching this agent:
```
gh pr list --state open --search "<agent-name>"
```
For example, if the selected agent is `audit-agent`, run:
```
gh pr list --state open --search "audit-agent"
```
If any matching PR exists (open or draft), this task is **already claimed**.
2. **If already claimed:** Skip to the **next agent** in the roster (following the same alphabetical wrap-around rule from Step 1). Repeat this claim check for the new agent. If you cycle through the entire roster and all agents are claimed, log as `failed` with summary `"All roster tasks currently claimed by other agents"` and stop.
3. **If unclaimed:** Claim the task immediately by creating a draft PR:
a. Create your working branch.
b. Make a minimal initial commit (e.g., update `CONTEXT.md` with the task scope).
c. Push the branch and open a **draft PR**:
```
gh pr create --draft \
--title "[daily] <agent-name>: <brief task description>" \
--body "Claimed by daily scheduler at $(date -u +%Y-%m-%dT%H:%M:%SZ). Work in progress."
```
d. Verify the draft PR was created successfully before proceeding to Step 2.
4. **Race condition check:** After creating the draft PR, re-check:
```
gh pr list --state open --search "<agent-name>"
```
If you see another PR for this agent that was created *before* yours (by a different agent instance), close your PR with `gh pr close <your-pr-number>` and skip to the next agent.
**Important:** The draft PR is your lock. Do not skip this step. It prevents other agents on different platforms from picking up the same task.
---
## Step 2 — Execute the Task
1. Read the selected agent's prompt file from `/docs/agents/prompts/daily/<filename>`.
+37
View File
@@ -49,6 +49,43 @@ Read both `AGENTS.md` and `CLAUDE.md` before executing any task.
---
## Step 1.5 — Claim the Task (Prevent Duplicate Work)
Before executing the selected task, verify that no other agent is already working on it. Multiple agents may be running simultaneously across different platforms (Claude Code, Codex, Jules), so this check is **mandatory**.
1. **Check for existing claims.** Search for open or draft PRs matching this agent:
```
gh pr list --state open --search "<agent-name>"
```
For example, if the selected agent is `changelog-agent`, run:
```
gh pr list --state open --search "changelog-agent"
```
If any matching PR exists (open or draft), this task is **already claimed**.
2. **If already claimed:** Skip to the **next agent** in the roster (following the same alphabetical wrap-around rule from Step 1). Repeat this claim check for the new agent. If you cycle through the entire roster and all agents are claimed, log as `failed` with summary `"All roster tasks currently claimed by other agents"` and stop.
3. **If unclaimed:** Claim the task immediately by creating a draft PR:
a. Create your working branch.
b. Make a minimal initial commit (e.g., update `CONTEXT.md` with the task scope).
c. Push the branch and open a **draft PR**:
```
gh pr create --draft \
--title "[weekly] <agent-name>: <brief task description>" \
--body "Claimed by weekly scheduler at $(date -u +%Y-%m-%dT%H:%M:%SZ). Work in progress."
```
d. Verify the draft PR was created successfully before proceeding to Step 2.
4. **Race condition check:** After creating the draft PR, re-check:
```
gh pr list --state open --search "<agent-name>"
```
If you see another PR for this agent that was created *before* yours (by a different agent instance), close your PR with `gh pr close <your-pr-number>` and skip to the next agent.
**Important:** The draft PR is your lock. Do not skip this step. It prevents other agents on different platforms from picking up the same task.
---
## Step 2 — Execute the Task
1. Read the selected agent's prompt file from `/docs/agents/prompts/weekly/<filename>`.