Skip to content

fix(agent-guard): read the empty-rebase refs where the push runs - #2033

Merged
potiuk merged 2 commits into
apache:mainfrom
potiuk:fix/agent-guard-empty-rebase-push-directory
Nov 9, 2026
Merged

potiuk merged 2 commits into
apache:mainfrom
potiuk:fix/agent-guard-empty-rebase-push-directory

Conversation

@potiuk

@potiuk potiuk commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The empty-rebase guard ran its git rev-parse / merge-base / rev-list checks in the hook's cwd and ignored git -C. A branch rebased in a linked worktree and pushed with git -C <worktree> push --force-with-lease … HEAD:<branch> was judged by the main checkout's HEAD. That checkout sits on the default branch, so it has 0 commits over its merge-base and the valid push was refused: "refusing to force-push 'HEAD' — it has 0 commits over its merge-base with origin/main". Hit while rebasing a contributor's PR from a pr-management session.
  • guard_empty_rebase now resolves git -C with the existing _git_start_dir helper, as guard_commit_trailer already does.
  • cd <worktree> && git push … is still judged in the hook's directory. Segments carry no separators or subshell depth, so the guard cannot tell it from (cd <worktree>); git push …, which pushes from the hook's directory. Following the cd would let that empty push through. An earlier commit on this branch did follow it; the second commit takes that back. The deny message now names git -C <dir> push as the spelling to use.

The plugin copy and the secure-setup fingerprint are regenerated.

Type of change

  • Python package (tools/*/ with pyproject.toml)

Test plan

  • prek run --all-files passes (not run: the checkout is sparse, because the sandbox denies writes to .apache-magpie-overrides/tools/vetted-ops/)
  • For Python packages touched: uv run pytest / ruff check / mypy passes
  • Other: prek run --files on the four changed files passes, including check-family-plugins and isolated-setup-fingerprint.
  • Other: test_empty_rebase_reads_the_repository_git_c_names fails on main and passes with this change. test_empty_rebase_still_denied_in_the_repository_git_c_names checks that an empty push is still refused in the directory -C names. test_empty_rebase_does_not_follow_cd_and_names_git_c pins the cd and subshell cases to the old directory and checks the new hint.

RFC-AI-0004 compliance

No principles affected: this corrects where an existing guard reads state. It never allows a push the guard refused before, apart from a git -C push whose named repository has commits, and it adds no mutation, host access or outbound message.

Linked issues

None.

🤖 Generated with Claude Code

The empty-rebase guard ran its git checks in the hook's cwd. A branch
rebased in a linked worktree and pushed with `cd <worktree> && git push`
or `git -C <worktree> push` was judged by the main checkout's HEAD,
which sits on the default branch, so a valid push was refused as empty.

The guard now resolves `git -C`, and dispatch follows a literal `cd`
earlier on the line, so the refs are read in the directory the push
runs in.

Generated-by: Claude Opus 5
@potiuk potiuk added family:tools tools/* capability:fix Implement code change to resolve an issue labels Nov 9, 2026
@github-actions github-actions Bot added family:setup setup-* skills capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) substrate:action-guard Tool substrate: deterministic pre-tool-use command guards labels Nov 9, 2026
Segments carry no separators or subshell depth, so a `cd` in a subshell
(`(cd x); git push --force …`) would have moved the guard to a directory
the push never runs in, and let an empty push through. Keep only the
exact `git -C` resolution, and name `git -C <dir> push` in the deny
message for a push made after a `cd`.

Generated-by: Claude Opus 5
@potiuk
potiuk merged commit 8384182 into apache:main Nov 9, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capability:fix Implement code change to resolve an issue capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) family:setup setup-* skills family:tools tools/* substrate:action-guard Tool substrate: deterministic pre-tool-use command guards

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant