Fix scheduler prompts for host-repo TORCH execution context

This commit is contained in:
thePR0M3TH3AN committed 2026-02-25 13:32:29 -05:00
1 parent 2b086f0791
commit 46bed2a75b
2 files changed
+89 -55

No files matched your search

+56 -34
View File
@@ -13,31 +13,42 @@ Authority model: **scheduler-owned completion/logging**. Spawned agents must not
Follow `src/prompts/scheduler-flow.md` exactly.
MUST 0: Normalize execution context before any other step:
- If `src/prompts/scheduler-flow.md` exists in the current working directory, run in TORCH-root mode:
- `script_prefix = npm run`
- `path_prefix = ` (empty)
- Else if `torch/src/prompts/scheduler-flow.md` exists, run in host-repo mode:
- `script_prefix = npm run --prefix torch`
- `path_prefix = torch/`
- Else stop and report: `Unable to locate TORCH scheduler files (checked src/prompts and torch/src/prompts).`
- Apply `script_prefix` to every `lock:*` command below and apply `path_prefix` to every repository path below.
MUST 1: Set cadence config to:
- cadence = daily
- log_dir = task-logs/daily/
- log_dir = <path_prefix>task-logs/daily/
- branch_prefix = agents/daily/
- prompt_dir = src/prompts/daily/
- prompt_dir = <path_prefix>src/prompts/daily/
MUST 2: Run preflight to get the exclusion set:
npm run lock:check:daily -- --json --quiet
<script_prefix> lock:check:daily -- --json --quiet
Use `excluded` from the JSON output as the canonical exclusion set.
If `excluded` is unavailable, fallback to the union of `locked`, `paused`, and `completed`.
MUST 3: Run these commands in this order:
1) test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing" (missing TORCH.md is non-fatal)
2) mkdir -p task-logs/daily task-logs/weekly
3) ls -1 task-logs/daily/ | sort | tail -n 1
1) test -f <path_prefix>TORCH.md && cat <path_prefix>TORCH.md || echo "No TORCH.md found; continuing" (missing TORCH.md is non-fatal)
2) mkdir -p <path_prefix>task-logs/daily <path_prefix>task-logs/weekly
3) ls -1 <path_prefix>task-logs/daily/ | sort | tail -n 1
4) Select next roster agent using this exact algorithm:
- Read roster from src/prompts/roster.json (`daily` key).
- Resolve the roster path as `<path_prefix>src/prompts/roster.json`.
- Find `latest_file` from step 3.
- Derive `previous_agent` from that file with precedence:
a) YAML frontmatter key `agent`.
b) Filename format `<timestamp>__<agent-name>__<status>.md`.
- If no valid previous log exists (missing file, parse failure, or agent not in roster):
- Read `scheduler.firstPromptByCadence.daily` from `torch-config.json` if present.
- Read `scheduler.firstPromptByCadence.daily` from `<path_prefix>torch-config.json` if present.
- If that agent is in roster, start there.
- Otherwise set `start_index = 0`.
- Else set `start_index = (index(previous_agent)+1) mod roster_length`.
@@ -49,9 +60,9 @@ MUST 3: Run these commands in this order:
- excluded: `{const-refactor-agent, docs-agent}`
- start at next after `ci-health-agent`, skip excluded `const-refactor-agent`, choose `content-audit-agent`.
5) Claim via repository lock:
AGENT_PLATFORM=<platform> npm run lock:lock -- --agent <agent-name> --cadence daily
AGENT_PLATFORM=<platform> <script_prefix> lock:lock -- --agent <agent-name> --cadence daily
Exit 0 = lock acquired, proceed. Exit 3 = race lost, go back to step 3.
6) Execute selected prompt from src/prompts/daily/ (spawned agent work only; completion publish and final task log writing remain scheduler-owned)
6) Execute selected prompt from <path_prefix>src/prompts/daily/ (spawned agent work only; completion publish and final task log writing remain scheduler-owned)
7) Run required memory workflow for this cadence:
- Before execution, run the retrieval command if configured:
`scheduler.memoryPolicyByCadence.daily.retrieveCommand`
@@ -66,7 +77,7 @@ MUST 3: Run these commands in this order:
- If any validation command exits non-zero, do not call `lock:complete`.
- Instead, write `_failed.md` with the failing command and reason, then stop.
10) Publish completion before writing `_completed.md` (only after step 9 passes):
AGENT_PLATFORM=<platform> npm run lock:complete -- --agent <agent-name> --cadence daily
AGENT_PLATFORM=<platform> <script_prefix> lock:complete -- --agent <agent-name> --cadence daily
(Equivalent command allowed: torch-lock complete --agent <agent-name> --cadence daily)
- Exit 0: continue.
- Exit non-zero: fail the run, write `_failed.md` with a clear completion-publish failure reason and retry guidance, then stop.
@@ -79,18 +90,18 @@ MUST 3: Run these commands in this order:
- Learnings: [Content of the memory update file or "No learnings recorded"]
Worked example (required order):
- `AGENT_PLATFORM=codex npm run lock:lock -- --agent content-audit-agent --cadence daily`
- `AGENT_PLATFORM=codex <script_prefix> lock:lock -- --agent content-audit-agent --cadence daily`
- execute selected prompt work
- `AGENT_PLATFORM=codex npm run lock:complete -- --agent content-audit-agent --cadence daily` (complete, permanent)
- write `task-logs/daily/<timestamp>__content-audit-agent__completed.md`
- `AGENT_PLATFORM=codex <script_prefix> lock:complete -- --agent content-audit-agent --cadence daily` (complete, permanent)
- write `<path_prefix>task-logs/daily/<timestamp>__content-audit-agent__completed.md`
- print final summary (Status: Success, Learnings: <content>)
Worked example (failed validation, no completion publish):
- `AGENT_PLATFORM=codex npm run lock:lock -- --agent content-audit-agent --cadence daily`
- `AGENT_PLATFORM=codex <script_prefix> lock:lock -- --agent content-audit-agent --cadence daily`
- execute selected prompt work
- `npm run lint` exits non-zero (or `npm test` exits non-zero)
- write `task-logs/daily/<timestamp>__content-audit-agent__failed.md` with failure reason
- stop without running `AGENT_PLATFORM=codex npm run lock:complete -- --agent content-audit-agent --cadence daily`
- `<script_prefix> lint` exits non-zero (or `<script_prefix> test` exits non-zero)
- write `<path_prefix>task-logs/daily/<timestamp>__content-audit-agent__failed.md` with failure reason
- stop without running `AGENT_PLATFORM=codex <script_prefix> lock:complete -- --agent content-audit-agent --cadence daily`
- print final summary (Status: Failed, Reason: <reason>)
MUST 4: If all daily agents are excluded, stop and write `_failed.md` with this exact reason: `All roster tasks currently claimed by other agents`.
@@ -105,31 +116,42 @@ Authority model: **scheduler-owned completion/logging**. Spawned agents must not
Follow `src/prompts/scheduler-flow.md` exactly.
MUST 0: Normalize execution context before any other step:
- If `src/prompts/scheduler-flow.md` exists in the current working directory, run in TORCH-root mode:
- `script_prefix = npm run`
- `path_prefix = ` (empty)
- Else if `torch/src/prompts/scheduler-flow.md` exists, run in host-repo mode:
- `script_prefix = npm run --prefix torch`
- `path_prefix = torch/`
- Else stop and report: `Unable to locate TORCH scheduler files (checked src/prompts and torch/src/prompts).`
- Apply `script_prefix` to every `lock:*` command below and apply `path_prefix` to every repository path below.
MUST 1: Set cadence config to:
- cadence = weekly
- log_dir = task-logs/weekly/
- log_dir = <path_prefix>task-logs/weekly/
- branch_prefix = agents/weekly/
- prompt_dir = src/prompts/weekly/
- prompt_dir = <path_prefix>src/prompts/weekly/
MUST 2: Run preflight to get the exclusion set:
npm run lock:check:weekly -- --json --quiet
<script_prefix> lock:check:weekly -- --json --quiet
Use `excluded` from the JSON output as the canonical exclusion set.
If `excluded` is unavailable, fallback to the union of `locked`, `paused`, and `completed`.
MUST 3: Run these commands in this order:
1) test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing" (missing TORCH.md is non-fatal)
2) mkdir -p task-logs/daily task-logs/weekly
3) ls -1 task-logs/weekly/ | sort | tail -n 1
1) test -f <path_prefix>TORCH.md && cat <path_prefix>TORCH.md || echo "No TORCH.md found; continuing" (missing TORCH.md is non-fatal)
2) mkdir -p <path_prefix>task-logs/daily <path_prefix>task-logs/weekly
3) ls -1 <path_prefix>task-logs/weekly/ | sort | tail -n 1
4) Select next roster agent using this exact algorithm:
- Read roster from src/prompts/roster.json (`weekly` key).
- Resolve the roster path as `<path_prefix>src/prompts/roster.json`.
- Find `latest_file` from step 3.
- Derive `previous_agent` from that file with precedence:
a) YAML frontmatter key `agent`.
b) Filename format `<timestamp>__<agent-name>__<status>.md`.
- If no valid previous log exists (missing file, parse failure, or agent not in roster):
- Read `scheduler.firstPromptByCadence.weekly` from `torch-config.json` if present.
- Read `scheduler.firstPromptByCadence.weekly` from `<path_prefix>torch-config.json` if present.
- If that agent is in roster, start there.
- Otherwise set `start_index = 0`.
- Else set `start_index = (index(previous_agent)+1) mod roster_length`.
@@ -141,9 +163,9 @@ MUST 3: Run these commands in this order:
- excluded: `{}`
- previous agent is final roster entry, so wrap to index 0 and choose `bug-reproducer-agent`.
5) Claim via repository lock:
AGENT_PLATFORM=<platform> npm run lock:lock -- --agent <agent-name> --cadence weekly
AGENT_PLATFORM=<platform> <script_prefix> lock:lock -- --agent <agent-name> --cadence weekly
Exit 0 = lock acquired, proceed. Exit 3 = race lost, go back to step 3.
6) Execute selected prompt from src/prompts/weekly/ (spawned agent work only; completion publish and final task log writing remain scheduler-owned)
6) Execute selected prompt from <path_prefix>src/prompts/weekly/ (spawned agent work only; completion publish and final task log writing remain scheduler-owned)
7) Run required memory workflow for this cadence:
- Before execution, run the retrieval command if configured:
`scheduler.memoryPolicyByCadence.weekly.retrieveCommand`
@@ -158,7 +180,7 @@ MUST 3: Run these commands in this order:
- If any validation command exits non-zero, do not call `lock:complete`.
- Instead, write `_failed.md` with the failing command and reason, then stop.
10) Publish completion before writing `_completed.md` (only after step 9 passes):
AGENT_PLATFORM=<platform> npm run lock:complete -- --agent <agent-name> --cadence weekly
AGENT_PLATFORM=<platform> <script_prefix> lock:complete -- --agent <agent-name> --cadence weekly
(Equivalent command allowed: torch-lock complete --agent <agent-name> --cadence weekly)
- Exit 0: continue.
- Exit non-zero: fail the run, write `_failed.md` with a clear completion-publish failure reason and retry guidance, then stop.
@@ -171,18 +193,18 @@ MUST 3: Run these commands in this order:
- Learnings: [Content of the memory update file or "No learnings recorded"]
Worked example (required order):
- `AGENT_PLATFORM=codex npm run lock:lock -- --agent bug-reproducer-agent --cadence weekly`
- `AGENT_PLATFORM=codex <script_prefix> lock:lock -- --agent bug-reproducer-agent --cadence weekly`
- execute selected prompt work
- `AGENT_PLATFORM=codex npm run lock:complete -- --agent bug-reproducer-agent --cadence weekly` (complete, permanent)
- write `task-logs/weekly/<timestamp>__bug-reproducer-agent__completed.md`
- `AGENT_PLATFORM=codex <script_prefix> lock:complete -- --agent bug-reproducer-agent --cadence weekly` (complete, permanent)
- write `<path_prefix>task-logs/weekly/<timestamp>__bug-reproducer-agent__completed.md`
- print final summary (Status: Success, Learnings: <content>)
Worked example (failed validation, no completion publish):
- `AGENT_PLATFORM=codex npm run lock:lock -- --agent bug-reproducer-agent --cadence weekly`
- `AGENT_PLATFORM=codex <script_prefix> lock:lock -- --agent bug-reproducer-agent --cadence weekly`
- execute selected prompt work
- `npm run lint` exits non-zero (or `npm test` exits non-zero)
- write `task-logs/weekly/<timestamp>__bug-reproducer-agent__failed.md` with failure reason
- stop without running `AGENT_PLATFORM=codex npm run lock:complete -- --agent bug-reproducer-agent --cadence weekly`
- `<script_prefix> lint` exits non-zero (or `<script_prefix> test` exits non-zero)
- write `<path_prefix>task-logs/weekly/<timestamp>__bug-reproducer-agent__failed.md` with failure reason
- stop without running `AGENT_PLATFORM=codex <script_prefix> lock:complete -- --agent bug-reproducer-agent --cadence weekly`
- print final summary (Status: Failed, Reason: <reason>)
MUST 4: If all weekly agents are excluded, stop and write `_failed.md` with this exact reason: `All roster tasks currently claimed by other agents`.
+33 -21
View File
@@ -66,29 +66,39 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
## Numbered MUST Procedure
0. Normalize execution context before any command:
- If `src/prompts/scheduler-flow.md` exists in the current working directory:
- `script_prefix = npm run`
- `path_prefix = ` (empty)
- Else if `torch/src/prompts/scheduler-flow.md` exists:
- `script_prefix = npm run --prefix torch`
- `path_prefix = torch/`
- Else stop with: `Unable to locate TORCH scheduler files (checked src/prompts and torch/src/prompts).`
- Apply `script_prefix` to all `lock:*` invocations and apply `path_prefix` to scheduler paths.
1. Set cadence variables before any command:
- `cadence` = `daily` or `weekly`
- `log_dir` = `task-logs/<cadence>/`
- `prompt_dir` = `src/prompts/<cadence>/`
- `log_dir` = `<path_prefix>task-logs/<cadence>/`
- `prompt_dir` = `<path_prefix>src/prompts/<cadence>/`
Note: branch naming (for example `agents/<cadence>/`) is orchestration-level behavior and is not used by `run-scheduler-cycle.mjs`.
2. Run preflight to build the exclusion set:
```bash
if daily: `npm run lock:check:daily -- --json --quiet`; if weekly: `npm run lock:check:weekly -- --json --quiet`
if daily: `<script_prefix> lock:check:daily -- --json --quiet`; if weekly: `<script_prefix> lock:check:weekly -- --json --quiet`
```
Canonical exclusion rule:
- Use `excluded` from the `npm run lock:check:<cadence>` JSON output.
- Use `excluded` from the `<script_prefix> lock:check:<cadence>` JSON output.
- If `excluded` is unavailable, fallback to the union of `locked`, `paused`, and `completed` from that same JSON payload.
Goose Desktop note: `npm run lock:check:<cadence>` can emit large hermit wrapper logs. Use `--json --quiet` (as documented above). If the command still fails due to Goose hermit issues, apply the PATH workaround in `KNOWN_ISSUES.md` before rerunning.
Goose Desktop note: `<script_prefix> lock:check:<cadence>` can emit large hermit wrapper logs. Use `--json --quiet` (as documented above). If the command still fails due to Goose hermit issues, apply the PATH workaround in `KNOWN_ISSUES.md` before rerunning.
3. Read policy file(s) once before the run loop. This step is conditional: if `TORCH.md` is missing, continue without failing.
```bash
test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing"
test -f <path_prefix>TORCH.md && cat <path_prefix>TORCH.md || echo "No TORCH.md found; continuing"
```
4. Bootstrap log directories before listing files:
@@ -100,7 +110,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
5. When lock health preflight is enabled (`scheduler.lockHealthPreflight: true` or env `SCHEDULER_LOCK_HEALTH_PREFLIGHT=1`), verify relay/query health before selecting an agent or calling `lock:lock`:
```bash
npm run lock:health -- --cadence <cadence>
<script_prefix> lock:health -- --cadence <cadence>
```
- Escape hatch: set `SCHEDULER_SKIP_LOCK_HEALTH_PREFLIGHT=1` to skip this check for local/offline workflows.
@@ -121,6 +131,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
Selection algorithm (MUST be followed exactly):
- Roster source: `src/prompts/roster.json` and the key matching `<cadence>`.
- Resolve that source path as `<path_prefix>src/prompts/roster.json`.
- Let `roster` be that ordered array and `excluded` be the set from step 2's canonical exclusion rule.
- Let `latest_file` be the lexicographically last filename in `<log_dir>`.
- Determine `previous_agent` from `latest_file` using this precedence:
@@ -129,6 +140,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
- If no valid `latest_file` exists, or parsing fails, or `previous_agent` is not in `roster`, treat as first run fallback.
- First run fallback:
- Read `scheduler.firstPromptByCadence.<cadence>` from `torch-config.json` if present.
- In host-repo mode, resolve this as `<path_prefix>torch-config.json`.
- If that agent exists in `roster`, set `start_index = index(configured_agent)`.
- Otherwise set `start_index = 0`.
- Otherwise: `start_index = (index(previous_agent in roster) + 1) mod len(roster)`.
@@ -163,7 +175,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
```bash
AGENT_PLATFORM=<platform> \
npm run lock:lock -- --agent <agent-name> --cadence <cadence>
<script_prefix> lock:lock -- --agent <agent-name> --cadence <cadence>
```
- Exit `0`: lock acquired, continue.
@@ -179,7 +191,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
- `lock_stderr_excerpt` (redacted stderr snippet)
- `lock_stdout_excerpt` (redacted stdout snippet)
- Include `failure_class: backend_unavailable` and `failure_category: lock_backend_error` for both deferred and failed backend-unavailable lock outcomes.
- Include recommended auto-remediation text in `detail`: retry window, `npm run lock:health -- --cadence <cadence>`, and incident runbook link.
- Include recommended auto-remediation text in `detail`: retry window, `<script_prefix> lock:health -- --cadence <cadence>`, and incident runbook link.
- Keep generic reason text for compatibility, but append actionable retry guidance in `detail` using the command from `lock_command`.
9. Execute `<prompt_dir>/<prompt-file>` end-to-end via configured handoff command.
@@ -217,7 +229,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
- Scheduler runs `node scripts/agent/verify-run-artifacts.mjs --since <run-start-iso> --check-failure-notes`.
- If artifact verification exits non-zero: write `_failed.md` and stop.
12. Run repository checks (for example: `npm run lint`).
12. Run repository checks (for example: `<script_prefix> lint`).
- If any validation command exits non-zero: **fail the run immediately**, write `_failed.md` with the failing command and reason, and stop.
- step 12 MUST NOT be executed (`lock:complete` is forbidden until validation passes).
@@ -227,13 +239,13 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
```bash
AGENT_PLATFORM=<platform> \
npm run lock:complete -- --agent <agent-name> --cadence <cadence>
<script_prefix> lock:complete -- --agent <agent-name> --cadence <cadence>
```
(Equivalent invocation is allowed: `torch-lock complete --agent <agent-name> --cadence <cadence>`.)
- Exit `0`: completion published successfully; continue to step 14.
- Exit non-zero: **fail the run**, write `_failed.md` with a clear reason that completion publish failed and retry guidance (for example: `Retry npm run lock:complete -- --agent <agent-name> --cadence <cadence> after verifying relay connectivity`), then stop.
- Exit non-zero: **fail the run**, write `_failed.md` with a clear reason that completion publish failed and retry guidance (for example: `Retry <script_prefix> lock:complete -- --agent <agent-name> --cadence <cadence> after verifying relay connectivity`), then stop.
14. Create final task log only after step 13 succeeds (scheduler-owned):
@@ -260,19 +272,19 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co
Worked post-task example (MUST order):
1. `AGENT_PLATFORM=codex npm run lock:lock -- --agent content-audit-agent --cadence daily`
2. Execute `src/prompts/daily/content-audit-agent.md`
1. `AGENT_PLATFORM=codex <script_prefix> lock:lock -- --agent content-audit-agent --cadence daily`
2. Execute `<path_prefix>src/prompts/daily/content-audit-agent.md`
3. `node scripts/agent/verify-run-artifacts.mjs --since <run-start-iso> --check-failure-notes`
4. `AGENT_PLATFORM=codex npm run lock:complete -- --agent content-audit-agent --cadence daily` (complete, permanent)
5. Write `task-logs/daily/2026-02-14T10-00-00Z__content-audit-agent__completed.md`
4. `AGENT_PLATFORM=codex <script_prefix> lock:complete -- --agent content-audit-agent --cadence daily` (complete, permanent)
5. Write `<path_prefix>task-logs/daily/2026-02-14T10-00-00Z__content-audit-agent__completed.md`
6. Print final summary (Status: Success, Learnings: <content>)
Worked validation-failure example (MUST behavior):
1. `AGENT_PLATFORM=codex npm run lock:lock -- --agent content-audit-agent --cadence daily`
2. Execute `src/prompts/daily/content-audit-agent.md`
1. `AGENT_PLATFORM=codex <script_prefix> lock:lock -- --agent content-audit-agent --cadence daily`
2. Execute `<path_prefix>src/prompts/daily/content-audit-agent.md`
3. `node scripts/agent/verify-run-artifacts.mjs --since <run-start-iso> --check-failure-notes` passes
4. `npm run lint` exits non-zero (or `npm test` exits non-zero)
5. Write `task-logs/daily/2026-02-14T10-00-00Z__content-audit-agent__failed.md` with the failing command and reason
6. Stop the run **without** calling `npm run lock:complete -- --agent content-audit-agent --cadence daily`
4. `<script_prefix> lint` exits non-zero (or `<script_prefix> test` exits non-zero)
5. Write `<path_prefix>task-logs/daily/2026-02-14T10-00-00Z__content-audit-agent__failed.md` with the failing command and reason
6. Stop the run **without** calling `<script_prefix> lock:complete -- --agent content-audit-agent --cadence daily`
7. Print final summary (Status: Failed, Reason: <reason>)