Skip to content

Add an escape-hatch ratchet and a .ub/ tamper guard - #17

Merged
0xjgv merged 4 commits into
mainfrom
ub-ratchet-guard
Nov 21, 2026
Merged

0xjgv merged 4 commits into
mainfrom
ub-ratchet-guard

Conversation

@0xjgv

@0xjgv 0xjgv commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Why

Agents can pass the CRAP, duplication, and mutation gates by switching a check off instead of fixing the code. They can also edit .ub/check itself. This is slice 1 of the maintainability roadmap: an anti-gaming ratchet and a tamper guard.

What

  • ub ratchet
    • Counts escape hatches per kind in every file Git tracks or would track, tests included: lint ignores, coverage exclusions, and skipped or focused tests, for Python, JS/TS, and Java.
    • Fails when a count exceeds .ub/ratchet, listing every current file:line of that kind.
    • Python string literals are blanked before matching. Skip rules ignore comments.
  • ub check runs the ratchet before coverage. A growth fails the verdict, and the other gates still run and report.
  • ub ratchet --update writes the counts, and ub init writes .ub/ratchet when it is absent.
  • ub ratchet --guard --base REF [--head REF]
    • Fails when commits change .ub/check (content or mode), delete .ub/ratchet, or raise a count, and when .ub/ has uncommitted changes.
    • Exits 2 without a merge base.
    • UB_ALLOW_UB_CHANGE=1 is the human override.
  • Pre-push hook
    • Guards each pushed branch against the remote's default branch, running the guard from the installed ub, not .ub/check.
    • Replays Git's ref list to the original hook.
    • ub hooks install upgrades the old block.
  • Stop hook warns the human, without blocking, when .ub/ has uncommitted changes.
  • README gains the ratchet section, the CI step with a label-based override, CODEOWNERS advice, exit codes, and known limits.
  • SKILL.md and the managed instructions tell agents never to run --update or edit .ub/ unless asked.
  • After review for strictness:
    • A failure lists the matches in files with uncommitted changes (the likely new ones) and how to remove or accept them.
    • exclude GLOB lines in .ub/ratchet skip vendored or generated files; the guard fails when one is added.
    • ub ratchet --lower lowers counts and never raises them; agents run it after removing escape hatches.
  • cli.run dispatches through a table, which brings it under the complexity limit.

Verification

  • make test: 151 tests pass.
  • make gate
    • ratchet.py has no surviving or uncovered mutants, and every function is under CRAP 10.
    • The gate still fails, as it does on main, on hooks/project functions whose tests run in child processes. Failing items dropped from 137 on main to about 115.
  • End to end in a scratch repo:
    • ub init writes the ratchet.
    • A new @unittest.skip fails ./.ub/check with its file:line.
    • A raised count fails the guard, and the override passes it.
    • A shallow clone exits 2.
    • A staged .ub/ edit triggers the Stop notice.
    • A real git push with a raised count is refused.
  • The change went through two rounds of dx self-review and one independent review. Their findings are fixed, except two that are now documented limits.

Known limits

  • Counts:
    • Moving or widening a hatch keeps the count the same.
    • Configuration-file hatches, such as per-file ignores and coverage omit, are not counted.
    • In JS/TS and Java, quoted or commented-out directives still count.
    • Go, Rust, and Clojure are not covered.
  • Enforcement:
    • The local hook is advisory. An agent can use --no-verify or set the override. CI plus CODEOWNERS on /.ub/ and the workflows is the real gate.
  • Not tested:
    • Windows, Linux CI, and the native build.

ub ratchet counts lint suppressions, coverage exclusions, and skipped
tests in every file Git lists, and fails when a count grows past the
human-owned .ub/ratchet. ub check runs it first and keeps running the
other gates. ub init writes .ub/ratchet when it is absent.

ub ratchet --guard --base REF fails when commits change .ub/check,
delete .ub/ratchet, or raise a count, and on uncommitted .ub/ edits.
The pre-push hook runs it from the installed ub for each pushed branch.
The Stop hook warns the human when .ub/ has uncommitted changes.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T11:48:38.827118Z 32042bc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

The Stop and init helpers now run in the measured process, so their
mutation sites count. Assert the empty-stderr Git message, a second
ratchet write, nested parent creation, and a failing ps. Drop the
unused managed_block default, text=True, and the <= that only
equivalent mutants could change.
…teps

A ratchet failure lists the grown kind's matches in files with
uncommitted changes, and the count elsewhere; without such files, as in
CI, it lists all of them. It ends with how to remove or accept them.

.ub/ratchet takes `exclude GLOB` lines for vendored or generated files.
`ub ratchet --update` keeps them; the guard fails when one is added.

`ub ratchet --lower` lowers counts and never raises one or adds an
exclude, so agents run it after removing escape hatches and the slack
each removal left is gone.
@0xjgv
0xjgv merged commit e789bf3 into main Nov 21, 2026
1 of 2 checks passed
@0xjgv
0xjgv deleted the ub-ratchet-guard branch November 21, 2026 21:01
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.

1 participant