Repository navigation
514 lines (502 loc) · 28.4 KB
/
Copy pathsupervisor.yml
File metadata and controls
514 lines (502 loc) · 28.4 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# The controller's supervisor (#626). A deterministic, read-only health pass
# every fifteen minutes; when a check fails, or on a two-hour sweep, an agent
# reads the report and asks for typed actions; an executor holding the bot's
# token performs only the dispatch requests agent-board admits and logs
# each in the supervisor log issue. The agent and the executor are off until
# SUPERVISOR is preview or apply; only apply executes requests.
# SUPERVISOR_HANDBACK=artifact keeps the agent's requests off the issue until
# admitted. Leave it unset until we have same-run download provenance, ledger
# continuity across two runs, refusal on missing ledger and ledger persistence
# after a write failure. For rollback, drain in-flight artifact executors and
# keep write caps at zero for one day after the last possible artifact write:
# the comment log cannot account for the ledger's writes.
name: supervisor
# Its own crons start it; an applying poll also starts a prompt-less health
# pass when enabled and no run on the default branch is newer than thirty
# minutes. `agent-board supervise due` makes it a sweep every two hours.
on:
schedule:
- cron: '*/15 * * * *'
- cron: '7 */2 * * *'
# The file as the default branch has it; health's `if` admits only the
# operator's comment on the locked requests issue.
issue_comment: # zizmor: ignore[dangerous-triggers]
types: [created]
workflow_dispatch:
inputs:
prompt:
description: Public operator request for the supervisor
type: string
default: ''
# The supervisor's own run, kept up for the operator's prompts over the
# tailnet after its first turn, with session.json's idle timeout.
session:
description: Run the agent as an interactive session
type: boolean
default: false
pool:
description: Inference pool from pools.json, for a session only
type: choice
options: [claude, openai, mistral]
default: claude
permissions: {}
# The agent-board commit both jobs install: the executor receives the bot's
# token, so it runs only a revision reviewed here, never agent-board's
# moving branch, and health/trigger and execute agree within a run. At this
# commit every write but the log is capped at zero unless config.json sets
# a cap. Move it only with a review of that revision's `supervise` code.
# session.yml and broker-probe.yml pin the same commit.
env:
AGENT_BOARD_REV: 183ed445b9b0b7b5510454e03e794a31c0efbb5d
# Keep whole runs serialized: trigger considers the previous workflow active
# through execute, even after its agent job ends, so a job-only group would
# discard manual prompts in that window. GitHub keeps one pending run per
# group and a newer arrival replaces it, so the fifteen-minute health passes
# get their own group: sharing one, the next pass would evict a prompt queued
# behind a long agent run. A health pass that finds an agent active declines
# (failures keep their cooldown and retry); a manual prompt declined that way
# fails visibly below. A run the health job skips (any comment but the
# operator's on the requests issue, or a run off the default branch) gets a
# group of its own: in a shared group it would evict a pending run and then
# do nothing (#803). That first branch is the negation of health's `if`;
# change both together. A prompt-less dispatch is a health pass too: in
# supervisor-agent it would evict a prompt. A session dispatch, prompt or
# not, is an agent run in supervisor-agent, so health passes keep running
# beside it and none evicts it; it holds that group for up to its idle
# timeout after each turn and its turn limit, while later prompts and
# comments wait (one of them pending) behind it.
concurrency:
group: >-
${{ (!(github.ref == format('refs/heads/{0}', github.event.repository.default_branch) &&
(github.event_name != 'issue_comment' ||
(github.event.comment.user.login == (vars.OPERATOR || 'cgwalters') &&
github.event.issue.number == fromJSON(vars.SUPERVISOR_REQUESTS_ISSUE || '656') && github.event.issue.locked == true &&
!github.event.issue.pull_request))) && format('supervisor-ignored-{0}', github.run_id)) ||
((github.event.schedule == '*/15 * * * *' ||
(github.event_name == 'workflow_dispatch' && inputs.prompt == '' && !inputs.session)) && 'supervisor-health') ||
'supervisor-agent' }}
cancel-in-progress: false
jobs:
health:
# Stop outsider comments spending inference or steering a bot-token executor.
# Keep the login and issue aligned with the trusted config.
# This gate runs before checkout, so another deployment names its own in
# the repository variables OPERATOR and SUPERVISOR_REQUESTS_ISSUE; the
# defaults are this deployment's. Set them to agent-board.json's operator
# and config.json's agent.requests.issue: `supervise compose` checks
# the comment against those again before any agent runs, but a mismatched
# login still gets a health pass and a supervisor-agent group slot.
if: >-
github.ref == format('refs/heads/{0}', github.event.repository.default_branch) &&
(github.event_name != 'issue_comment' ||
(github.event.comment.user.login == (vars.OPERATOR || 'cgwalters') &&
github.event.issue.number == fromJSON(vars.SUPERVISOR_REQUESTS_ISSUE || '656') && github.event.issue.locked == true &&
!github.event.issue.pull_request))
runs-on: ubuntu-26.04
# Build (10), previous report (2), pacing (1), collection (8), plus setup/upload.
timeout-minutes: 25
permissions:
contents: read
actions: read
issues: read
pull-requests: read
# The annotations of failed dispatch jobs, which say why they failed.
checks: read
outputs:
act: ${{ steps.trigger.outputs.act }}
repo: ${{ steps.trigger.outputs.repo }}
item: ${{ steps.trigger.outputs.item }}
task: ${{ steps.compose.outputs.task }}
agent: ${{ steps.session.outputs.agent || steps.trigger.outputs.agent }}
model: ${{ steps.session.outputs.model || steps.trigger.outputs.model }}
budget: ${{ steps.session.outputs.budget || steps.trigger.outputs.budget }}
session: ${{ steps.session.outcome == 'success' }}
idle: ${{ steps.session.outputs.idle }}
session-repo: ${{ steps.session.outputs.repo }}
session-issue: ${{ steps.session.outputs.issue }}
# The agenthome commit compose resolved the profile branch to, so execute
# checks the same text the agent read.
profile-commit: ${{ steps.compose.outputs.profile_commit || steps.session.outputs.profile_commit }}
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 fresh, never a cached binary that another job could replace
# before token use.
- name: Install verified agent-board at the pinned revision
env:
GH_TOKEN: ${{ github.token }}
timeout-minutes: 10
run: just build-agent-board "$AGENT_BOARD_REV"
# A foreign workflow or fork's report could steer pacing/failure history.
# Verify provenance; read=true means restored or proved absent, not a
# failed lookup (#814). Selection and bounded extraction live in agent-board.
- name: Previous health report
id: previous
continue-on-error: true
timeout-minutes: 2
env:
GH_TOKEN: ${{ github.token }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise previous \
--repository "$GITHUB_REPOSITORY" --workflow .github/workflows/supervisor.yml \
--artifact supervisor-health --branch "$DEFAULT_BRANCH" \
--event schedule --event workflow_dispatch --event issue_comment \
--destination "$RUNNER_TEMP/previous-health" >> "$GITHUB_OUTPUT"
# health is always true; daily marks a request or a due sweep. Without
# read (the lookup failed), only an explicit request sweeps (#814).
# `due` reads only whether a dispatch's prompt is empty, so a session
# with none is passed one: it is an explicit request too.
- name: Whether a pass is due
id: due
timeout-minutes: 1
env:
EVENT: ${{ github.event_name }}
PROMPT: ${{ inputs.prompt || (inputs.session && 'session' || '') }}
READ: ${{ steps.previous.outputs.read }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise due --event "$EVENT" --prompt "$PROMPT" \
${READ:+--previous "$RUNNER_TEMP/previous-health/times.json"} >> "$GITHUB_OUTPUT"
- name: Read-only health snapshot
if: ${{ steps.due.outputs.health == 'true' }}
timeout-minutes: 8
env:
# PAT: it reads private bot-ops' usage snapshot, and a pass would spend most of the job token's 1000 requests an hour.
GH_TOKEN: ${{ secrets.CGWALTERS_BOT_PAT }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise health \
--config .github/poll/agent-board.json --supervisor-config .github/supervisor/config.json \
--usage-config .github/usage/config.json --previous "$RUNNER_TEMP/previous-health/health.json" \
| tee -a "$GITHUB_STEP_SUMMARY"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
# Without a report, nothing: the next run looks back to the last one
# that has it, and its times, so a failed pass records no sweep.
if: ${{ !cancelled() && steps.due.outputs.health == 'true' && hashFiles('health.json') != '' }}
with:
name: supervisor-health
path: |
health.json
times.json
retention-days: 2
# Off unless agent.skipUnchangedFailures: a pass whose failures all
# failed in the previous report leaves them to the sweep (#804).
- name: Whether a check newly fails
id: repeat
if: ${{ steps.due.outputs.health == 'true' }}
# A failure here sets no skip, so the trigger runs as before.
continue-on-error: true
timeout-minutes: 1
env:
DAILY: ${{ steps.due.outputs.daily == 'true' && '--daily' || '' }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise repeat \
--config .github/poll/agent-board.json --supervisor-config .github/supervisor/config.json \
--previous "$RUNNER_TEMP/previous-health/health.json" ${DAILY:+"$DAILY"} >> "$GITHUB_OUTPUT"
# Decides from health.json and this workflow's own recent runs, and adds
# the day's use of each cap from the log, which is in a private repository
# the job token can't read. --daily bypasses cooldown, not an active agent,
# for explicit requests and the sweep; failures retain the normal cooldown.
- name: Whether the agent runs
id: trigger
if: ${{ steps.due.outputs.health == 'true' && steps.repeat.outputs.skip != 'true' }}
env:
GH_TOKEN: ${{ secrets.CGWALTERS_BOT_PAT }}
DAILY: ${{ steps.due.outputs.daily == 'true' && '--daily' || '' }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise trigger \
--config .github/poll/agent-board.json --supervisor-config .github/supervisor/config.json \
--pools .github/agentic-job/pools.json ${DAILY:+"$DAILY"} >> "$GITHUB_OUTPUT"
# Operator comments also reach an active agent through watch-item; a
# prompt has no other way in, so its operator must see it was dropped.
- name: Fail a manual prompt the trigger declined
if: ${{ github.event_name == 'workflow_dispatch' && (inputs.prompt != '' || inputs.session) && steps.trigger.outputs.act != 'true' && (vars.SUPERVISOR == 'preview' || vars.SUPERVISOR == 'apply') }}
run: |
echo "::error::The trigger declined this prompt or session, most likely because another supervisor agent run is active. Repeat it when that run ends."
exit 1
# The pool and the publication issue come from trusted files, as
# session.yml's do; the dispatcher picks only a pool name.
- name: Session settings
id: session
if: ${{ github.event_name == 'workflow_dispatch' && inputs.session && steps.trigger.outputs.act == 'true' && (vars.SUPERVISOR == 'preview' || vars.SUPERVISOR == 'apply') }}
timeout-minutes: 1
env:
POOL: ${{ inputs.pool }}
run: |
jq -e --arg repo "$GITHUB_REPOSITORY" '.enabled == true and .repository == $repo' .github/agentic-job/session.json > /dev/null ||
{ echo "::error::session.json does not enable sessions publishing on $GITHUB_REPOSITORY"; exit 1; }
jq -r '"repo=\(.repository)", "issue=\(.issue)", "idle=\(.idleMinutes)"' .github/agentic-job/session.json >> "$GITHUB_OUTPUT"
jq -r --arg pool "$POOL" '(.[$pool] // error("pools.json has no pool \($pool)")) | "agent=\(.agent)", "model=\(.model)", "budget=\(.budget)"' .github/agentic-job/pools.json >> "$GITHUB_OUTPUT"
- name: Supervisor profile and operator request
id: compose
if: ${{ steps.trigger.outputs.act == 'true' && (vars.SUPERVISOR == 'preview' || vars.SUPERVISOR == 'apply') }}
timeout-minutes: 2
env:
GH_TOKEN: ${{ github.token }}
TASK: ${{ steps.trigger.outputs.task }}
PROMPT: ${{ inputs.prompt }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise compose \
--config .github/poll/agent-board.json --supervisor-config .github/supervisor/config.json \
--task "$TASK" --prompt "$PROMPT" --event "$GITHUB_EVENT_PATH" >> "$GITHUB_OUTPUT"
# The agent: a research run of the shared wrapper on the requests issue,
# whose one checked add_comment carries the typed requests. Its token is
# the wrapper's read-only job token; the bot's token reaches only apply,
# which posts that comment, as for every dispatch.
agent:
needs: health
if: ${{ (vars.SUPERVISOR == 'preview' || vars.SUPERVISOR == 'apply') && needs.health.outputs.act == 'true' }}
uses: cgwalters-forge/actions/.github/workflows/cgwalters-agentic-job.yml@main
permissions:
contents: read
issues: write
pull-requests: write
actions: read
id-token: write
with:
task: ${{ needs.health.outputs.task }}
repo: ${{ needs.health.outputs.repo }}
item: ${{ needs.health.outputs.item }}
kind: research
research-artifact-only: ${{ vars.SUPERVISOR_HANDBACK == 'artifact' }}
config: .github/agentic-job/supervisor.toml
agent: ${{ needs.health.outputs.agent }}
model: ${{ needs.health.outputs.model }}
budget: ${{ needs.health.outputs.budget }}
session: ${{ needs.health.outputs.session == 'true' }}
idle-minutes: ${{ needs.health.outputs.idle }}
apply-environment: agent-apply
secrets:
# PAT: apply posts the requests comment with it, and execute accepts only the bot's, not github-actions[bot]'s.
SAFE_OUTPUTS_PAT: ${{ secrets.CGWALTERS_BOT_PAT }}
# The wrapper names a session's endpoint on its item, here the requests
# issue; the control app's chat pane looks for it on session.json's issue,
# in a comment by github-actions[bot] with this run's URL, as session.yml's
# wrapper posts it. The address is the wrapper's: its agent job joins the
# tailnet as agentic-job-RUN-ATTEMPT.
session-endpoint:
needs: health
if: ${{ needs.health.outputs.session == 'true' }}
runs-on: ubuntu-26.04
timeout-minutes: 5
permissions:
issues: write
steps:
- name: The session's endpoint on the session issue
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ needs.health.outputs.session-repo }}
ISSUE: ${{ needs.health.outputs.session-issue }}
DOMAIN: ${{ vars.TAILNET_DOMAIN }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
[[ -n $DOMAIN ]] || { echo '::error::a session needs the variable TAILNET_DOMAIN'; exit 1; }
endpoint="wss://agentic-job-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.$DOMAIN/"
gh issue comment "$ISSUE" --repo "$REPO" --body "⏳ [$GITHUB_WORKFLOW]($RUN_URL) is running. Session: after the task's turn the operator attaches at \`$endpoint\`, once the agent job's summary shows it served."
# Runs no agent-produced code: it parses the requests as data.
execute:
needs: [health, agent]
if: >-
(vars.SUPERVISOR == 'preview' || vars.SUPERVISOR == 'apply') &&
((vars.SUPERVISOR_HANDBACK != 'artifact' && needs.agent.outputs.result-url != '') ||
(vars.SUPERVISOR_HANDBACK == 'artifact' && needs.agent.outputs.research-status == 'ready'))
# Health passes run outside supervisor-agent, so keep the executor's cap
# census and reservation serialized across both groups.
concurrency:
group: supervisor-execute
cancel-in-progress: false
runs-on: ubuntu-26.04
timeout-minutes: 20
environment: agent-apply
permissions:
contents: read
issues: read
actions: read
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 at the pinned revision
env:
GH_TOKEN: ${{ github.token }}
timeout-minutes: 10
run: just build-agent-board "$AGENT_BOARD_REV"
# Preview has no bot token and never calls execute, which always writes
# its log even for a refused batch. List the proposed comment only.
- name: Preview requests without applying
if: ${{ vars.SUPERVISOR == 'preview' && vars.SUPERVISOR_HANDBACK != 'artifact' }}
timeout-minutes: 2
env:
GH_TOKEN: ${{ github.token }}
RESULT_URL: ${{ needs.agent.outputs.result-url }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise preview \
--config .github/poll/agent-board.json --supervisor-config .github/supervisor/config.json \
--result-url "$RESULT_URL"
- name: Perform the validated requests
if: ${{ vars.SUPERVISOR == 'apply' && vars.SUPERVISOR_HANDBACK != 'artifact' }}
timeout-minutes: 8
env:
# PAT: it logs on private cgwalters-forge/operator, writes items in other repositories and posts the org Projects v2 status.
GH_TOKEN: ${{ secrets.CGWALTERS_BOT_PAT }}
RESULT_URL: ${{ needs.agent.outputs.result-url }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
PROFILE_COMMIT: ${{ needs.health.outputs.profile-commit }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise execute \
--config .github/poll/agent-board.json --supervisor-config .github/supervisor/config.json \
--pools .github/agentic-job/pools.json --result-url "$RESULT_URL" \
${PROFILE_COMMIT:+--profile-commit "$PROFILE_COMMIT"} \
| tee -a "$GITHUB_STEP_SUMMARY"
- name: Verify and stage artifact hand-back
id: handback
if: ${{ vars.SUPERVISOR_HANDBACK == 'artifact' }}
timeout-minutes: 2
env:
GH_TOKEN: ${{ github.token }}
NEEDS_LEDGER: ${{ vars.SUPERVISOR == 'apply' }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
HANDBACK_REPO: ${{ needs.agent.outputs.handback-repository }}
HANDBACK_RUN: ${{ needs.agent.outputs.handback-run-id }}
HANDBACK_ATTEMPT: ${{ needs.agent.outputs.handback-run-attempt }}
PRODUCER: ${{ needs.agent.outputs.handback-agent-job }}
REQUESTS_ID: ${{ needs.agent.outputs.safe-outputs-artifact-id }}
REQUESTS_DIGEST: ${{ needs.agent.outputs.safe-outputs-artifact-digest }}
run: |
python3 - <<'PY'
import hashlib, io, json, os, re, subprocess, tempfile, zipfile
from pathlib import Path
env = os.environ
repo, run, attempt = (env['GITHUB_' + k] for k in ('REPOSITORY', 'RUN_ID', 'RUN_ATTEMPT'))
api = f'repos/{repo}/actions'
mib = 1024 * 1024
def require(condition, error):
if not condition:
raise SystemExit(error)
def get(path):
return json.loads(subprocess.check_output(['gh', 'api', f'{api}/{path}']))
def own(info):
return (info['path'] == '.github/workflows/supervisor.yml'
and (info['head_repository'] or {}).get('full_name') == repo
and info['head_branch'] == env['DEFAULT_BRANCH']
and info['event'] in ('schedule', 'workflow_dispatch', 'issue_comment'))
def listed(path, key):
page = get(path)
require(page['total_count'] == len(page[key]), f'Incomplete {key} listing')
return page[key]
def jobs(run_id, run_attempt):
return listed(f'runs/{run_id}/attempts/{run_attempt}/jobs?per_page=100', 'jobs')
def stage(directory, artifact_id, run_id, digest, member, limit):
require(isinstance(digest, str) and re.fullmatch(r'sha256:[0-9a-f]{64}', digest), 'Invalid artifact digest')
info = get(f'artifacts/{artifact_id}')
require(info['id'] == artifact_id and info['workflow_run']['id'] == run_id
and info['expired'] is False and info['digest'] == digest,
'Artifact metadata does not match the expected run and digest')
# Bound attacker-controlled downloads and decompress only the one
# expected member, to a fixed destination, never archive paths.
with subprocess.Popen(['gh', 'api', f'{api}/artifacts/{artifact_id}/zip'], stdout=subprocess.PIPE) as download:
data = download.stdout.read(4 * mib + 1)
if len(data) > 4 * mib:
download.kill()
raise SystemExit('Artifact archive exceeds 4 MiB')
require(download.wait() == 0, 'Artifact download failed')
require('sha256:' + hashlib.sha256(data).hexdigest() == digest, 'Artifact download digest mismatch')
with zipfile.ZipFile(io.BytesIO(data)) as archive:
matches = [entry for entry in archive.infolist() if entry.filename == member]
require(len(matches) == 1 and matches[0].file_size <= limit, f'Missing, duplicate or oversized {member}')
(directory / member).write_bytes(archive.read(matches[0]))
# Partial reruns can report outputs from an earlier producer; bind
# both the checked identity and the producer to this latest attempt.
require((env['HANDBACK_REPO'], env['HANDBACK_RUN'], env['HANDBACK_ATTEMPT']) == (repo, run, attempt),
'Hand-back identity is not this repository, run and attempt')
current = get(f'runs/{run}')
require(own(current) and current['id'] == int(run) and current['run_attempt'] == int(attempt)
and current['head_sha'] == env['GITHUB_SHA'] and current['run_number'] == int(env['GITHUB_RUN_NUMBER']),
'Hand-back is not for the latest attempt of this supervisor run')
require(any(str(job['id']) == env['PRODUCER'] and job['run_attempt'] == int(attempt)
and job['conclusion'] == 'success' for job in jobs(run, attempt)),
'Hand-back producer is absent from this attempt or did not succeed')
require(re.fullmatch(r'[1-9][0-9]*', env['REQUESTS_ID']), 'Invalid hand-back artifact ID')
directory = Path(tempfile.mkdtemp(prefix='supervisor-handback-', dir=env['RUNNER_TEMP']))
stage(directory, int(env['REQUESTS_ID']), int(run), 'sha256:' + env['REQUESTS_DIGEST'], 'outputs.jsonl', mib)
with open(env['GITHUB_OUTPUT'], 'a') as out:
if env['NEEDS_LEDGER'] == 'true':
# The name is only a discovery key. Do not take a different
# workflow's artifact or fall back from an invalid ledger.
# The locked agent has no artifact upload credential; the
# wrapper's uploads use its own fixed dispatch prefix.
candidates = []
for artifact in listed('artifacts?name=supervisor-executor-ledger&per_page=100', 'artifacts'):
run_id = artifact['workflow_run']['id']
if run_id == int(run):
continue
prior = get(f'runs/{run_id}')
if own(prior) and prior['run_number'] < current['run_number']:
candidates.append((prior['run_number'], run_id, artifact))
require(candidates, 'No prior supervisor executor ledger')
number, run_id, artifact = max(candidates, key=lambda candidate: candidate[0])
require(sum(candidate[0] == number for candidate in candidates) == 1,
'Ambiguous prior supervisor executor ledger')
require(any(job['name'] == 'execute' and any(step['name'] == 'Upload executor ledger'
and step['conclusion'] == 'success' for step in job['steps']) for job in jobs(run_id, 1)),
'Prior run did not upload a ledger from its executor')
stage(directory, artifact['id'], run_id, artifact['digest'], 'ledger.json', 2 * mib)
(directory / 'next').mkdir()
print(f'ledger-run={run_id}', file=out)
print(f'directory={directory}', file=out)
PY
- name: Preview artifact requests without applying
if: ${{ vars.SUPERVISOR == 'preview' && vars.SUPERVISOR_HANDBACK == 'artifact' }}
timeout-minutes: 2
env:
REQUESTS_DIR: ${{ steps.handback.outputs.directory }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise preview \
--config .github/poll/agent-board.json --supervisor-config .github/supervisor/config.json \
--requests "$REQUESTS_DIR/outputs.jsonl"
- name: Perform the validated artifact requests
id: execute-artifact
if: ${{ vars.SUPERVISOR == 'apply' && vars.SUPERVISOR_HANDBACK == 'artifact' }}
timeout-minutes: 8
shell: bash
env:
GH_TOKEN: ${{ secrets.CGWALTERS_BOT_PAT }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
PROFILE_COMMIT: ${{ needs.health.outputs.profile-commit }}
REQUESTS_DIR: ${{ steps.handback.outputs.directory }}
LEDGER_RUN: ${{ steps.handback.outputs.ledger-run }}
run: |
"$RUNNER_TEMP/agent-board/bin/agent-board" supervise execute \
--config .github/poll/agent-board.json --supervisor-config .github/supervisor/config.json \
--pools .github/agentic-job/pools.json --requests "$REQUESTS_DIR/outputs.jsonl" \
--ledger "$REQUESTS_DIR/ledger.json" --ledger-run "$LEDGER_RUN" \
--ledger-out "$REQUESTS_DIR/next/ledger.json" \
${PROFILE_COMMIT:+--profile-commit "$PROFILE_COMMIT"} \
| tee -a "$GITHUB_STEP_SUMMARY"
- name: Upload executor ledger
if: ${{ !cancelled() && (steps.execute-artifact.outcome == 'success' || steps.execute-artifact.outcome == 'failure') }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: supervisor-executor-ledger
path: ${{ steps.handback.outputs.directory }}/next/ledger.json
retention-days: 2
if-no-files-found: error