Repository navigation
341 lines (336 loc) · 17.3 KB
/
Copy pathpoll.yml
File metadata and controls
341 lines (336 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# One `agent-board pass` (agent-board's docs/pass.md): follows the bot's pull
# requests, refreshes usage from the broker, plans and applies the operator's
# epics, starts board work by Priority, WIP and pace, and derives board
# Status. The configuration is .github/pass.json on the default branch.
# Ours: the pass applies only while the variable PASS_APPLY is `enabled`,
# whether scheduled or started by hand (upstream lets a manual `apply=true`
# through without it), so unsetting PASS_APPLY stops every write
# (jmarrero-forge/tracker#42). pass.json follows cgwalters-forge/tracker's,
# adapted to our repositories and the single `claude` pool.
name: poll
run-name: pass${{ inputs.apply && vars.PASS_APPLY == 'enabled' && ' (apply)' || '' }}
# The clock is the `next` job: each applying pass starts the next one ten
# minutes after its own start, and `next-fallback` stands in when `next`
# fails or GitHub never creates it. GitHub drops most `*/10` scheduled runs
# (hours apart on 2026-11-08), so the schedule restarts a broken chain only
# eventually, not within one interval. Its disposable response cache
# comes from a validated applying predecessor; bootstrap runs discover one.
# Living status stays disabled until replay records have independent durability.
on:
schedule:
- cron: '*/10 * * * *'
workflow_dispatch:
inputs:
apply:
description: Take the steps; otherwise only preview
type: boolean
default: false
previous_run_id:
description: Preceding applying poll run (empty discovers a trusted predecessor)
type: string
required: false
default: ''
permissions: {}
# The agent-board commit the pass runs. It is given the bot's token, so it is
# a revision reviewed here, never agent-board's moving branch: move it only
# with a review of what that revision's `pass` does.
env:
AGENT_BOARD_REV: 113f892e9a4589c6a88e2740ef1a018f8c212f98
jobs:
pass:
if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
# One pass at a time; one that is due while another runs waits for it,
# and a group keeps only the newest waiting run. The group is the job's,
# not the workflow's, so `next` waiting out its ten minutes holds nothing.
concurrency:
group: pass
cancel-in-progress: false
runs-on: ubuntu-26.04
# The build (10), the join (3) and the pass's own bound (15, plus two
# to finish its writes), with room for checkout and setup.
timeout-minutes: 40
# `actions: write` starts dispatch.yml and review.yml runs with the job
# token; the identity token is the tailnet join's.
permissions:
contents: read
actions: write
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# A GitHub release outage (504s for over an hour on 2026-11-08) must not
# stop the job: build the same just from crates.io instead.
- id: just
continue-on-error: true
uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0
with:
just-version: 1.58.0
- if: steps.just.outcome == 'failure'
run: cargo install --locked --version 1.58.0 just && echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
# Built each pass and never cached: a cache any job on the default
# branch can write is not where a binary given the bot's token should
# come from.
- name: Install verified agent-board
env:
GH_TOKEN: ${{ github.token }}
timeout-minutes: 10
run: just build-agent-board "$AGENT_BOARD_REV"
# Stage 2 reads the broker's /usage over the tailnet. Without the
# join the pass runs without usage.url, pacing on the published
# snapshot, rather than failing on a broker it cannot reach.
# Ours: the join waits until pass.json has a usage section, the only
# thing it is for, so that a preview adds no tailnet node.
- name: Whether the pass reads usage
id: usage
run: echo "usage=$(jq 'has("usage")' .github/pass.json)" >> "$GITHUB_OUTPUT"
- name: Join the tailnet
id: tailnet
if: ${{ steps.usage.outputs.usage == 'true' }}
continue-on-error: true
timeout-minutes: 3
uses: jmarrero-forge/actions/tailscale@main
with:
oauth-client-id: ${{ vars.AGENTIC_JOB_TAILSCALE_OAUTH_CLIENT_ID }}
tags: ${{ vars.AGENTIC_JOB_TAILSCALE_TAGS }}
hostname: pass-${{ github.run_id }}-${{ github.run_attempt }}
# The broker's address stays in the variable the agent job, the
# broker probe and the tailnet test read (else the organization's
# tailnet setting), not in a second copy in pass.json.
- name: Configuration
env:
INFERENCE_URL: >-
${{ steps.tailnet.outcome == 'success' && (vars.INFERENCE_URL || steps.tailnet.outputs.proxy) || '' }}
run: |
base=${INFERENCE_URL%/}
base=${base%/v1}
jq --arg base "$base" 'if $base == "" then . else .usage.url = "\($base)/usage" end' \
.github/pass.json > "$RUNNER_TEMP/pass.json"
# Threat: a forged cached body can steer scheduling even with a valid
# ETag. Validate the named or discovered applying run after its pass job ends.
- name: Validate predecessor
id: predecessor
timeout-minutes: 2
env:
GH_TOKEN: ${{ github.token }}
PREVIOUS_RUN_ID: ${{ inputs.previous_run_id }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: just pass-state validate
- name: Restore pass state
id: restore
if: steps.predecessor.outputs.run-id != ''
continue-on-error: true
timeout-minutes: 2
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
github-token: ${{ github.token }}
run-id: ${{ steps.predecessor.outputs.run-id }}
name: pass-state
path: .state
- name: Start cold after an unreadable artifact
if: steps.restore.outcome == 'failure'
run: rm -rf .state
- name: Prepare state directory
run: mkdir -p .state
- name: One pass
id: pass
timeout-minutes: 18
env:
# The bot's write token (upstream's CGWALTERS_BOT_PAT) only for a
# pass that applies, by APPLY's own condition below; a preview
# reads with the read-only JMARRERO_BOT_READ_TOKEN.
GH_TOKEN: >-
${{ vars.PASS_APPLY == 'enabled' && (github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && inputs.apply)) && secrets.JMARRERO_BOT_PAT || secrets.JMARRERO_BOT_READ_TOKEN }}
DISPATCH_TOKEN: ${{ github.token }}
AGENT_BOARD: ${{ runner.temp }}/agent-board/bin/agent-board
# A scheduled pass applies once the operator sets PASS_APPLY; a
# pass started by hand applies only when asked to, and here only
# while PASS_APPLY is set too.
APPLY: >-
${{ vars.PASS_APPLY == 'enabled' && (github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && inputs.apply)) && '--apply' || '' }}
shell: bash
# The caps of the first scheduled passes, until they have been
# watched (upstream's); stderr too, so that the summary says why a
# pass failed.
# Dispatch picks one fix bounds file per target, so the pass needs both.
run: |
"$AGENT_BOARD" pass --config "$RUNNER_TEMP/pass.json" ${APPLY:+"$APPLY"} \
--fix-bounds .github/agentic-job/fix.toml \
--fix-bounds .github/agentic-job/midstream-fix.toml \
--max-dispatch 20 --max-writes 60 --max-status-changes 50 2>&1 | tee "$RUNNER_TEMP/pass.log"
# Threat: raw state includes private usage/holds comments and status records.
# Export only allowed responses and ledger entries in public repositories.
- name: Prepare public pass state
id: state
if: >-
${{ !cancelled() && (steps.pass.outcome == 'success' || steps.pass.outcome == 'failure') &&
vars.PASS_APPLY == 'enabled' && (github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && inputs.apply)) }}
timeout-minutes: 2
env:
GH_TOKEN: ${{ github.token }}
run: just pass-state export
- name: Upload pass state
if: ${{ !cancelled() && steps.state.outcome == 'success' }}
timeout-minutes: 2
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: pass-state
path: |
.state/public/pass.json
.state/public/living-status.json
include-hidden-files: true
retention-days: 1
if-no-files-found: ignore
- name: Summary
if: ${{ !cancelled() }}
run: |
{
echo '### Pass'
echo '<pre>'
sed 's/&/\&/g; s/</\</g; s/>/\>/g' "$RUNNER_TEMP/pass.log" 2>/dev/null || echo 'No pass ran'
echo '</pre>'
} >> "$GITHUB_STEP_SUMMARY"
next:
needs: pass
# Only an applying pass continues the chain, whether it passed or failed
# (`!cancelled()`, else GitHub adds an implicit `success()`);
# a preview by hand never starts one. A newer `next` replaces a waiting
# one, but two chains offset by a few minutes never wait at once (#1019),
# so before dispatching `next` also stops if a newer applying run on the
# default branch is still to finish: that run continues the chain. A run
# arriving between the check and the dispatch, or the newer run failing
# to continue, can still leave two chains or none. Setting PASS_APPLY to
# anything but `enabled`, or cancelling the waiting run, ends it. While
# it waits, `next` keeps a hosted runner busy for up to ten minutes per
# pass. While RELEASE_TRAIN is `dry-run` or `apply`, `next` also starts
# release-train.yml when its newest run is an hour old or absent, since
# GitHub drops its hourly schedule too; the train's own gate and
# concurrency still decide what that run does. Supervisor wakes use a
# thirty-minute threshold. With MAINTAIN_SHADOW `enabled`, `next` also
# starts maintain-shadow.yml when its newest default-branch run is at
# least thirty minutes old or absent; failures only warn. Its cron is
# the fallback, and its preview keeps its own read-only job token.
concurrency:
group: pass-next
cancel-in-progress: true
if: >-
${{ !cancelled() && (needs.pass.result == 'success' || needs.pass.result == 'failure') && vars.PASS_APPLY == 'enabled' &&
github.ref == format('refs/heads/{0}', github.event.repository.default_branch) &&
(github.event_name == 'schedule' || inputs.apply) }}
runs-on: ubuntu-26.04
# The verified download, ten-minute wait and bounded keep-alive requests.
timeout-minutes: 30
permissions:
actions: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# A GitHub release outage (504s for over an hour on 2026-11-08) must not
# stop the job: build the same just from crates.io instead.
- id: just
continue-on-error: true
uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0
with:
just-version: 1.58.0
- if: steps.just.outcome == 'failure'
run: cargo install --locked --version 1.58.0 just && echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- name: Install verified agent-board
env:
GH_TOKEN: ${{ github.token }}
timeout-minutes: 10
run: just build-agent-board "$AGENT_BOARD_REV"
- name: Start the shadow poll if stale
if: ${{ vars.MAINTAIN_SHADOW == 'enabled' }}
timeout-minutes: 2
env:
GH_TOKEN: ${{ github.token }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
shell: bash
run: |
if latest=$(timeout 30s gh run list --workflow maintain-shadow.yml --branch "$DEFAULT_BRANCH" --limit 1 --json createdAt --jq '.[0].createdAt // empty'); then
if [[ -z $latest ]] || (( $(date +%s) - $(date -d "$latest" +%s) >= 1800 )); then
timeout 30s gh workflow run maintain-shadow.yml --ref "$DEFAULT_BRANCH" || echo '::warning::Could not start maintain-shadow.yml'
fi
else
echo '::warning::Could not check maintain-shadow.yml age'
fi
- name: Start the next pass ten minutes after this one started
env:
GH_TOKEN: ${{ github.token }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
SUPERVISOR: ${{ vars.SUPERVISOR }}
RELEASE_TRAIN: ${{ vars.RELEASE_TRAIN }}
shell: bash
run: |
supervisor=()
if [[ $SUPERVISOR == preview || $SUPERVISOR == apply ]]; then
supervisor=(--supervisor-workflow supervisor.yml --supervisor-stale-minutes 30
--supervisor-input prompt= --supervisor-input session=false)
fi
train=()
if [[ $RELEASE_TRAIN == dry-run || $RELEASE_TRAIN == apply ]]; then
train=(--train-workflow release-train.yml --train-stale-minutes 60)
fi
"$RUNNER_TEMP/agent-board/bin/agent-board" pass next --workflow poll.yml \
--branch "$DEFAULT_BRANCH" --input apply=true --input "previous_run_id=$GITHUB_RUN_ID" --apply-title 'pass (apply)' \
--wait-minutes 10 "${supervisor[@]}" "${train[@]}"
# Best-effort recovery when `next` fails or never runs, including a missing
# `pass`. Use only runner tools and one dispatch attempt; there is no further
# recovery job. Dropped GitHub schedules/jobs still prevent a within-one-
# interval guarantee. Previews and cancelled/replaced passes never recover.
next-fallback:
needs: [pass, next]
if: >-
${{ !cancelled() && needs.pass.result != 'cancelled' &&
(needs.next.result == 'failure' || needs.next.result == 'skipped' || needs.next.result == '') &&
vars.PASS_APPLY == 'enabled' &&
github.ref == format('refs/heads/{0}', github.event.repository.default_branch) &&
(github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.apply)) }}
runs-on: ubuntu-26.04
timeout-minutes: 12
permissions:
actions: write
steps:
- name: Recover the next pass
env:
GH_TOKEN: ${{ github.token }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
PASS_RESULT: ${{ needs.pass.result }}
NEXT_RESULT: ${{ needs.next.result }}
shell: bash
run: |
printf 'Recovery dependencies: pass=<%s> next=<%s>\n' "$PASS_RESULT" "$NEXT_RESULT"
started=$(timeout 30s gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" --jq .run_started_at)
[[ -n $started && $started != null ]] || { echo '::error::missing run start time' >&2; exit 1; }
started_epoch=$(date -d "$started" +%s)
delay=$(( started_epoch + 600 - $(date +%s) ))
if (( delay > 600 )); then delay=600; fi
if (( delay > 0 )); then sleep "$delay"; fi
# Threat: a recovered old run can fork an already-owned chain. Match
# pinned pass next's branch, event/title, active statuses, creation-time
# and ID ordering, and fail if this run is outside its 200-run bound.
runs='[]'
for page in 1 2; do
listed=$(timeout 30s gh api --method GET "repos/$GITHUB_REPOSITORY/actions/workflows/poll.yml/runs" \
-f branch="$DEFAULT_BRANCH" -f exclude_pull_requests=true -f per_page=100 -f page="$page")
runs=$(jq -ce --argjson listed "$listed" '. + ($listed.workflow_runs | if type == "array" then . else error("missing workflow_runs") end)' <<< "$runs")
if jq -e --argjson id "$GITHUB_RUN_ID" 'any(.[]; .id == $id)' <<< "$runs" >/dev/null; then break; fi
if (( $(jq '.workflow_runs | length' <<< "$listed") < 100 )); then break; fi
done
newer=$(jq -r --argjson id "$GITHUB_RUN_ID" --arg branch "$DEFAULT_BRANCH" '
def created: .created_at | fromdateiso8601;
map(if (.id | type) == "number" and
all(.head_branch, .status, .event, .created_at; type == "string") and
(.event != "workflow_dispatch" or (.display_title | type) == "string")
then (created as $at | .) else error("invalid workflow run") end) |
(map(select(.id == $id))[0] // error("current run absent from bounded listing")) as $me |
first(.[] | select(.id != $id and .head_branch == $branch and
(.status == "queued" or .status == "waiting" or .status == "pending" or .status == "requested" or .status == "in_progress") and
(.event == "schedule" or (.event == "workflow_dispatch" and .display_title == "pass (apply)")) and
([created, .id] > [($me | created), $id])) | .id) // empty' <<< "$runs")
if [[ -n $newer ]]; then echo "run $newer continues the chain; not starting another"; exit 0; fi
timeout 30s gh workflow run poll.yml --repo "$GITHUB_REPOSITORY" --ref "$DEFAULT_BRANCH" -f apply=true -f "previous_run_id=$GITHUB_RUN_ID"