fix(agents): rewrite scheduler prompts to force pre-flight execution

Agents were skipping the pre-flight curl/gh check for in-progress work,
causing duplicate task runs. Root causes:

1. Two-document indirection (meta prompt → scheduler) caused the pre-flight
   instructions to get lost when the agent opened the second file
2. No proof-of-execution gate — agents could assert "no conflicts" without
   actually running the commands
3. curl|jq pipeline silently fails when jq is unavailable
4. "Step 0" labeling felt like skippable preamble

Changes:
- Make the commands the literal first instruction ("run NOW, paste output")
- Use gh CLI as primary (authenticated, no jq needed), curl as fallback
- Require raw terminal output pasted before proceeding (output gate)
- Rename "Step 0" to "PRE-FLIGHT GATE" to signal it's not optional
- Eliminate duplication between meta prompt and scheduler files
- Add explicit "STOP HERE" checkpoint after command execution
- Add skip-ahead clause for agents arriving from meta prompt

https://claude.ai/code/session_01S7jaQb9ctJ4bzqRhEcm28Q
This commit is contained in:
Claude committed 2026-02-13 05:21:25 +00:00
1 parent fcf7fef058
commit f794971bfc
3 files changed
+149 -109

No files matched your search

+73 -61
View File
@@ -1,6 +1,6 @@
# Bitvid Agent Scheduler Meta Prompts
This file contains the authoritative "Meta Prompts" to be used when triggering the daily and weekly agent schedulers. These prompts ensure that the agent correctly follows the scheduler's logic, including the critical task-claiming step to prevent duplicate work.
This file contains the authoritative "Meta Prompts" to be used when triggering the daily and weekly agent schedulers. Copy-paste the relevant prompt below into the agent session.
---
@@ -9,42 +9,48 @@ This file contains the authoritative "Meta Prompts" to be used when triggering t
```text
You are the bitvid daily agent scheduler.
CRITICAL — DUPLICATE WORK PREVENTION:
Before doing ANYTHING else, you MUST check what work is already in progress.
Agents that skip this check cause the same task to run repeatedly, wasting
entire runs. This has happened before. Do not let it happen again.
YOUR VERY FIRST ACTION — before reading any file, before planning anything,
before choosing a task — is to run these two commands. Not later. NOW.
Follow these steps IN ORDER. Do not skip or reorder any step.
COMMAND 1 — Check for open daily agent PRs:
STEP 0 — PRE-FLIGHT SCAN (do this FIRST, before choosing a task):
a) Run: curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq -c '.[] | select(.title | contains("[daily]")) | {number: .number, title: .title, created_at: .created_at, author: .user.login, url: .html_url}'
Record ALL open daily PRs. Every agent name in those titles is OFF LIMITS.
IMPORTANT: this query intentionally filters to titles containing "[daily]". It will NOT list unrelated open PRs.
(Optional visibility check) If you need total open PR context, run a second command without the filter.
b) Run: ls docs/agents/task-logs/daily/ | sort
Look for any "_started.md" files that do NOT have a corresponding
"_completed.md" or "_failed.md" file from the same agent at a later
timestamp. Those agents are OFF LIMITS (unless the started file is >24h old).
c) Write down your exclusion list before proceeding.
If the `curl` command fails, you MUST still check the task log directory.
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt,author --limit 100 | grep -i "\[daily\]"
STEP 1 — Read `AGENTS.md` and `CLAUDE.md` for project rules.
If `gh` is not available, use this fallback:
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | grep -o '"title":"[^"]*\[daily\][^"]*"'
STEP 2 — Read `docs/agents/prompts/daily-scheduler.md` and follow its
instructions completely, starting from Step 1 (Determine the Next Task).
You already completed Step 0 above — use the exclusion list you built.
- When selecting the next agent, SKIP any agent on your exclusion list.
- Before executing: create a draft PR claim AND create a "started" log file
in docs/agents/task-logs/daily/.
- These two actions MUST happen before any task execution begins.
COMMAND 2 — Check for in-progress task logs:
STEP 3 — Once the task is claimed and executed:
- Create a new "completed" or "failed" log file in docs/agents/task-logs/daily/.
- Do NOT modify the "started" file — always create a new file.
- Commit and push your changes.
ls docs/agents/task-logs/daily/ | sort
REMEMBER: The #1 failure mode is agents not checking for in-progress work
and re-running the same task. Your pre-flight scan in Step 0 prevents this.
Run both commands and PASTE THE COMPLETE RAW OUTPUT of each command into your
response. Do not summarize. Do not paraphrase. Paste the actual terminal output.
If a command returns nothing, write: "OUTPUT: (empty — no results)"
STOP HERE. Do not proceed until both outputs are pasted.
---
Now analyze the output:
- Any agent name that appears in an open PR title is EXCLUDED.
- Any agent with a "_started.md" log file that has no matching "_completed.md"
or "_failed.md" from the same agent at a later timestamp is EXCLUDED
(unless the started file is more than 24 hours old).
- Write your exclusion list. Format: "EXCLUDED AGENTS: agent-a, agent-b"
or "EXCLUDED AGENTS: (none)"
---
Now proceed with the scheduler:
1. Read `AGENTS.md` and `CLAUDE.md` for project rules.
2. Read `docs/agents/prompts/daily-scheduler.md` and follow its instructions
starting from "Step 1 — Determine the Next Task." You already completed
the pre-flight gate above — use your exclusion list when selecting an agent.
3. Before executing any task: create a draft PR claim AND a "started" log file
in docs/agents/task-logs/daily/. Both MUST exist before task execution begins.
4. After execution: create a "completed" or "failed" log file (new file, never
modify the "started" file). Commit and push.
```
## Weekly Scheduler Meta Prompt
@@ -52,40 +58,46 @@ and re-running the same task. Your pre-flight scan in Step 0 prevents this.
```text
You are the bitvid weekly agent scheduler.
CRITICAL — DUPLICATE WORK PREVENTION:
Before doing ANYTHING else, you MUST check what work is already in progress.
Agents that skip this check cause the same task to run repeatedly, wasting
entire runs. This has happened before. Do not let it happen again.
YOUR VERY FIRST ACTION — before reading any file, before planning anything,
before choosing a task — is to run these two commands. Not later. NOW.
Follow these steps IN ORDER. Do not skip or reorder any step.
COMMAND 1 — Check for open weekly agent PRs:
STEP 0 — PRE-FLIGHT SCAN (do this FIRST, before choosing a task):
a) Run: curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq -c '.[] | select(.title | contains("[weekly]")) | {number: .number, title: .title, created_at: .created_at, author: .user.login, url: .html_url}'
Record ALL open weekly PRs. Every agent name in those titles is OFF LIMITS.
IMPORTANT: this query intentionally filters to titles containing "[weekly]". It will NOT list unrelated open PRs.
(Optional visibility check) If you need total open PR context, run a second command without the filter.
b) Run: ls docs/agents/task-logs/weekly/ | sort
Look for any "_started.md" files that do NOT have a corresponding
"_completed.md" or "_failed.md" file from the same agent at a later
timestamp. Those agents are OFF LIMITS (unless the started file is >24h old).
c) Write down your exclusion list before proceeding.
If the `curl` command fails, you MUST still check the task log directory.
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt,author --limit 100 | grep -i "\[weekly\]"
STEP 1 — Read `AGENTS.md` and `CLAUDE.md` for project rules.
If `gh` is not available, use this fallback:
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | grep -o '"title":"[^"]*\[weekly\][^"]*"'
STEP 2 — Read `docs/agents/prompts/weekly-scheduler.md` and follow its
instructions completely, starting from Step 1 (Determine the Next Task).
You already completed Step 0 above — use the exclusion list you built.
- When selecting the next agent, SKIP any agent on your exclusion list.
- Before executing: create a draft PR claim AND create a "started" log file
in docs/agents/task-logs/weekly/.
- These two actions MUST happen before any task execution begins.
COMMAND 2 — Check for in-progress task logs:
STEP 3 — Once the task is claimed and executed:
- Create a new "completed" or "failed" log file in docs/agents/task-logs/weekly/.
- Do NOT modify the "started" file — always create a new file.
- Commit and push your changes.
ls docs/agents/task-logs/weekly/ | sort
REMEMBER: The #1 failure mode is agents not checking for in-progress work
and re-running the same task. Your pre-flight scan in Step 0 prevents this.
Run both commands and PASTE THE COMPLETE RAW OUTPUT of each command into your
response. Do not summarize. Do not paraphrase. Paste the actual terminal output.
If a command returns nothing, write: "OUTPUT: (empty — no results)"
STOP HERE. Do not proceed until both outputs are pasted.
---
Now analyze the output:
- Any agent name that appears in an open PR title is EXCLUDED.
- Any agent with a "_started.md" log file that has no matching "_completed.md"
or "_failed.md" from the same agent at a later timestamp is EXCLUDED
(unless the started file is more than 24 hours old).
- Write your exclusion list. Format: "EXCLUDED AGENTS: agent-a, agent-b"
or "EXCLUDED AGENTS: (none)"
---
Now proceed with the scheduler:
1. Read `AGENTS.md` and `CLAUDE.md` for project rules.
2. Read `docs/agents/prompts/weekly-scheduler.md` and follow its instructions
starting from "Step 1 — Determine the Next Task." You already completed
the pre-flight gate above — use your exclusion list when selecting an agent.
3. Before executing any task: create a draft PR claim AND a "started" log file
in docs/agents/task-logs/weekly/. Both MUST exist before task execution begins.
4. After execution: create a "completed" or "failed" log file (new file, never
modify the "started" file). Commit and push.
```
+38 -24
View File
@@ -64,45 +64,59 @@ To find all entries for a specific agent:
ls docs/agents/task-logs/daily/ | grep "<agent-name>"
```
To check for in-progress (`started`) entries without a matching `completed`/`failed`:
```bash
ls docs/agents/task-logs/daily/ | grep "_started.md"
```
Then verify each `started` file has a corresponding `completed` or `failed` file from the same agent at a later timestamp. If not, that agent is still in progress.
---
## Step 0 — Pre-Flight: Scan ALL In-Flight Work (MANDATORY)
## PRE-FLIGHT GATE — Run These Commands NOW
> **DO NOT SKIP THIS STEP. This is the single most important step in the entire scheduler. If you skip this, you will cause duplicate work and waste an entire agent run.**
> **This gate is NOT optional. You MUST run both commands below and paste their raw output before doing anything else. If you skip this, you will duplicate another agent's work and waste the entire run. This has happened repeatedly.**
Before determining which agent to run, you MUST build situational awareness of what is already in progress. Run these commands and record the results:
If you arrived here from the meta prompt and already ran these commands and pasted the output, you may skip ahead to Step 1. Otherwise:
### 0a. List ALL open daily agent PRs
### COMMAND 1 — Check for open daily agent PRs
Run this command:
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq -c '.[] | select(.title | contains("[daily]")) | {number: .number, title: .title, created_at: .created_at, author: .user.login}'
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt,author --limit 100 | grep -i "\[daily\]"
```
Record every open PR. These represent **active claims by other agents**. Any agent whose name appears in these PR titles is OFF LIMITS.
If `gh` is unavailable, use this fallback:
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | grep -o '"title":"[^"]*\[daily\][^"]*"'
```
### 0b. Check the task log for incomplete runs
**Paste the complete raw output.** If the command returns nothing, write: `OUTPUT: (empty — no results)`
Every agent name that appears in these PR titles is **OFF LIMITS** — do not select it.
### COMMAND 2 — Check the task log for incomplete runs
Run this command:
```bash
ls docs/agents/task-logs/daily/ | sort
```
Look for any `_started.md` files that do NOT have a corresponding `_completed.md` or `_failed.md` file from the same agent at a later timestamp. These represent agents that began work but haven't finished. Treat them the same as open PRs: those agents are OFF LIMITS unless the `started` entry is **older than 24 hours** (stale/abandoned — check the date in the filename).
**Paste the complete raw output.**
### 0c. Build your exclusion list
Look for any `_started.md` files that do NOT have a corresponding `_completed.md` or `_failed.md` file from the same agent at a later timestamp. Those agents are **OFF LIMITS** (unless the started file is more than 24 hours old — check the date in the filename).
Combine the results from 0a and 0b into an explicit exclusion list:
### Build your exclusion list
Combine results from Commands 1 and 2:
- Agents with open/draft PRs → EXCLUDED
- Agents with `started` status less than 24 hours old (no matching `completed`/`failed`) → EXCLUDED
Write this exclusion list down before proceeding. You will reference it in Step 1.
Write your exclusion list explicitly:
```
EXCLUDED AGENTS: agent-a, agent-b
```
or:
```
EXCLUDED AGENTS: (none)
```
**If the `curl` command fails** (e.g., network error, API limit): You MUST still check the task log directory for `started` entries. Log a warning in your summary that PR-based claim checking was unavailable.
**If Command 1 failed** (network error, API limit, `gh`/`curl` unavailable): you MUST still check the task log directory (Command 2). Log a warning in your summary that PR-based claim checking was unavailable.
**Do not proceed to Step 1 until you have pasted command outputs and written your exclusion list.**
---
@@ -114,7 +128,7 @@ Write this exclusion list down before proceeding. You will reference it in Step
4. Look up that agent in the alphabetical roster below and select the **next agent** in the list.
5. If the most recent agent is the **last** in the roster, wrap around to the **first**.
6. If the directory is empty, start with the **first** agent in the roster.
7. **CHECK YOUR EXCLUSION LIST FROM STEP 0.** If the selected agent is on the exclusion list, skip to the next agent in the roster. Repeat until you find an agent that is NOT excluded. If you cycle through the entire roster and ALL agents are excluded, log as `failed` with summary `"All roster tasks currently claimed by other agents"` and stop.
7. **CHECK YOUR EXCLUSION LIST.** If the selected agent is on the exclusion list, skip to the next agent in the roster. Repeat until you find an agent that is NOT excluded. If you cycle through the entire roster and ALL agents are excluded, log as `failed` with summary `"All roster tasks currently claimed by other agents"` and stop.
### Agent Roster (alphabetical order)
@@ -166,13 +180,13 @@ You must create a visible claim before doing any work. This claim is a **distrib
After creating the draft PR, immediately re-check:
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq -c '.[] | select(.title | contains("[daily] <agent-name>")) | {number: .number, title: .title, created_at: .created_at}'
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt --limit 100 | grep -i "<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>` (if `gh` works) and go back to Step 1 to select the next agent.
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 go back to Step 1 to select the next agent.
### 2c. Log "started" in the task log immediately
> **This is critical.** Create a `started` log file NOW, before executing the task. This ensures the rotation advances even if you crash during execution.
> **Create a `started` log file NOW, before executing the task. This ensures the rotation advances even if you crash during execution.**
Create a new file in `docs/agents/task-logs/daily/` with this naming pattern:
@@ -273,8 +287,8 @@ Use the current UTC timestamp (which will be later than the `started` file). The
| Layer | Mechanism | Catches |
|-------|-----------|---------|
| **Step 0** | Scan ALL open `[daily]` PRs | Agents claimed by any platform |
| **Step 0** | Check task log dir for `started` files | Agents in progress (even without PR) |
| **Pre-flight gate** | Scan ALL open `[daily]` PRs via `gh`/`curl` | Agents claimed by any platform |
| **Pre-flight gate** | Check task log dir for `started` files | Agents in progress (even without PR) |
| **Step 2a** | Create draft PR as lock | Cross-platform visibility |
| **Step 2b** | Race condition re-check | Simultaneous claims |
| **Step 2c** | Create `started` log file immediately | Crash recovery — rotation advances |
+38 -24
View File
@@ -64,45 +64,59 @@ To find all entries for a specific agent:
ls docs/agents/task-logs/weekly/ | grep "<agent-name>"
```
To check for in-progress (`started`) entries without a matching `completed`/`failed`:
```bash
ls docs/agents/task-logs/weekly/ | grep "_started.md"
```
Then verify each `started` file has a corresponding `completed` or `failed` file from the same agent at a later timestamp. If not, that agent is still in progress.
---
## Step 0 — Pre-Flight: Scan ALL In-Flight Work (MANDATORY)
## PRE-FLIGHT GATE — Run These Commands NOW
> **DO NOT SKIP THIS STEP. This is the single most important step in the entire scheduler. If you skip this, you will cause duplicate work and waste an entire agent run.**
> **This gate is NOT optional. You MUST run both commands below and paste their raw output before doing anything else. If you skip this, you will duplicate another agent's work and waste the entire run. This has happened repeatedly.**
Before determining which agent to run, you MUST build situational awareness of what is already in progress. Run these commands and record the results:
If you arrived here from the meta prompt and already ran these commands and pasted the output, you may skip ahead to Step 1. Otherwise:
### 0a. List ALL open weekly agent PRs
### COMMAND 1 — Check for open weekly agent PRs
Run this command:
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq -c '.[] | select(.title | contains("[weekly]")) | {number: .number, title: .title, created_at: .created_at, author: .user.login}'
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt,author --limit 100 | grep -i "\[weekly\]"
```
Record every open PR. These represent **active claims by other agents**. Any agent whose name appears in these PR titles is OFF LIMITS.
If `gh` is unavailable, use this fallback:
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | grep -o '"title":"[^"]*\[weekly\][^"]*"'
```
### 0b. Check the task log for incomplete runs
**Paste the complete raw output.** If the command returns nothing, write: `OUTPUT: (empty — no results)`
Every agent name that appears in these PR titles is **OFF LIMITS** — do not select it.
### COMMAND 2 — Check the task log for incomplete runs
Run this command:
```bash
ls docs/agents/task-logs/weekly/ | sort
```
Look for any `_started.md` files that do NOT have a corresponding `_completed.md` or `_failed.md` file from the same agent at a later timestamp. These represent agents that began work but haven't finished. Treat them the same as open PRs: those agents are OFF LIMITS unless the `started` entry is **older than 24 hours** (stale/abandoned — check the date in the filename).
**Paste the complete raw output.**
### 0c. Build your exclusion list
Look for any `_started.md` files that do NOT have a corresponding `_completed.md` or `_failed.md` file from the same agent at a later timestamp. Those agents are **OFF LIMITS** (unless the started file is more than 24 hours old — check the date in the filename).
Combine the results from 0a and 0b into an explicit exclusion list:
### Build your exclusion list
Combine results from Commands 1 and 2:
- Agents with open/draft PRs → EXCLUDED
- Agents with `started` status less than 24 hours old (no matching `completed`/`failed`) → EXCLUDED
Write this exclusion list down before proceeding. You will reference it in Step 1.
Write your exclusion list explicitly:
```
EXCLUDED AGENTS: agent-a, agent-b
```
or:
```
EXCLUDED AGENTS: (none)
```
**If the `curl` command fails** (e.g., network error, API limit): You MUST still check the task log directory for `started` entries. Log a warning in your summary that PR-based claim checking was unavailable.
**If Command 1 failed** (network error, API limit, `gh`/`curl` unavailable): you MUST still check the task log directory (Command 2). Log a warning in your summary that PR-based claim checking was unavailable.
**Do not proceed to Step 1 until you have pasted command outputs and written your exclusion list.**
---
@@ -114,7 +128,7 @@ Write this exclusion list down before proceeding. You will reference it in Step
4. Look up that agent in the alphabetical roster below and select the **next agent** in the list.
5. If the most recent agent is the **last** in the roster, wrap around to the **first**.
6. If the directory is empty, start with the **first** agent in the roster.
7. **CHECK YOUR EXCLUSION LIST FROM STEP 0.** If the selected agent is on the exclusion list, skip to the next agent in the roster. Repeat until you find an agent that is NOT excluded. If you cycle through the entire roster and ALL agents are excluded, log as `failed` with summary `"All roster tasks currently claimed by other agents"` and stop.
7. **CHECK YOUR EXCLUSION LIST.** If the selected agent is on the exclusion list, skip to the next agent in the roster. Repeat until you find an agent that is NOT excluded. If you cycle through the entire roster and ALL agents are excluded, log as `failed` with summary `"All roster tasks currently claimed by other agents"` and stop.
### Agent Roster (alphabetical order)
@@ -161,13 +175,13 @@ You must create a visible claim before doing any work. This claim is a **distrib
After creating the draft PR, immediately re-check:
```bash
curl -s "https://api.github.com/repos/PR0M3TH3AN/bitvid/pulls?state=open&per_page=100" | jq -c '.[] | select(.title | contains("[weekly] <agent-name>")) | {number: .number, title: .title, created_at: .created_at}'
gh pr list --repo PR0M3TH3AN/bitvid --state open --json number,title,createdAt --limit 100 | grep -i "<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>` (if `gh` works) and go back to Step 1 to select the next agent.
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 go back to Step 1 to select the next agent.
### 2c. Log "started" in the task log immediately
> **This is critical.** Create a `started` log file NOW, before executing the task. This ensures the rotation advances even if you crash during execution.
> **Create a `started` log file NOW, before executing the task. This ensures the rotation advances even if you crash during execution.**
Create a new file in `docs/agents/task-logs/weekly/` with this naming pattern:
@@ -270,8 +284,8 @@ Use the current UTC timestamp (which will be later than the `started` file). The
| Layer | Mechanism | Catches |
|-------|-----------|---------|
| **Step 0** | Scan ALL open `[weekly]` PRs | Agents claimed by any platform |
| **Step 0** | Check task log dir for `started` files | Agents in progress (even without PR) |
| **Pre-flight gate** | Scan ALL open `[weekly]` PRs via `gh`/`curl` | Agents claimed by any platform |
| **Pre-flight gate** | Check task log dir for `started` files | Agents in progress (even without PR) |
| **Step 2a** | Create draft PR as lock | Cross-platform visibility |
| **Step 2b** | Race condition re-check | Simultaneous claims |
| **Step 2c** | Create `started` log file immediately | Crash recovery — rotation advances |