Skip to content

Keep a Bare Push's Branch Unresolved Behind an Unrecognized env Option in the Write Guard - #3731

Merged
ptr727 merged 10 commits into
developfrom
feature/burndown-guard-bare-branch
Oct 31, 2026
Merged

ptr727 merged 10 commits into
developfrom
feature/burndown-guard-bare-branch

Conversation

@ptr727

@ptr727 ptr727 commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Fixes a finding raised on promotion #3715.

Closes on promotion: #3728

What changes

_bare_branch in host-setup/agent-safety/claude/gh-write-guard.py read the branch a push naming no refspec (or HEAD) writes. Behind an env option the guard does not recognize, it fell back to reading that branch in the caller's directory with the command-carried GIT_DIR, as if the option were absent. So from a feature branch, env --ch=/srv/other git push origin was judged on the caller's feature branch while git may push main in /srv/other.

  • The fallback is deleted, along with the lenient read of _named_git_dir it alone used.
  • Behind such an option the branch now resolves only where an absolute --git-dir, git -C, or cd names the repository, as the existing reading already does.
  • Otherwise _bypass_denial reads the push as writing every branch protected by default, as --all is, so a protected default fails closed. _push_targets now takes the branches a bare or HEAD push may write as a tuple, so that expansion has one home.
  • A denial from that expansion carries its own reason, naming the unrecognized option and the ways to anchor the push, rather than claiming a write to main.
  • Requirement 4 in host-setup/agent-safety/README.md states the new behavior and its cost once: such a push may be refused even from a feature branch.

Verification

  • Reproduced first with the guard's own classify on two constructed scratch repositories, one checked out on main and the caller on a feature branch. Before: env --ch=<main repo> git push origin allowed. After: denied. env --ch=<main repo> git push origin feature/x stays allowed, and an absolute git -C or --git-dir naming the feature-branch repository is judged on its branch and allowed.
  • New and changed self-test rows: the no-refspec case and HEAD behind an unknown option are refused, an absolute --git-dir or git -C behind one resolves to that repository's branch, an absolute git -C naming a feature-branch checkout behind one is allowed, the explicit-refspec feature push stays allowed, and an unresolved bare push with no env option stays allowed.
  • gh-write-guard.py --selftest: SELFTEST PASS. Prose gate, ruff check and format, and pyright are clean.

Local strict-review findings

The two findings the opening push listed as open (no row checked which reason a denial carries, and the _bare_branch docstring naming a plain cd as an anchor) are fixed in later commits on this branch. Self-test rows now mark the dedicated reason, pin both halves of the condition that chooses it, and, through the rules seam, pin that the expansion reaches each of main, master, and develop for a bare, HEAD, and @ push. Each row was checked against a mutant it must kill. The last local pass over the pushed head raised no findings.

Copilot review on 7a3b468

  • Its three threads (docstring anchor scope, the wrapper-body cd remedy, a reason-regression self-test) are fixed and resolved.
  • Its overview also listed, with no thread, "Scope the unresolved-branch denial reason to only the targets produced by the expansion". Fixed: the dedicated reason now applies only to a denied target the push does not name, and named targets are judged first, so HEAD develop with a rule on develop keeps the ordinary reason.

Filed separately

🤖 Generated with Claude Code

ptr727 and others added 3 commits October 31, 2026 13:26
…n in the write guard

Behind an env option the guard does not recognize, a push naming no
refspec or HEAD no longer reads its branch in the caller's directory
with the command-carried GIT_DIR. Unless an absolute --git-dir, git -C,
or cd names the repository, it is read as writing every branch protected
by default, so a protected default fails closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings October 31, 2026 20:42
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ptr727

ptr727 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 7a3b468bf213009e7a5db5889bf73b834dfdee37, the content this pull request carries at that commit against develop, and it recorded 2 findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The change has three unresolved nit-level issues: missing reason-regression assertions and documentation or denial guidance that do not fully describe absolute anchor behavior, including wrapper-body cd.

3 open issues
What changed in this PR

This pull request hardens the write guard against bare or HEAD pushes hidden behind unrecognized env options. It removes unsafe repository-context fallback behavior and fails closed unless an absolute repository anchor resolves the target branch.

Changes:

  • Removes the lenient GIT_DIR fallback and expands unresolved bare pushes to protected default branches.
  • Updates branch-target expansion, denial messaging, and regression tests.
  • Documents the new behavior and supported repository anchors.

Review findings remain:

  • Moderate (1 vote): Scope the unresolved-branch denial reason to only the targets produced by the expansion.
  • Nit (4 votes): Add self-test assertions for denial reasons on bare and HEAD pushes.
  • Nit (4 votes): Clarify that only absolute anchors, including wrapper-body cd, resolve the repository.
  • Nit (2 votes): Include wrapper-body cd in the denial remediation message.
File Description
host-setup/​agent-safety/​README.md Documents fail-closed handling for unresolved bare and HEAD pushes behind unrecognized env options.
host-setup/​agent-safety/​claude/​gh-write-guard.py Updates repository resolution, protected-branch expansion, denial messaging, and self-test coverage.

Review effort: Lite

…n its env-option condition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.02%. Comparing base (afeb869) to head (ba5f237).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3731   +/-   ##
========================================
  Coverage    82.02%   82.02%           
========================================
  Files           27       27           
  Lines         9275     9275           
========================================
  Hits          7608     7608           
  Misses        1667     1667           
Flag Coverage Δ
python-3.13 82.02% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727

ptr727 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 07a1b12f1388f37930833b203902ec0b640c3cab, the content this pull request carries at that commit against develop, and it recorded 1 finding.

@ptr727

ptr727 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 87d2ca501d1ec908abc58769cd4277520779e957, the content this pull request carries at that commit against develop, and it recorded 2 findings.

@ptr727

ptr727 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 0a14a2b04188fb36ae7ff247e681c8c9e8259dc2, the content this pull request carries at that commit against develop, and it recorded 0 findings.

ptr727 and others added 2 commits October 31, 2026 14:03
…e the wrapper-body cd remedy

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727

ptr727 commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head ba5f2375f0280b4c0205995b405865ef26ec17e9, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727
ptr727 merged commit 5ad2acf into develop Oct 31, 2026
13 checks passed
@ptr727
ptr727 deleted the feature/burndown-guard-bare-branch branch October 31, 2026 21:25
ptr727 added a commit that referenced this pull request Oct 31, 2026
…d Unread Moves Whole, and Name uv's No-Cache Setting (#3715)

Promotes the changes merged into `develop` since promotion #3703 to
`main`, the third round of a backlog burndown.

- [#3709](#3709) Reads a
push's remote, and the branch of a push with no refspec, in the
repository git actually uses in the write guard's owner check
(requirement 4). Before, `--git-dir` and a `GIT_DIR` on the push were
ignored, so a constructed `git --git-dir=<other>/.git push origin
develop` was checked against the working directory's repository rules
and allowed. A shape whose repository the guard cannot determine (an
earlier `GIT_DIR`, a `-c` or `--config-env` override of a `remote.` or
`url.` key, any `GIT_CONFIG*` variable, an unresolvable `--git-dir`) now
blocks `main`, `master` and `develop`. The self-test covers each shape
and `host-setup/agent-safety/README.md` states the requirement.
- [#3712](#3712) Reads a
file moved out of a source some rule never read in full for that rule in
the prose gate: a narrowed directory scope, a `home_path_exempt` file,
instruction text for `issue-ref`, and a move that changes the file's
lexer. Skips YAML block scalars when reading a Compose file's volume
entries.
- [#3707](#3707) Names
uv's no-cache setting, and its remedies, when the repo gate's resolved
PyYAML interpreter is gone at launch, rather than reporting a bare
missing-file error.
- [#3708](#3708) Moves the
section-name lookup key into one `section_key()` in
`spec/fidelity_text.py`, used by the carry, the audit, the skill build
and the review ledger, with no behavior change.

- [#3722](#3722) Applies
`env`'s directory and environment options to the command the write guard
judges, answering this promotion's first review round: `env
-C`/`--chdir` move the repository a relative `GIT_DIR` and the remote
resolve in, `env -i`/`-u` clear a `GIT_DIR` that no longer steers the
check, and `env -S` is read rather than skipped. A run-time directory
reads as undetermined, which blocks `main`, `master` and `develop`.
- [#3721](#3721) Finds a
Compose block-scalar opener through the YAML lexer the gate already uses
rather than a hand-written pattern, so a key holding `#`, quoted or not,
opens the opaque region. Also answers this promotion's first review
round.

- [#3727](#3727) Reads an
`env` option the write guard does not recognize, such as GNU `env`'s
`--ch` abbreviation of `--chdir`, as leaving the push's repository
undetermined, so `main`, `master` and `develop` fail closed, answering
this promotion's second review round. A feature-branch push is never
newly blocked.

- [#3731](#3731) Removes
the fallback #3727 kept for a push naming no refspec behind an
unrecognized `env` option, answering this promotion's third review
round. Such a push resolves its branch only through an absolute
`--git-dir`, git's own `-C`, or a `cd` in a wrapper body, and is
otherwise read as writing every protected default, so it fails closed
even from a feature branch.

Deferred review findings: #3705 (`scripts/README.md`'s uvx promise),
#3706 (`validate.py`'s exact section-name match), #3710 (whether
`section_key` should casefold), #3711 (Compose-name and directory moves
in the prose gate), #3713 (the review reader's `open review findings:`
spelling), #3714 (an edited shebang that changes a file's lexer), #3720
(the write guard's reading of `git push -o<value>`), #3723 (unused
`_bare_push_branch` parameters), #3729 (a bare push after a branch
switch earlier in the same command), #3732 (the review reader's `Review
findings remain:` spelling).

For the maintainer: #3730 asks whether every bare push whose repository
the guard cannot determine should fail closed, as #3731 now does behind
an unrecognized `env` option.

Fixes #3695
Fixes #3684
Fixes #3694
Fixes #2358
Fixes #3686
Fixes #3716
Fixes #3717
Fixes #3725
Fixes #3728

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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