Skip to content

Fail Closed on an Unread Write Target With No Origin - #3297

Merged
ptr727 merged 3 commits into
developfrom
feature/guard-no-origin-unread-target
Oct 21, 2026
Merged

ptr727 merged 3 commits into
developfrom
feature/guard-no-origin-unread-target

Conversation

@ptr727

@ptr727 ptr727 commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Summary

With no resolvable origin, the write guard now fails closed on a gh write whose target it does not read. That covers a gh write an eval runs, a gh api write to a repositories/<id> endpoint, and a gh api write through a .. segment. A literal target keeps the no-origin allow, since there is no owner to compare it against. The run-time-word check and the cross-owner comparison stay inside the origin branch.

Changes

  • classify() in host-setup/agent-safety/claude/gh-write-guard.py calls _gh_unread_target after the if origin: block rather than inside it. With an origin resolved, the check order and every decision are unchanged. The comment above the block now states which checks need an origin.
  • A new _NO_ORIGIN_CASES table and _no_origin_selftest() run with _origin_owner_repo pinned to resolve nothing. The pin is restored in a finally. The table holds deny cases for each unread shape and allow cases for a literal cross-owner target, a write naming no target, a run-time --repo, and reads.
  • host-setup/agent-safety/README.md requirement 3 and the "Opaque targets are unseen" bullet in host-setup/agent-safety/claude/README.md now state the no-origin posture: the owner comparison and the run-time-word check are skipped, and an unread target still fails closed.

Scope Note for the Maintainer

_gh_unread_target also covers a write taking its repository from a GH_REPO that an unread builtin sets, such as declare -x, read, set -a, an eval, or GH_REPO+=. That shape moves with the call. So outside a checkout, declare -x GH_REPO=stranger/example; gh pr comment 5 -b x is now denied, though the value is written out. This fits "an unread target fails closed", since the hook does not read those builtins. It may differ from what "literal targets keep the no-origin allow" meant. The self-test pins the deny so either answer is a one-line change.

Verification

  • python3 host-setup/agent-safety/claude/gh-write-guard.py --selftest: SELFTEST PASS, including every new no-origin case.
  • python3 host-setup/agent-safety/claude/test_install.py: OK.
  • Revert proof: a scratch copy of this branch's guard with only the code move undone (tests kept) fails exactly the four no-origin deny cases (eval, repositories/<id>, .. segment, declare -x GH_REPO), each read as allow. The working tree was never reverted.
  • Develop-versus-branch differential: develop's guard, loaded from git show origin/develop:... into a fresh mktemp -d, and this branch's guard classified the same constructed corpus under timeout. The corpus is every command in the guard's *_CASES tables plus the no-origin cases, classified with two resolved origins and with no origin. Every flip is allow to deny, with no origin, through the unread-target deny message. There are zero deny-to-allow flips and zero flips with an origin resolved. The flipped forms are the eval write, the repositories/<id> endpoint, the .. segment, and the unread-builtin GH_REPO shapes.
  • Gates: prose_lint.py --diff origin/develop (with --check sentence-length too), repo_gate.py --check eol and eol-coverage, docker_lint.py, spec/validate.py, and ruff check plus ruff format --check.
  • Local strict review: three recorded passes. The first found sentence-length lines, a closed rule list on line 158 of the claude README, and an ambiguous pronoun, all fixed. The second found an unreflowed docstring and a comment narrower than the code, both fixed. The third found nothing.

The comment lines this change adds need the comments label.

Closes #3288

🤖 Generated with Claude Code

ptr727 and others added 3 commits October 20, 2026 18:47
With no resolvable origin, the write guard now denies a gh write whose
target it does not read: a gh write an eval runs, a gh api write to a
repositories/<id> endpoint or through a .. segment, and a write taking
its repository from a GH_REPO an unread builtin sets. A literal target
and a run-time-word target keep the no-origin allow, since there is no
owner to compare them against.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Split the sentences the length check flagged, drop the closed list of
rules a non-git write meets, and name the no-origin case directly
rather than through a pronoun.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings October 21, 2026 01:54
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Oct 21, 2026
@ptr727

ptr727 commented Oct 21, 2026

Copy link
Copy Markdown
Owner Author

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

@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

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

⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 10f18240-7529-41fd-82ed-281cada11c1b
  • 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.

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

No unresolved issues were identified across the reviewed files.

No open issues 🎉

What changed in this PR

Updates the GitHub write guard to fail closed on unread targets when no repository origin resolves.

Changes:

  • Moves unread-target detection outside origin-dependent checks.
  • Adds no-origin self-test coverage.
  • Documents the updated behavior.
File Summary
host-setup/​agent-safety/​README.md Documents no-origin handling.
host-setup/​agent-safety/​claude/​README.md Clarifies opaque-target behavior.
host-setup/​agent-safety/​claude/​gh-write-guard.py Implements and tests fail-closed behavior.

Review effort: Lite

@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@a86e92c). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #3297   +/-   ##
==========================================
  Coverage           ?   65.49%           
==========================================
  Files              ?       17           
  Lines              ?    10011           
  Branches           ?        0           
==========================================
  Hits               ?     6557           
  Misses             ?     3454           
  Partials           ?        0           
Flag Coverage Δ
python-3.13 65.49% <ø> (?)

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 390e225 into develop Oct 21, 2026
14 checks passed
@ptr727
ptr727 deleted the feature/guard-no-origin-unread-target branch October 21, 2026 02:15
ptr727 added a commit that referenced this pull request Oct 21, 2026
…ixes to Main (#3299)

## Summary

Promotes these pull requests from develop.

- [#3297](#3297): the
write guard fails closed on an unread write target when no origin
resolves.
- [#3296](#3296): fixes
and pins the Docker task workflow test reader's known limits.
- [#3295](#3295): corrects
the smoke stub's `enable_*` description in the caller-stub paragraph.
- [#3293](#3293): carries
a command the user must run inside the prompt's own question.
- [#3291](#3291): matches
session-handoff's platform-lane exception to the fix-and-verify rule.

Closes #3288
Closes #3280
Closes #3282
Closes #3284
Closes #3275

🤖 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

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants