Skip to content

Fail Closed When the Write Guard Cannot Read the Remote Names - #3037

Merged
ptr727 merged 2 commits into
developfrom
feature/3030-guard-remote-read-unresolved
Oct 15, 2026
Merged

ptr727 merged 2 commits into
developfrom
feature/3030-guard-remote-read-unresolved

Conversation

@ptr727

@ptr727 ptr727 commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Answers the Copilot finding on the promotion pull request #3030 at host-setup/agent-safety/claude/gh-write-guard.py, which showed that a failed git remote read could let a bare push to a protected branch through.

  • _read_branch read a failed git remote as an empty remote list. A remote named up/stream then kept a segment, so a push target of refs/remotes/up/stream/develop was read only as stream/develop and up/stream/develop, and the branch-rule lookup never saw develop.
  • A failed git remote read now answers _UNRESOLVED. _bare_push_branch passes it through, and both of its callers in _push_targets already turn it into the unresolved deny. A git remote read that succeeds with no output still reads as no remotes.
  • The unresolved deny message now names a failed remote read as one of its causes, since a plain git push in a valid checkout can reach it that way.
  • A new self-test, _push_remote_read_selftest, builds a constructed repository whose push target sits under the slash-named remote up/stream. It makes only the git remote read fail and asserts the unresolved deny. With the fix reverted, the case fails as allow.

Differential against develop

The guard on origin/develop and the guard on this branch were each run over every _PUSH_DIR_CASES and _PUSH_NAME_CASES row plus the new case, once with git remote working and once with it failing. That makes 282 rows in all.

  • With git remote working, no verdict changes.
  • With git remote failing, 6 rows change from allow to deny, each an unresolved deny on a remote-tracking push target. Those are the new case and the 5 name cases whose push target is a remote-tracking ref that the first-segment read does not turn into develop.
  • No row is newly allowed.

Local Review

Two local-strict-review passes ran. The first raised two findings. The deny message's stated causes are fixed in this branch. A failed @{push} read falling back to the local branch name is pre-existing and filed as #3036. The second pass raised no findings.

Verification

  • gh-write-guard.py --selftest passes.
  • test_install.py passes, as do the root tests/ suite, spec/validate.py, ruff format and check, mypy, prose_lint.py, and the repo_gate.py gates.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Push attempts are now denied when remote information cannot be read, rather than relying on incomplete branch details.
    • The denial message now clarifies that unreadable remotes may prevent identification of the target branch.

ptr727 and others added 2 commits October 14, 2026 17:14
A bare push whose @{push} target is a remote-tracking ref is read against
the remote names `git remote` lists, so a remote named up/stream loses both
its segments. A failed `git remote` read fell back to an empty list, which
left refs/remotes/up/stream/develop read only as stream/develop and
up/stream/develop, so a push to a protected develop could be allowed. The
failed read now answers unresolved, which the push check denies.

A self-test case makes only the `git remote` read fail under a slash-named
remote and asserts the unresolved deny.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The unresolved deny gave only a directory that does not resolve and an
earlier command that may move the branch as its causes. A bare push in a
valid checkout whose `git remote` read fails now reaches that same deny, so
the message names that cause too.

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

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d8fd0a93-081f-4626-96f0-4c03cd2ce092
📥 Commits

Reviewing files that changed from the base of the PR and between 16ad456 and 7b37479.

📒 Files selected for processing: 1
  • host-setup/agent-safety/claude/gh-write-guard.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Push branch resolution now returns _UNRESOLVED when Git cannot list remotes. The denial reason identifies unreadable remotes, and a new self-test checks the failure case.

Changes: Push branch resolution

Layer / File(s) Summary
Handle unreadable remote lists
host-setup/agent-safety/claude/gh-write-guard.py
_read_branch returns _UNRESOLVED when the remote list cannot be read. The push-bypass denial reason includes this condition. A self-test checks the unresolved result and denial classification. The test is called from _selftest().

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 7b374

The write guard now denies bare pushes when it cannot read the remote names, instead of allowing them. No actionable merge risk remains from the supplied evidence.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: the write guard fails closed when it cannot read remote names.
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 1 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@ptr727

ptr727 commented Oct 15, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 7b3747923b4cc2e21019cfe3f93b2eaed3ce9601, the content this pull request carries at that commit against develop, and it recorded 0 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.

🟢 Approval recommended

The focused change reaches the existing denial path and has targeted regression coverage.

0 open findings

What changed in this PR

This PR makes the write guard deny a bare push when it cannot read remote names, rather than risk missing a protected destination branch.

Changes:

  • Treat a failed git remote read as an unresolved push target while preserving successful empty reads.
  • Clarify the denial message and add a regression self-test for a slash-named remote.
File Description
host-setup/​agent-safety/​claude/​gh-write-guard.py Fails closed on remote-read errors and tests that path.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ptr727

ptr727 commented Oct 15, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.00%. Comparing base (fd49353) to head (7b37479).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3037      +/-   ##
===========================================
+ Coverage    60.98%   61.00%   +0.01%     
===========================================
  Files           17       17              
  Lines         9010     9014       +4     
===========================================
+ Hits          5495     5499       +4     
  Misses        3515     3515              
Flag Coverage Δ
python-3.13 61.00% <ø> (+0.01%) ⬆️

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 merged commit 02f21a5 into develop Oct 15, 2026
14 checks passed
@ptr727
ptr727 deleted the feature/3030-guard-remote-read-unresolved branch October 15, 2026 00:35
ptr727 added a commit that referenced this pull request Oct 15, 2026
…ng, and backlog-burndown Re-Dispatch Rules to Main (#3030)

- #2997 adds an updater that keeps the coding-agent tools already
installed on a host current, without installing a tool the maintainer
has not chosen
- #3017 brings the agent-safety READMEs up to the write guard's #3011
readings: `--admin` read inside a quoted `eval` argument, clustered and
cut-short push options, `--branches` as `--all`, `refs/` pattern
destinations, and a double-quoted list expansion as a directory or
commit value failing closed
- #3022 pairs a Copilot overview-table or `Review findings:` entry with
a review thread by the file it names, replacing word overlap, compares
the headline count against everything the round and the pull request
account for, and makes `pr_review.py cleanup` read every page of the
head pull requests, counting only this repository's own
- #3018 has `backlog-burndown` name a new branch when an issue is
dispatched again, name the open pull request a pushed branch still heads
when cleanup reports it, and splits the long cleanup sentence
- #3028 keeps an abandoned group's issue out of the `backlog-burndown`
ranking while that group is stopped for the maintainer, and records the
release on the claim comment
- #3023 makes `gh-write-guard` read a `heads/` push destination as the
branch git completes it to, read `--prune` beside a pattern, `:`,
`--all`, or bare push as a delete of each branch matched, read
`--mirror` as a force and a delete, and read the `@{push}` target
against the configured remote names. A differential against the previous
guard found no deny-to-allow flip
- #3032 subtracts every thread id an open entry links, back-references
included, from the earlier threads `pr_review.py`'s headline shortfall
counts, so a back-referenced thread is no longer counted twice
- #3035 covers the bootstrap upgrade handoff on Linux and Windows, the
root and elevated skips included, and has `bootstrap.ps1` say when the
agent tools report fails
- #3037 makes `gh-write-guard` fail closed when a push target resolves
but the remote names cannot be read

After this merges, the host-safety installer payload changes, so the
maintainer runs the installer after promotion.

Fixes #3009
Fixes #2985
Fixes #3003
Fixes #2993
Fixes #3016
Fixes #3005
Fixes #3007
Fixes #2973

🤖 Generated with [Claude Code](https://claude.com/claude-code)
ptr727 added a commit that referenced this pull request Oct 15, 2026
… Narrative Findings, and Bootstrap Handoff Tests to Main (#3051)

- #3042 brings the agent-safety READMEs up to the write guard's #3023
and #3037 readings: `--prune` beside a pattern, `:`, `--all`, or a bare
push, a `--mirror` push with no refspec, a `heads/` destination outside
`refs/`, the full `@{push}` read, and a bare push denied when `git
remote` cannot list the remotes
- #3041 has `backlog-burndown` keep an abandoned group's claim comment
until cleanup decides its release, say stopped on each path that sends a
group to the maintainer, and name a branch no pull request has used when
a claim comment first names it
- #3044 tests `bootstrap.sh`'s `--report` handoff to the agent tools
step, tests the `--agents` handoff on Linux and through
`Invoke-AgentsInstall` under `pwsh`, and moves the unprivileged-root
probe into `tests/host_capability.py`
- #3045 makes `pr_review.py` read an `Open findings remain:` list in a
Copilot review and count each entry no thread of the round accounts for,
pairing by severity tier and file, so the count can only rise
- #3049 makes `gh-write-guard` read a bare push's destination from
`push.default` and `branch.<name>.merge`, read a persisted
`remote.<name>.mirror`, deny when the `@{push}` read times out or cannot
run, give a dash-named word after `--` or `--end-of-options` a reading
as a remote or refspec, and judge a push moved into another checkout
against that checkout's origin as well. A differential against the
previous guard found no deny-to-allow flip. It addresses one item of
#2943, which stays open
- #3054 makes `gh-write-guard` answer unresolved, and so deny, when its
`push.default` read times out or cannot run, a promotion fix for this
pull request's first review
- #3062 brings both agent-safety READMEs up to #3054: an unset
`push.default` is read as `simple`, both destinations are read for a
value git does not define or a read exiting with any other error, and a
read that times out or cannot run is denied
- #3059 bumps `actions/create-github-app-token` from 3.2.0 to 3.3.0

After this merges, the host-safety installer payload changes, so the
maintainer runs the installer after promotion.

Fixes #3021
Fixes #3026
Fixes #3027
Fixes #3039
Fixes #3033
Fixes #3038
Fixes #3034
Fixes #3031
Fixes #3019
Fixes #3020
Fixes #3029
Fixes #3036
Fixes #3052

🤖 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