Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/scripts/describe-skill-updates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env bash

# Describe every split skill's update within one total time budget (#15), so slow upstreams cannot
# use up the update job's time limit before any per-skill pull request opens.
#
# usage: describe-skill-updates.sh <describer> <out-dir> < <manifest>
#
# <manifest> has one `<slug><TAB><path>` line per split skill. For each line, in order, the describer
# (describe-skill-update.sh) writes <out-dir>/<slug>.md. A skill described before the budget is spent
# keeps its full description. A describer that fails, or that is stopped because the budget ran out
# while it was working, leaves the visible warning body instead, and so does every skill reached
# after the budget is spent: those are not described at all. The run always succeeds once every
# skill has a body, so the job goes on to open every pull request.
#
# The budget: the update job has 60 minutes (`timeout-minutes: 60`). The steps before this one took
# about 30 seconds in a real run, but `gh skill update` has no bound of its own, so they keep the
# first half of the hour. One describer run can take up to three bounded fetches of 300 seconds each
# plus lookups without a bound, so a budget of 30 minutes still fits two worst-case skills, and a
# typical skill takes seconds. A describer still running at the deadline is stopped (then killed
# after a grace of $kill_grace_seconds seconds), so the step ends within the budget plus that grace,
# leaving the upload and the other half of the hour untouched.
#
# DESCRIBE_SKILL_UPDATES_BUDGET_SECONDS replaces the budget, for tests only.

set -euo pipefail

budget_seconds=1800
kill_grace_seconds=10

[[ $# -eq 2 ]] || {
echo "usage: describe-skill-updates.sh <describer> <out-dir> < <manifest>" >&2
exit 2
}
describer="$1"
out_dir="$2"
budget="${DESCRIBE_SKILL_UPDATES_BUDGET_SECONDS:-$budget_seconds}"
[[ "$budget" =~ ^[0-9]+$ ]] || {
echo "describe-skill-updates: the budget must be a whole number of seconds, got '$budget'" >&2
exit 2
}

logs="$(mktemp -d)"
trap 'rm -rf "$logs"' EXIT

now() { date +%s; }

# bounded <seconds> <out> <err> <command...>: runs the command in its own process group with stdout
# to <out> and stderr to <err>, and stops the whole group when it outlives <seconds>. A grandchild
# that moved to a group of its own (the describer's own `timeout` around a fetch) is not reached, but
# it has its own bound, and the files keep it from holding this step's output open.
bounded() {
local seconds="$1" out="$2" err="$3" pid watcher rc=0
shift 3
set -m
"$@" >"$out" 2>"$err" </dev/null &
pid=$!
(
sleep "$seconds"
kill -TERM -- "-$pid" 2>/dev/null || exit 0
sleep "$kill_grace_seconds"
kill -KILL -- "-$pid" 2>/dev/null || true
) >/dev/null 2>&1 </dev/null &
watcher=$!
set +m
wait "$pid" || rc=$?
# Whatever is left in the group once the describer has exited, such as a child that ignored the
# stop, is a straggler: it is killed now, before the watcher that would have escalated goes.
kill -KILL -- "-$pid" 2>/dev/null || true
kill -TERM -- "-$watcher" 2>/dev/null || true
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
wait "$watcher" 2>/dev/null || true
return "$rc"
}

fallback() { # <body>
{
echo "> [!WARNING]"
echo "> - The upstream range, licence and repository state of this update could not be described; review them by hand."
echo
echo "Automated update of this agent skill to its latest version."
echo
echo "Each changed skill gets its own pull request, so one blocked update does not hold back the others."
} >"$1"
}

deadline=$(($(now) + budget))
n=0
while IFS=$'\t' read -r slug path; do
body="$out_dir/${slug}.md"
n=$((n + 1))
remaining=$((deadline - $(now)))
if ((remaining <= 0)); then
echo "::warning::The time budget for describing updates is spent, so ${path} was not described; its PR says so."
fallback "$body"
continue
fi
rc=0
bounded "$remaining" "$body" "$logs/$n.err" bash "$describer" "$path" || rc=$?
cat "$logs/$n.err" >&2
if ((rc != 0)); then
echo "::warning::Could not describe the update of ${path}; its PR says so."
fallback "$body"
fi
done
21 changes: 20 additions & 1 deletion .github/tests/test-describe-skill-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ cat >"$work/bin/gh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
printf '%s\n' "$*" >>"$GH_STUB/calls"
# A forge that never answers, for the time budget.
[[ ! -f "$GH_STUB/hang" ]] || sleep 60
[[ "$1" == api && $# -eq 2 ]] || { echo "unexpected gh call: $*" >&2; exit 64; }
case "$2" in
repos/acme/skills)
Expand Down Expand Up @@ -283,6 +285,8 @@ q() { yq -r "$1" "$workflow"; }
keep="$(q '.jobs.update-agent-skills.steps[] | select(.name == "📋 Keep the per-skill splitter") | .run')"
grep -qF '.github/scripts/describe-skill-update.sh' <<<"$keep" ||
fail "the describer must be copied out of this workflow's own commit with the splitter"
grep -qF '.github/scripts/describe-skill-updates.sh' <<<"$keep" ||
fail "the budgeted describing loop must be copied out of this workflow's own commit with the splitter"
step='.jobs.update-agent-skills.steps[] | select(.name == "📝 Describe each skill'\''s update")'
[[ "$(q "$step | .if")" == "\${{ steps.split.outputs.skills != '' && steps.split.outputs.skills != '[]' }}" ]] ||
fail "the describe step must run whenever a per-skill patch exists"
Expand All @@ -300,6 +304,7 @@ q "$step | .run" >"$work/describe-step.sh"
run_step() { # <manifest> <describer>
mkdir -p "$work/runner/skill-updates"
cp "$2" "$work/runner/describe-skill-update.sh"
cp "$repo_root/.github/scripts/describe-skill-updates.sh" "$work/runner/describe-skill-updates.sh"
(cd "$caller" && RUNNER_TEMP="$work/runner" SKILLS="$1" bash "$work/describe-step.sh")
}
describe_update "$t1" "$t4" >/dev/null
Expand All @@ -311,6 +316,20 @@ run_step '[{"slug":"p-skills-demo","path":"plugins/p/skills/demo"}]' "$work/brok
body="$(cat "$work/runner/skill-updates/p-skills-demo.md")"
has "$(warning_block "$body")" "could not be described" "a describer failure"
has "$body" "Automated update of this agent skill to its latest version." "the fallback body"
echo "ok: the workflow describes each split skill, falls back visibly, and each PR uses its description"
DESCRIBE_SKILL_UPDATES_BUDGET_SECONDS=0 run_step '[{"slug":"p-skills-demo","path":"plugins/p/skills/demo"}]' "$describe" >/dev/null 2>&1 ||
fail "a spent time budget must not stop the update"
body="$(cat "$work/runner/skill-updates/p-skills-demo.md")"
has "$(warning_block "$body")" "could not be described" "a spent time budget"
lacks "$body" "| Compare |" "a description written after the time budget was spent"
# A forge that never answers holds the real describer only until the budget runs out.
touch "$GH_STUB/hang"
start="$(date +%s)"
DESCRIBE_SKILL_UPDATES_BUDGET_SECONDS=2 run_step '[{"slug":"p-skills-demo","path":"plugins/p/skills/demo"}]' "$describe" >/dev/null 2>&1 ||
fail "a forge that never answers must not stop the update"
elapsed=$(($(date +%s) - start))
rm -f "$GH_STUB/hang"
((elapsed < 10)) || fail "a forge that never answers held the describe step for ${elapsed}s"
has "$(warning_block "$(cat "$work/runner/skill-updates/p-skills-demo.md")")" "could not be described" "a forge that never answers"
echo "ok: the workflow describes each split skill within its time budget, falls back visibly, and each PR uses its description"

echo "PASS: per-skill update PRs state the upstream range, licence and repository state of each skill"
134 changes: 134 additions & 0 deletions .github/tests/test-describe-skill-updates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env bash
# Contract test for the budgeted describing loop (#15): every split skill gets a body, a skill
# described before the time budget is spent keeps its description, and once the budget is spent every
# remaining skill gets the visible warning body while the step still succeeds, so every per-skill
# pull request opens. A describer that fails costs only its own skill, and one still running at the
# deadline is stopped together with its children.
#
# Time is a fake clock (a `date` stub that the stub describer moves forward), so no case waits on a
# real budget; only the deadline case waits one real second.
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
loop="$repo_root/.github/scripts/describe-skill-updates.sh"

fail() {
echo "FAIL: $*" >&2
exit 1
}

work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT

# ── the fake clock and the stub describer ────────────────────────────────────────────────────
mkdir -p "$work/bin"
real_date="$(command -v date)"
cat >"$work/bin/date" <<EOF
#!/usr/bin/env bash
if [[ "\$*" == "+%s" ]]; then cat "\$CLOCK"; else exec "$real_date" "\$@"; fi
EOF
chmod +x "$work/bin/date"
export PATH="$work/bin:$PATH" CLOCK="$work/clock"

# The stub describes <path> as one line. STUB_STEP moves the clock forward per call, STUB_FAIL names a
# path it fails for, and STUB_HANG a path it hangs on with a child that ignores SIGTERM, recording the child's pid.
cat >"$work/describer.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
printf '%s\n' "$1" >>"$STUB_CALLS"
echo "$(($(cat "$CLOCK") + ${STUB_STEP:-0}))" >"$CLOCK"
if [[ "$1" == "${STUB_FAIL:-}" ]]; then echo "partial"; exit 3; fi
if [[ "$1" == "${STUB_HANG:-}" ]]; then
echo "partial"
# A child that ignores the stop, so only the cleanup after the describer exits can end it.
(trap '' TERM; exec sleep 60) &
echo "$!" >"$STUB_CHILD"
wait
fi
echo "described $1"
EOF
export STUB_CALLS="$work/calls" STUB_CHILD="$work/child"

fallback_body='> [!WARNING]
> - The upstream range, licence and repository state of this update could not be described; review them by hand.

Automated update of this agent skill to its latest version.

Each changed skill gets its own pull request, so one blocked update does not hold back the others.'

out="$work/out"
run_loop() { # <budget>: runs the loop over skills a, b and c; stdout and stderr go to $work/log
rm -rf "$out" "$STUB_CALLS"
mkdir -p "$out"
: >"$STUB_CALLS"
echo 1000 >"$CLOCK"
printf 'a\tskills/a\nb\tskills/b\nc\tskills/c\n' >"$work/manifest.tsv"
DESCRIBE_SKILL_UPDATES_BUDGET_SECONDS="$1" bash "$loop" "$work/describer.sh" "$out" \
<"$work/manifest.tsv" >"$work/log" 2>&1 || fail "the loop must succeed (budget $1):"$'\n'"$(cat "$work/log")"
}
described() { [[ "$(cat "$out/$1.md")" == "described skills/$1" ]] || fail "$2: skill $1 must keep its description, got:"$'\n'"$(cat "$out/$1.md")"; }
fell_back() { [[ "$(cat "$out/$1.md")" == "$fallback_body" ]] || fail "$2: skill $1 must get the warning body, got:"$'\n'"$(cat "$out/$1.md")"; }
calls() { [[ "$(tr '\n' ' ' <"$STUB_CALLS")" == "$1" ]] || fail "$2: expected describer calls '$1', got '$(tr '\n' ' ' <"$STUB_CALLS")'"; }

# ── every skill inside the budget ────────────────────────────────────────────────────────────
STUB_STEP=10 run_loop 100
for s in a b c; do described "$s" "inside the budget"; done
calls "skills/a skills/b skills/c " "inside the budget"
grep -q '::warning::' "$work/log" && fail "no warning is due inside the budget:"$'\n'"$(cat "$work/log")"
echo "ok: every skill described inside the budget keeps its description"

# ── the budget is spent by the first skill ───────────────────────────────────────────────────
STUB_STEP=100 run_loop 100
described a "the first skill, described before the budget ran out"
fell_back b "the budget spent"
fell_back c "the budget spent"
calls "skills/a " "the budget spent"
[[ "$(grep -c 'time budget for describing updates is spent' "$work/log")" == 2 ]] ||
fail "each skill left undescribed must be named in a warning:"$'\n'"$(cat "$work/log")"
echo "ok: once the budget is spent, the remaining skills get the warning body and the step succeeds"

# ── a describer that fails costs only its own skill ──────────────────────────────────────────
STUB_STEP=10 STUB_FAIL=skills/b run_loop 100
described a "before a failing describer"
fell_back b "a failing describer"
described c "after a failing describer"
calls "skills/a skills/b skills/c " "a failing describer"
grep -qF '::warning::Could not describe the update of skills/b; its PR says so.' "$work/log" ||
fail "a failing describer must be named in a warning:"$'\n'"$(cat "$work/log")"
echo "ok: a describer that fails for one skill leaves the others their chance"

# ── a budget of zero ─────────────────────────────────────────────────────────────────────────
run_loop 0
for s in a b c; do fell_back "$s" "a budget of zero"; done
calls "" "a budget of zero"
echo "ok: a budget of zero describes nothing and still gives every skill its body"

# ── a describer still running at the deadline is stopped with its children ──────────────────
# Skill a uses 99 of the 100 fake seconds, so skill b, which hangs, has one real second left. The
# stop must come at that second, not at the whole budget and not after the kill grace.
start="$("$real_date" +%s)"
STUB_STEP=99 STUB_HANG=skills/b run_loop 100
elapsed=$(($("$real_date" +%s) - start))
((elapsed < 8)) || fail "the loop must stop a hanging describer when the budget runs out, it took ${elapsed}s"
described a "before the hanging describer"
fell_back b "a describer stopped at the deadline"
fell_back c "after the budget ran out during a describer"
calls "skills/a skills/b " "a describer stopped at the deadline"
child="$(cat "$STUB_CHILD")"
sleep 1
if kill -0 "$child" 2>/dev/null; then
kill "$child" 2>/dev/null || true
fail "the stopped describer's child must be stopped with it"
fi
echo "ok: a describer still running at the deadline is stopped with its children and falls back"

# ── usage ────────────────────────────────────────────────────────────────────────────────────
if DESCRIBE_SKILL_UPDATES_BUDGET_SECONDS=soon bash "$loop" "$work/describer.sh" "$out" </dev/null 2>/dev/null; then
fail "a budget that is not a whole number of seconds must be refused"
fi
if bash "$loop" "$work/describer.sh" </dev/null 2>/dev/null; then fail "a missing argument must be refused"; fi
grep -qE '^budget_seconds=[0-9]+$' "$loop" || fail "the budget must be one named value in the loop"
[[ "$(grep -c 'budget_seconds' "$loop")" == 2 ]] || fail "the budget is set in one place and read in one"
echo "ok: the budget is one named whole number of seconds"

echo "PASS: the describing loop keeps to its time budget and always leaves every skill a body"
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,10 @@ jobs:
- name: "\U0001F4DD Test the per-skill update description"
shell: bash
run: bash .github/tests/test-describe-skill-update.sh
# Every description shares one time budget, so slow upstreams cannot stop the per-skill PRs (#15).
- name: "\U000023F1 Test the time budget for describing skill updates"
shell: bash
run: bash .github/tests/test-describe-skill-updates.sh
- name: "\U0001F4E6 Seed pinned agent-skill fixture"
shell: bash
run: |
Expand Down
19 changes: 5 additions & 14 deletions .github/workflows/update-agent-skills.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ jobs:
run: |
cp .devantler-tech-actions/.github/scripts/split-skill-updates.sh "$RUNNER_TEMP/split-skill-updates.sh"
cp .devantler-tech-actions/.github/scripts/describe-skill-update.sh "$RUNNER_TEMP/describe-skill-update.sh"
cp .devantler-tech-actions/.github/scripts/describe-skill-updates.sh "$RUNNER_TEMP/describe-skill-updates.sh"

# Root scans must not discover the checkout's fixture skills, and the PR must not
# carry the checkout as a stray gitlink. The action itself resolves through $/.
Expand Down Expand Up @@ -191,20 +192,10 @@ jobs:
run: |
set -euo pipefail
jq -r '.[] | [.slug, .path] | @tsv' <<<"$SKILLS" > "$RUNNER_TEMP/skills.tsv"
while IFS=$'\t' read -r slug path; do
body="$RUNNER_TEMP/skill-updates/${slug}.md"
if ! bash "$RUNNER_TEMP/describe-skill-update.sh" "$path" > "$body"; then
echo "::warning::Could not describe the update of ${path}; its PR says so."
{
echo "> [!WARNING]"
echo "> - The upstream range, licence and repository state of this update could not be described; review them by hand."
echo
echo "Automated update of this agent skill to its latest version."
echo
echo "Each changed skill gets its own pull request, so one blocked update does not hold back the others."
} > "$body"
fi
done < "$RUNNER_TEMP/skills.tsv"
# One total time budget for every description (#15): once it is spent, the remaining
# skills get the warning body, so the pull requests still open.
bash "$RUNNER_TEMP/describe-skill-updates.sh" "$RUNNER_TEMP/describe-skill-update.sh" \
"$RUNNER_TEMP/skill-updates" < "$RUNNER_TEMP/skills.tsv"

- name: 📤 Upload the per-skill patches
if: ${{ steps.split.outputs.skills != '' && steps.split.outputs.skills != '[]' }}
Expand Down
Loading
Loading