Repository navigation
fix(generator): restore local setup composites before POST cleanup - #847
Conversation
review and mention load a local `setup:` composite from the workspace, then land the PR's tree over it. At job end the runner re-reads that file to dispatch the POST steps of the actions nested inside it, indexing into the step list it cached at load time — so a PR that changes the composite's step count fails cleanup with `Index was out of range`, and one that drops the file with `Can't find 'action.yml'`. Both paint the job red after a session that did its work correctly. Emit an `always()` step below the tree switch that restores each local `setup:` path from $GITHUB_SHA — the tree the job's first checkout took — before the POST chain walks. Inert for adopters whose setup names no local action. Closes #846
The Jinja for-loop left its last newline in the macro output, so a generated review workflow ended with a blank line — churn in the adopter's regen diff, and the repo's end-of-file-fixer rejected the snapshot. Build the run body in Python instead, where the trailing newline is under control, and pin the invariant for every workflow.
tend-agent
left a comment
There was a problem hiding this comment.
The mechanism traces cleanly and the $GITHUB_SHA argument holds for both callers: under pull_request_target GITHUB_SHA is the base-branch tip and github.ref is refs/heads/<base>, and actions/checkout with no ref fetches +<github.sha>:refs/remotes/origin/<base> — so the restore source is by construction the tree the composite loaded from. Same for mention's issues/issue_comment/repository_dispatch, where both resolve to the default branch. The object survives the second checkout too (checkout disables gc, and the +refs/pull/N/merge:refs/remotes/pull/N/merge refspec prunes nothing under refs/remotes/origin/). Suite is green locally at 334.
Nothing blocking; a few things worth weighing.
"Never switch trees" is a YAML-level claim, not a runtime one. The PR body scopes the fix to review and mention because the other four workflows don't swap the workspace after setup:. That's true of their templates, but not of what the agent does inside the agent step. nightly's bot-PR-conflict routine opens with gh pr checkout <number> (nightly/SKILL.md), and running-in-ci's "Pushing to PR Branches" hands every workflow the same recipe. An adopter whose setup: names a local composite gets the identical Index was out of range on tend-nightly the moment it checks out a bot PR that resized that composite — which is exactly the shape of PR the nightly conflict-resolution pass exists to handle.
Generalizing isn't a matter of dropping the macro call into the other four templates, though, and that's the part worth recording: those workflows check out ref: <default_branch>, which actions/checkout resolves to origin/<default> at fetch time, while $GITHUB_SHA on a schedule event is pinned at trigger time. A push landing in that window makes the two differ, and restoring the wrong-but-plausible version of the composite reintroduces the step-count mismatch the step exists to prevent. The macro would need the restore source parameterized to whatever ref the calling checkout used.
Nested local actions aren't covered. The restore replays only the paths named in setup:. A composite that itself does uses: ./.github/actions/inner gets its own POST re-read of inner, and unless inner happens to live under the restored directory it's still whatever the PR's tree put there. Narrow, but it's the same failure with a second hop.
Minor: shlex.quote protects the git checkout operand, but the same quoted string is interpolated into a double-quoted echo on the next line, so the quoting doesn't hold there — a $ in the path expands into the warning text, and a " would terminate the string early and fail the step whose whole job is to not turn a working run red. Realistically nobody names a directory that way, and fixing it means moving the path into a shell variable, which churns both new snapshots — so it's a judgement call whether it's worth the diff.
`shlex.quote` made it a safe `git` operand, but the same string was interpolated into the double-quoted warning, where a `$` would expand and a `"` would end the string early — failing the one step whose job is to never turn a working run red.
|
Thanks — taking these in reverse order of how cheap they were. Quoting. Fixed in d85aa96. The path now goes through a shell variable, so the raw value appears exactly once, inside single quotes, and both the You were right that it's the step whose whole job is not to turn a working run red, which is what made it worth the snapshot churn rather than a judgement call. Verified rather than reasoned: rendering Runtime tree switches and nested siblings. Both real, both filed as #848 rather than folded in here. The nightly case is the one that convinced me it's worth writing down — an adopter with a local composite hits the identical error the moment nightly's conflict pass checks out a bot PR that resized it, and that's precisely the PR shape that pass exists to handle. I kept it out of this PR because your own diagnosis is the reason it isn't mechanical: the other four check out On the nested gap: the restore is recursive over the named directory, so a composite nesting an action inside its own tree is covered — it's only a sibling |
# Conflicts: # generator/src/tend/templates/review.yaml.j2 # generator/src/tend/workflows.py
tend-agent
left a comment
There was a problem hiding this comment.
The merge with main lands the new review gate above this step, and the two don't compose: if: always() fires on runs where the composite was never loaded.
always() runs a step regardless of whether earlier steps were skipped, not just failed. So on a gate-skipped review run — a synchronize whose HEAD is already stamped, which is exactly the case main's gate exists to make common — no actions/checkout has run and the workspace is empty. git checkout then fails into the ||:
fatal: not a git repository (or any of the parent directories): .git
::warning::could not restore .github/actions/tend-setup from deadbeef; POST cleanup of the local action may fail
(ran the rendered step body under bash -e in a non-repo directory; exit 0, warning emitted.) Nothing goes red — the || holds. But every gate-skipped review on an adopter with a local setup: composite now carries a warning annotation announcing that cleanup may fail, when in fact no composite loaded and there is no POST chain to clean up. That's the same run-summary surface this PR exists to keep quiet.
Threading the gate condition through fixes it: always() && (steps.gate.outputs.should_run == 'true'). Suggestions below add an optional if_condition to the macro and pass skip_condition from review; mention keeps the bare always(), since its handle job gates at the job level so every step either runs or the job doesn't. Rendered both shapes against the real Jinja env (trim_blocks/lstrip_blocks on) to check the inline expression doesn't disturb the surrounding lines.
There's a self-hosted variant of the same gap worth a line in the comment if you touch it: where the workspace persists between jobs, the skipped-run restore doesn't fail — it succeeds against whatever repo the previous job left behind, staging the base tree's copy of the composite into a stale workspace. Harmless, but it's the same missing condition.
Two smaller things. The macro comment still names the parameter paths, which it hasn't been since d85aa96. And test_local_setup_action_restored_for_post_cleanup asserts if == "always()" exactly — that assertion is what pins the current shape, so relaxing it is needed either way; worth also adding a review-specific assertion that the restore's condition names steps.gate.outputs.should_run, so the composition is pinned rather than merely permitted.
`always()` runs past a skip, not just a failure, so on a gate-skipped review run — the case main's examined-HEAD gate exists to make common — no checkout had run and the restore warned about POST cleanup for a composite that never loaded. Thread `steps.gate.outputs.should_run` through an optional `if_condition` on the macro; mention keeps the bare `always()`, since its handle job gates at the job level.
|
Taken as suggested, in 7cac13b.
The macro comment names On the test: the I haven't run this on a live gate-skipped review either — same gap as the original fix, and for the same reason. The reasoning is from the rendered condition plus |
…tale two snapshots (#956) `wt test` failed six tests on macOS: the shell-script tests replace the environment wholesale, so a bare `bash` resolved through the PATH they set for their fake binaries and reached `/bin/bash` 3.2. `compute-token-usage.sh` uses `mapfile`, a bash 4 builtin, so those tests exited 127 locally while passing on the ubuntu runners. `BASH = shutil.which("bash")` joins `ACTION_VERSION` in `generator/tests/__init__.py` and every shell invocation in the suite uses it, `test_integration.py`'s generated-snippet run included — so the tests exercise the scripts under the bash version CI does. `_usage` was the one helper still hardcoding its PATH; it now resolves `jq` the way the three fixtures below it do, so the token-usage tests don't depend on `jq` sitting in `/usr/bin`. Merging main surfaced two more suites of the same kind, both fixed here: - **`jq` 1.8 removed `_nwise`**, which the outage-reconcile fake used to page comments, so it returned nothing to reconcile and `test_report_failure_reconciles_a_racing_leg` / `…_past_the_first_page` failed on any box with jq ≥ 1.8 (ubuntu ships 1.7.1). It now slices by index; an empty list still pages as `[[]]`, the shape real `gh` returns. - **`test_workflow_with_local_setup_regtest[review]` and `[mention]` were red on main**, not just locally: [#847](#847) recorded their snapshots against a base that predated the [#904](#904) revert and [#849](#849), so they carried the prose prompt and the older mention comments. Re-recorded from the current render. 429 tests pass on macOS. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Problem
tend-reviewandtend-mentionboth load the adopter's localsetup:composite from the workspace and then land the PR's tree over that same workspace. At job end the runner re-reads the composite's action file to dispatch the POST steps of the actions nested inside it (Swatinem/rust-cacheand friends), indexing into the step list it cached at load time. The file on disk is now the PR's version, so:Index was out of range. Must be non-negative and less than the size of the collection.— tend-review: POST cleanup of the local <setup> composite fails with 'Index was out of range' when a PR changes its step count (post-adoption variant of #561) #846Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under ...— tend-mention/handle: POST-job cleanup of local <setup> action fails on stale PR branches (followup to #391) #561One root cause, two surface errors: actions/runner#2816. Both paint the job red after a session that reviewed the PR or answered the mention correctly, in the one place a maintainer reads a red X as "the bot failed". #561 was closed as self-limiting because its trigger (branches predating tend adoption) decays out; the step-count variant does not — the setup composite is adopter-owned and gets edited, so it recurs on any PR that adds or removes a step in it.
Solution
Emit an
always()step below the tree switch intend-reviewandtend-mentionthat restores each localsetup:path from$GITHUB_SHAbefore the POST chain walks:This is option 1 from #561, generalized to cover both variants — it puts back the file's existence and its step count.
$GITHUB_SHAis the right source by construction: both workflows give their firstactions/checkoutnoref, so it resolves the triggering event's own commit, which is the tree the composite loaded from. Every main step runs ahead of every POST step, so a step in last position is early enough. The restore is tolerant — a path that can't be resolved warns rather than failing the job, so it never converts a working run into a red one._restore_local_actions_run()collects theuses: ./...entries fromsetup:, shell-quoted and de-duplicated. Adopters whose setup names only remote actions (tend's own,astral-sh/setup-uv@v6) render no step at all, so nothing changes for them. The four workflows that never switch trees after setup — triage, ci-fix, scheduled, notifications — are untouched.Testing
test_local_setup_action_restored_for_post_cleanupreproduces the bug: it asserts review and mention emit a restore step, guarded byif: always(), positioned after the step that switches the tree. It failed on both before the fix.test_no_restore_step_without_a_local_setup_actionpins the no-op case for remote-only setups.ruff(0.14.11, the pinned rev) check and format clean, and the fullpre-commit run --all-filesset passes.actionlintv1.7.10 over it (which runs shellcheck on inlinerun:blocks): clean. An earlierfor dir in ...shape tripped SC2043 on the single-path case, hence the one-line-per-path rendering.The path reaches both the
gitoperand and the warning text through a shell variable rather than being interpolated twice:shlex.quotemakes a safegitoperand, but the warning is a double-quoted string where a$would expand and a"would end it early — failing the one step whose job is never to turn a working run red. Verified by renderinguses: './weird/$HOME"; rm -rf /; echo "'and running the result underset -x:gitreceives it as one literal argument,$HOMEunexpanded. Pinned bytest_restore_step_quotes_the_setup_path.I have not exercised this against a live PR that resizes a setup composite — the failure only reproduces while such a PR is open against a differing base, and the fix ships to adopters at the next release, not from this branch. The mechanism above is traced from the runner issue and the template step order rather than observed end-to-end.
Known gaps, filed as #848
The scoping to review and mention is a claim about the templates. The agent can switch the tree at runtime on any workflow — nightly's bot-PR-conflict pass opens with
gh pr checkout— so an adopter with a local composite can hit the same error there. Generalizing isn't mechanical: the other four check outref: <default_branch>, which resolves at fetch time while$GITHUB_SHAis pinned at trigger time, so reusing this macro would restore a wrong-but-plausible tree. #848 carries that reasoning and the candidate shape. It also records the second gap: the restore is recursive over the named directory, so an action nested inside the composite's own tree is covered, but a siblinguses: ./elsewhereis not.Closes #846 — automated triage