Skip to content

Commit 9dac92a

Browse files
vybeclaude
andcommitted
agent-dev: pre-check block v3 — always fire, never override (v1.3.2)
Fixes Abilityai/trinity#955. v2 of the scaffolded ~/.trinity/pre-check emitted "pipeline-tick: <reason>" when work was pending, which Trinity applies as a message override to whichever schedule called the pre-check — hijacking unrelated schedules (digests, heartbeats, batch jobs) into running pipeline-tick logic instead of their own work. v3 strips the block to a single `echo "fire"`; work-detection lives inside pipeline-tick where it only affects pipeline-tick. Migration auto-rewrites both v1 (silenced schedules with empty stdout) and v2 (hijacked with override) blocks to v3. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent dc6df18 commit 9dac92a

3 files changed

Lines changed: 33 additions & 80 deletions

File tree

‎plugins/agent-dev/.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "agent-dev",
33
"description": "Develop and extend existing agents — add skills, memory systems, GitHub Issues development workflow (backlog, roadmap, groom, claim, autoplan, commit, sprint, work-loop), and long-running multi-stage pipelines (add-pipeline + heartbeat / status / recover / pause / resume runtime skills)",
4-
"version": "1.3.1",
4+
"version": "1.3.2",
55
"author": {
66
"name": "Ability.ai",
77
"email": "[email protected]"

‎plugins/agent-dev/skills/add-pipeline/SKILL.md‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Add a long-running, multi-stage **pipeline** to any Trinity-compatible agent. Im
2929
| `.claude/skills/pipeline-resume/` | agent repo | operator resume |
3030
| `~/.trinity/pipelines/<slug>.yaml` | user home | write-through copy — Trinity's read surface |
3131
| `~/.trinity/pipeline-state/<slug>/` | user home | per-instance state, read by dashboards and other agents |
32-
| `~/.trinity/pre-check` | user home | advisory marker — emits a reason when pipeline-tick has work, always fires the schedule otherwise (see Step 6 for why) |
32+
| `~/.trinity/pre-check` | user home | heartbeat gate — always emits `fire` so every schedule runs; never emits a message override (see Step 6 for why) |
3333
| `dashboard.yaml` panel | agent repo (if present) | Trinity UI shows a row per instance |
3434
| heartbeat schedule | Trinity MCP (if available) | `pipeline-<slug>-heartbeat` cron `*/15 * * * *` |
3535

@@ -162,9 +162,14 @@ date -u +%Y-%m-%dT%H:%M:%SZ > "$HOME/.trinity/pipelines/$SLUG.last_synced"
162162

163163
### Step 6: Extend ~/.trinity/pre-check
164164

165-
The pre-check script emits an advisory reason when pipeline-tick has work pending. **It always fires the schedule** — skip logic belongs inside pipeline-tick itself, not here. Multiple pipelines coexist by sharing one script with a single managed block (it scans every `~/.trinity/pipeline-state/*/*.json`).
165+
The pre-check script always emits `fire` so the heartbeat schedule runs. It never emits a message override. Skip / work-detection logic belongs inside pipeline-tick itself, not here. Multiple pipelines share one script with a single managed block — no per-pipeline edits needed.
166166

167-
> ⚠️ **Why this constraint matters.** Trinity's pre-check API is **agent-global** — the same `~/.trinity/pre-check` is consulted before every scheduled skill on the agent, not just pipeline-tick. If the block ever returns empty stdout, Trinity silences **every** schedule on the agent (digests, heartbeats, batch jobs, the lot). Earlier versions of this template made that mistake. The block default MUST be `echo "fire"`.
167+
> ⚠️ **Why this constraint matters.** Trinity's pre-check API is **agent-global** — the same `~/.trinity/pre-check` is consulted before every scheduled skill on the agent, not just pipeline-tick. Two failure modes both silently hijack unrelated schedules:
168+
>
169+
> 1. **Empty stdout** silences every schedule on the agent (digests, heartbeats, batch jobs, the lot). v1 of this template made this mistake.
170+
> 2. **Any non-`fire`/`skip` stdout becomes the message override** applied to whichever schedule called the pre-check — overwriting the intended message of unrelated schedules and making them run whatever the override text says (e.g. `pipeline-tick`) instead of their own work. v2 of this template made this mistake.
171+
>
172+
> The block must emit exactly `echo "fire"` — nothing else.
168173
169174
```bash
170175
PRE_CHECK="$HOME/.trinity/pre-check"
@@ -179,12 +184,16 @@ if [ ! -f "$PRE_CHECK" ]; then
179184
fi
180185

181186
# Migrate or install the block
182-
if grep -q "BEGIN add-pipeline block v2" "$PRE_CHECK"; then
183-
echo "add-pipeline block v2 already present in pre-check — skipping."
187+
if grep -q "BEGIN add-pipeline block v3" "$PRE_CHECK"; then
188+
echo "add-pipeline block v3 already present in pre-check — skipping."
184189
elif grep -q "BEGIN add-pipeline block" "$PRE_CHECK"; then
185-
# v1 block present — rewrite it in place (v1 returned empty stdout when idle,
186-
# silencing all other agent schedules; v2 defaults to "fire").
187-
echo "⚠️ Found v1 add-pipeline block in pre-check — replacing with v2 (default-fire)."
190+
# v1 or v2 block present — rewrite it in place.
191+
# v1 returned empty stdout when idle, silencing every other agent schedule.
192+
# v2 emitted "pipeline-tick: <reason>" when work was pending, which Trinity
193+
# applies as a message override to whichever schedule called the pre-check —
194+
# hijacking unrelated schedules into running pipeline-tick. v3 always emits
195+
# "fire" and never overrides messages.
196+
echo "⚠️ Found older add-pipeline block in pre-check — replacing with v3 (always fire, no override)."
188197
TMP=$(mktemp)
189198
awk '
190199
/BEGIN add-pipeline block/ {skip=1; next}
@@ -316,7 +325,7 @@ Status: <installed via Trinity MCP | NOT installed — see Step 7>
316325
| Trinity MCP unavailable | Skip schedule install, print manual instructions |
317326
| dashboard.yaml has conflicting `pipelines:` key | Warn, leave existing alone, suggest manual review |
318327
| pre-check has un-marked content | Append our block but warn the user to review |
319-
| pre-check has v1 add-pipeline block (no `v2` marker) | Auto-rewrite to v2 (v1 emitted empty stdout when idle, silencing every other schedule on the agent — see Step 6) |
328+
| pre-check has v1 or v2 add-pipeline block (no `v3` marker) | Auto-rewrite to v3 (v1 silenced other schedules with empty stdout; v2 hijacked other schedules with a `pipeline-tick:` message override — see Step 6) |
320329

321330
## Idempotency
322331

Lines changed: 14 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,17 @@
1-
# BEGIN add-pipeline block v2 — managed by /add-pipeline, do not edit by hand
2-
# Emits an advisory reason when pipeline-tick has work pending. Always exits 0
3-
# with non-empty stdout so the heartbeat fires.
1+
# BEGIN add-pipeline block v3 — managed by /add-pipeline, do not edit by hand
2+
# Always emits "fire" so the heartbeat schedule runs. Never emits a message
3+
# override.
44
#
55
# CRITICAL: Trinity's pre-check API is agent-global — every scheduled skill on
6-
# this agent (not just pipeline-tick) consults this same file. If this block
7-
# ever returns empty stdout, Trinity silences ALL schedules on the agent. The
8-
# default MUST be "fire". Skip decisions belong inside pipeline-tick itself,
9-
# where they only affect pipeline-tick.
10-
11-
PIPELINE_STATE_DIR="${HOME}/.trinity/pipeline-state"
12-
if [ ! -d "$PIPELINE_STATE_DIR" ]; then
13-
# No pipelines installed yet — must still fire so other schedules run.
14-
echo "fire"
15-
exit 0
16-
fi
17-
18-
NOW_EPOCH=$(date +%s)
19-
HORIZON_SECONDS=900 # 15 minutes — match heartbeat cron
20-
21-
NEEDS_TICK=""
22-
for state_file in "$PIPELINE_STATE_DIR"/*/*.json; do
23-
[ -f "$state_file" ] || continue
24-
25-
# Status that always needs attention
26-
STATUS=$(jq -r '.status // "idle"' "$state_file" 2>/dev/null)
27-
case "$STATUS" in
28-
running|blocked)
29-
# in-flight or precondition-blocked instances need evaluation
30-
NEEDS_TICK="$state_file: status=$STATUS"
31-
break
32-
;;
33-
escalated)
34-
# check if escalation has been resolved externally
35-
OPEN=$(jq -r '.open_escalations | length' "$state_file" 2>/dev/null)
36-
if [ "$OPEN" = "0" ]; then
37-
NEEDS_TICK="$state_file: escalation cleared"
38-
break
39-
fi
40-
;;
41-
esac
42-
43-
# Idle instances with a stale last-completed-cycle need to start the next cycle
44-
LAST_CYCLE=$(jq -r '.last_completed_cycle_at // empty' "$state_file" 2>/dev/null)
45-
if [ -n "$LAST_CYCLE" ]; then
46-
LAST_CYCLE_EPOCH=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$LAST_CYCLE" +%s 2>/dev/null || date -d "$LAST_CYCLE" +%s 2>/dev/null)
47-
if [ -n "$LAST_CYCLE_EPOCH" ]; then
48-
AGE=$((NOW_EPOCH - LAST_CYCLE_EPOCH))
49-
# idle for over 24h → trigger
50-
if [ "$AGE" -gt 86400 ]; then
51-
NEEDS_TICK="$state_file: idle for ${AGE}s"
52-
break
53-
fi
54-
fi
55-
fi
56-
57-
# Stage timing out within the next horizon
58-
NEXT_CHECK=$(jq -r '.next_check_at // empty' "$state_file" 2>/dev/null)
59-
if [ -n "$NEXT_CHECK" ]; then
60-
NEXT_CHECK_EPOCH=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$NEXT_CHECK" +%s 2>/dev/null || date -d "$NEXT_CHECK" +%s 2>/dev/null)
61-
if [ -n "$NEXT_CHECK_EPOCH" ] && [ "$NEXT_CHECK_EPOCH" -le "$((NOW_EPOCH + HORIZON_SECONDS))" ]; then
62-
NEEDS_TICK="$state_file: next_check_at within horizon"
63-
break
64-
fi
65-
fi
66-
done
67-
68-
if [ -n "$NEEDS_TICK" ]; then
69-
echo "pipeline-tick: $NEEDS_TICK"
70-
else
71-
echo "fire"
72-
fi
6+
# this agent (not just pipeline-tick) consults this same file. Two failure
7+
# modes both silently hijack unrelated schedules:
8+
# 1. Empty stdout silences ALL schedules on the agent.
9+
# 2. Any non-"fire"/"skip" stdout becomes the message override applied to
10+
# WHICHEVER schedule called the pre-check — overwriting the intended
11+
# message of unrelated schedules (digests, heartbeats, batch jobs) and
12+
# making them run pipeline-tick instead of their own work.
13+
# This block must therefore emit exactly "fire" and nothing else. Skip /
14+
# work-detection logic belongs inside pipeline-tick itself, where it only
15+
# affects pipeline-tick.
16+
echo "fire"
7317
# END add-pipeline block

0 commit comments

Comments
 (0)