Skip to content

fix(review): run adopter setup on the base tree, not the PR's - #806

Merged
max-sixty merged 2 commits into
mainfrom
kaspersky-report-triage
Aug 2, 2026
Merged

max-sixty merged 2 commits into
mainfrom
kaspersky-report-triage

Conversation

@max-sixty

@max-sixty max-sixty commented Aug 2, 2026 •

Copy link
Copy Markdown
Owner

tend-review checked out the fork's tree and then ran the adopter's setup: steps against it. Those steps execute as the runner user, which holds sudo and — until proxy/setup-sandbox.sh strips it — the checkout PAT in .git/config. So a contributor's build backend, added dependencies, or local uses: ./ action ran with that access, ahead of the containment the harness exists to build. Root on the runner before the sandbox is set up makes everything downstream of it decorative.

Review now checks out the base tree, runs setup:, then lands the PR's tree. That is the ordering every other generated workflow already had — mention runs setup: before its gh pr checkout, and the rest check out the default branch — so this removes an exception rather than adding a rule.

The base checkout renders only alongside setup:, since giving setup a reviewed tree is the whole reason it exists. Where it does render, the PR checkout carries clean: false. Verified against actions/checkout's git-directory-helper.ts at v7: with clean false, prepareExistingDirectory skips git clean -ffdx && git reset --hard, keeps the existing repo since the fetch URL matches, and only detaches HEAD and prunes local branches. Setup's untracked output survives; tracked files are overwritten by the PR tree, which is what a reviewer should see. The merge-ref tree is preserved, so this doesn't reopen the tradeoff settled in #723.

Adopters with no setup: generate byte-identical output to before this PR — clean is omitted along with the base checkout, since the action consults that input only on the existing-repo path, which a lone checkout never reaches.

Scope

This strengthens defense in depth, not a load-bearing boundary. The merge restriction still stops the worst outcome, unchanged either way. Under the codex harness the effect is close to cosmetic: that harness runs the agent on the runner with sandbox: danger-full-access and passes both credentials directly, so the agent executes the same code with the same access moments later.

Adopter impact

Setup no longer sees the PR's manifests. Project setup that must (installing the PR's dependencies) belongs in sandbox_setup:, which runs as the sandbox user with the workspace as cwd — documented in docs/tend.example.yaml. Adopters whose setup only installs toolchains, or who have none, need no change.

Verification

285 tests pass, pre-commit run --all-files clean, and actionlint passes on generated workflows both with and without setup steps.

This was written by Claude Code on behalf of max-sixty

`tend-review` checked out the fork's tree and then ran the adopter's
`setup:` steps against it. Those steps execute as the runner user, which
holds sudo and, until the harness's sandbox setup strips it, the checkout
PAT in `.git/config` — so a contributor's build backend, added
dependencies, or local `uses: ./` action ran with that access, ahead of
the containment the harness exists to build.

Review now checks out the base tree, runs `setup:`, then lands the PR's
tree with `clean: false` so setup's workspace output survives. That is
the ordering every other generated workflow already had; review was the
exception. `sandbox_setup:` is the lever for project setup that must see
the PR's own manifests.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering change and clean: false reasoning both check out — traced the second checkout against actions/checkout v7: with clean false it reuses the existing repo, --force-reconciles tracked files to the merge tree, and leaves setup's untracked output in place. Tests and regtests are consistent (284 pass).

One design observation, non-blocking: for adopters with an empty setup:, the review job now runs two full actions/checkout@v7 steps (fetch-depth: 0) with nothing between them — visible in the regenerated test_workflow_minimal_regtest[review] output. The base checkout exists only to give setup: a reviewed tree; with no setup it's a full-history clone of the base branch that the second checkout immediately supersedes, so it's pure overhead on every review run for that subset. The other generated workflows have this too, but they run a single checkout — review is the one place the base checkout is genuinely redundant when there's no setup.

Guarding the base checkout + <<setup>> behind {% if setup %} in review.yaml.j2 would keep the security ordering when setup is present and drop the wasted clone when it isn't (the second clean: false checkout clones fine into an empty workspace — clean only affects the existing-repo path). The tradeoff is template uniformity vs. avoiding the redundant fetch. Happy to push that if you'd prefer it; otherwise this is fine as-is.

The base checkout exists to give `setup:` a reviewed tree. With no
setup it was a full-history clone of the base branch that the PR
checkout immediately superseded, on every review run. `clean` goes with
it: the action consults that input only when it finds an existing repo,
which a lone checkout never does.

Adopters without `setup:` now generate byte-identical output to before
the reordering.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner Author

Took the suggestion — pushed in a9aefae.

The base checkout is setup:'s, so it now renders only alongside it, guarded by {% if has_setup %} in review.yaml.j2. clean went with it rather than staying pinned to false: as you noted, git-source-provider.ts only calls prepareExistingDirectory when it finds an existing repo, so the input is inert on a lone checkout and emitting it would just be a wart for a future reader.

The result is stronger than avoiding the extra fetch — all three no-setup regtest snapshots (test_workflow_minimal_regtest[review], test_workflow_minimal_codex_regtest[review], test_extras_apply_path_regtest) are now byte-identical to main. Adopters without setup: see no diff at all from this PR, so the change is scoped to exactly the repos where the ordering matters.

Added test_review_without_setup_checks_out_once for that shape; 285 pass, and actionlint is clean on generated workflows both with and without setup.

This was written by Claude Code on behalf of max-sixty

@max-sixty
max-sixty merged commit 1dfe619 into main Aug 2, 2026
7 checks passed
@max-sixty
max-sixty deleted the kaspersky-report-triage branch August 2, 2026 18:29
max-sixty added a commit that referenced this pull request Aug 3, 2026
Bumps the generator to 0.1.13, syncs the lockfile, and adds the
CHANGELOG section the release workflow publishes verbatim as the GitHub
Release notes.

13 commits since 0.1.12. The release's substance is the security work:
the operational secrets move into a gated `tend` deployment environment,
with a secretless review-event relay in `tend-mention` and two new `tend
check` checks ([#810](#810)), and
`tend check` now verifies the bot cannot bypass the merge restriction
([#795](#795)). Alongside those:
the `claude-interactive` harness is removed
([#804](#804)), `tend-review` runs
the adopter's `setup:` on the base tree rather than the PR's
([#806](#806)), tend's uv is
pinned and isolated from the adopter's
([#807](#807)), and the proxy
readiness check waits for the port instead of trusting the CA file
([#811](#811)).

Adopters have manual work after this ships: the environment gate is
inert until each repo's regenerated workflows name the environment and
its secrets are re-minted into it. `TODO.md` carries the per-repo
recipe.

Once this merges: tag `0.1.13`, which publishes to PyPI and creates the
GitHub Release, then regenerate tend's own workflows against the
published version.

> _This was written by Claude Code on behalf of max-sixty_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants