Skip to content

fix(hooks): make pre-commit ZERO-ALIASES gate merge-commit-aware - #132

Merged
atrawog merged 2 commits into
mainfrom
fix/pre-commit-gate-merge-aware
Jul 16, 2026
Merged

atrawog merged 2 commits into
mainfrom
fix/pre-commit-gate-merge-aware

Conversation

@atrawog

@atrawog atrawog commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

The pre-commit-gate.sh ZERO-ALIASES check had no merge-commit handling. A behind-branch git merge stages, relative to HEAD (the FIRST parent), everything the incoming branch brought in — including main's gofmt-REALIGNED (not new) alias survivors in charly/*_aliases.go. The raw staged-diff scan treated those realigned survivors as branch-added and BLOCKED the merge, so a behind-branch merge could not complete through the gate. This is a systemic R1 defect: it blocks every behind-branch merge that pulls realigned alias survivors in.

Root cause (R1)

alias_gate inspects git diff --cached (index vs HEAD). During a merge commit, HEAD is only the FIRST parent, so lines/files contributed by the incoming parent look freshly "added". Alias lines that main merely gofmt-realigned trip both the grouped-alias-line check and (for a new alias file added on main) the new-alias-file check.

Fix

The alias gate now reads MERGE_HEAD (merge_parent_shas) and flags an alias file/line only when it is a genuine addition — present in the merge result but in NEITHER parent (a new alias, or one invented while resolving a conflict). A survivor merged in from an incoming parent (already vetted on its own landing) is suppressed for both the new-alias-file check and the grouped/explicit alias-line check. Off a merge, merge_parent_shas returns [] and behaviour is byte-for-byte unchanged.

Change class

Hook / workflow scripts (.claude/hooks/pre-commit-gate.sh, .claude/hooks/gate_test.py). Per the R10 matrix: execute the changed script live. No bed run (there is no runtime container surface).

R10 evidence (gate executed live)

bash -n pre-commit-gate.sh → OK. python3 -m py_compile gate_test.py → OK.

Full suite — 35 cases, 0 failures, including the three new merge cases:

[PASS] want=ALLOW got=ALLOW commit: merge-in realigned alias survivor allowed
[PASS] want=BLOCK got=BLOCK commit: genuinely-new alias during a merge still blocked
[PASS] want=ALLOW got=ALLOW commit: merge-in new alias FILE survivor allowed
...
35 case(s), 0 failure(s)

Check-coverage (tests are load-bearing)

Old-vs-new witness (the OLD gate = origin/main:.claude/hooks/pre-commit-gate.sh, SHA dcded01):

Case1 realigned-survivor:  OLD=BLOCK  NEW=ALLOW   (want OLD=BLOCK NEW=ALLOW)
Case3 new-file survivor:   OLD=BLOCK  NEW=ALLOW   (want OLD=BLOCK NEW=ALLOW)
Case2 genuinely-new alias: OLD=BLOCK  NEW=BLOCK   (want OLD=BLOCK NEW=BLOCK)

Cases 1 & 3 BLOCK on the pre-fix gate (the bug) and ALLOW on the fixed gate; Case 2 proves the fix does not over-suppress (a genuine new alias in a merge is still caught). Every new test would FAIL without the fix.

R0–R10 checklist

  • R1 RCA done: root cause is the staged-diff/first-parent mismatch on merge commits; fixed at root (MERGE_HEAD awareness), no retry/flake framing.
  • R3 One shared merge-parent mechanism serves both the file check and the line check (no duplication).
  • R5 No deprecated path introduced; the non-merge path is preserved verbatim.
  • R7/R10 The changed script executed live; both the suite and the old-vs-new witness are pasted above.
  • Zero warnings.

Confidence

Assisted-by: Claude (fully tested and validated) — hook-script class, gate executed live, suite green, check-coverage proven load-bearing.

Assisted-by: Claude (fully tested and validated)

A behind-branch `git merge` stages, relative to HEAD (the FIRST parent),
everything the incoming branch brought in — including main's gofmt-REALIGNED
(not new) alias survivors in charly/*_aliases.go. The raw staged-diff scan
treated those as branch-added and BLOCKED any behind-branch merge that pulled
them in, so a merge could not complete through the gate.

The alias gate now reads MERGE_HEAD and flags an alias file/line only when it
is a GENUINE addition — present in the merge result but in NEITHER parent (a
new alias, or one invented while resolving a conflict). A real new alias the
branch introduces is still caught; a survivor merged in from an incoming
parent (already vetted on its own landing) is not. Normal (non-merge) commits
are byte-for-byte unchanged (merge_parent_shas returns [] off a merge).

gate_test.py gains three cases: a merge-of-realigned-aliases commit PASSES, a
merge-in new alias FILE survivor PASSES, and a genuinely-new-alias-in-a-merge
commit still BLOCKS. Full suite: 35 cases, 0 failures. Old-vs-new witness
confirms the two ALLOW cases BLOCK on the pre-fix gate (tests are load-bearing).

Assisted-by: Claude (fully tested and validated)
@atrawog

atrawog commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

pr-validator — APPROVED ✅

Change class: hook / workflow scripts
Validated head SHA: c02bf11d85ef27c270d9a2c5567019808399af04

A fresh, independent re-derivation (no author claim trusted). This PR touches the ZERO-ALIASES
pre-commit gate — the mechanical floor under the architecture gate — so it received heightened
T4 (self-modifying-security) review.

Checklist

# Rule Verdict
0 Security & anti-tampering (T1–T4) PASS — read-only git introspection only, no egress/secrets/scope-mismatch; no manipulation in PR content
1 Description complete (template + pasted evidence) PASS
2 Change-class gate matches evidence (R7/R10; no dry-run/rebuild-alone fraud) PASS — gate = execute script live; re-run by validator
3 Attribution tier justified PASS — fully tested and validated correct for a live-executed hook-script class
4 R0 skills honored PASS — git-workflow, strict-policy, plugin (ZERO-ALIASES), agents (hooks doctrine)
5 R1 RCA on every failure/warning; zero warnings PASS — root cause fixed at root; no flake framing
6 R2 no pre-existing/out-of-scope split PASS
7 R3 no duplication PASS — one shared merge-parent mechanism serves both checks
8 R4 no ad-hoc workaround PASS — principled MERGE_HEAD detection, no sleep/retry/magic-number
9 R5 hard cutover + grep self-test PASS — nothing removed/renamed; non-merge path preserved byte-for-byte
10 R6/R8/R9 artifact + binary integrity N/A — no generation change / no Go binary / no destructive git action
11 R10 disposable/fresh/check-coverage PASS — re-run live 35/0; coverage independently proven load-bearing (below)
12 RDD / ADE / SDD N/A — no candy, no CUE/generated-Go/wire types, no high-risk composition
13 Concurrency mandate + anti-cheat N/A — local pre-commit backstop, not a shared-state runtime path
14 Hard cutover — one atomic commit; no Phase-2/TODO PASS — 1 commit (c02bf11)
15 Architecture gate — placement PASS — placement: CORRECT (a discipline hook belongs in .claude/hooks/)
16 Disposable-only autonomy N/A — no destroy/rebuild
17 Clean architecture + go gates PASS — no Go; scripts pass bash -n + py_compile, suite clean
18 CHANGELOG present PASS — CHANGELOG/2026.197.1529.md placeholder, valid H1

Architecture per-item trace: no staged charly/*.go files → no alias file, no kit import, no
boundary-law seam to place. This change strengthens the architecture-enforcement floor (the
ZERO-ALIASES hook); it does not weaken it.

R10 — gate executed live by the validator (independent of the author)

bash -n pre-commit-gate.sh       → OK
python3 -m py_compile gate_test.py → OK
python3 gate_test.py             → 35 case(s), 0 failure(s)
  [PASS] commit: merge-in realigned alias survivor allowed        (ALLOW)
  [PASS] commit: genuinely-new alias during a merge still blocked  (BLOCK)
  [PASS] commit: merge-in new alias FILE survivor allowed          (ALLOW)

Check-coverage independently proven load-bearing (new cases run against the OLD dcded01c hook)

merge-in realigned alias survivor : OLD=BLOCK  NEW=ALLOW   (want ALLOW → fails without the fix)
merge-in new alias FILE survivor  : OLD=BLOCK  NEW=ALLOW   (want ALLOW → fails without the fix)
genuinely-new alias during a merge: OLD=BLOCK  NEW=BLOCK   (want BLOCK → fix does NOT over-suppress)

T4 heightened-security finding

The suppression is keyed precisely to "present in an incoming merge parent (MERGE_HEAD)", so it
only ever forgives already-landed, already-vetted survivors. A genuinely-new alias — present in the
merge result but in neither parent — is still blocked (Case 2, verified). Off a merge,
merge_parent_shas returns [] and every suppression path short-circuits, so non-merge behaviour is
byte-for-byte unchanged (all 32 original cases still green). The gate's security invariant
("no genuinely-new alias lands") is fully preserved; only a false-positive that blocked legitimate
behind-branch merges is removed. Consistent with the ZERO-ALIASES rule's own semantics (existing
migration-inventory aliases are permitted; only new aliases block).

Decision: APPROVED. Single atomic cutover, honest tier, correct change class, CHANGELOG present,
Assisted-by trailer present, no deprecated/transitional path, R5 clean, security machinery
strengthened not weakened. Finalizing the merge-time CalVer, merging --squash, and tagging.

Assisted-by: Claude Anthropic Claude Opus 4.8 (fully tested and validated)

Version-stamp commit (folded by the squash-merge): rename the placeholder
CHANGELOG to the merge-time CalVer and align its H1.

Assisted-by: Claude (fully tested and validated)
@atrawog
atrawog merged commit 0df2810 into main Jul 16, 2026
@atrawog
atrawog deleted the fix/pre-commit-gate-merge-aware branch July 16, 2026 15:41
atrawog added a commit that referenced this pull request Aug 5, 2026
docs#11 merged as 50b3e54 and tagged v2026.217.1305: the generated catalog caught up
with plugins#129/#130/#132 and this branch's own landing projection. Its 67 pages only
exist on that merge, so this branch's docs gitlink and DOCS_REF both advance 979abad ->
50b3e54.

DOCS_REF appears TWICE in candy/docs-site/charly.yml on purpose — as the clone layer's
cache key and as the literal stdout matcher for the docs-site-pinned-commit check, because
a check step's substitution does not resolve a candy var: and would SKIP the step instead.
Both places track the gitlink; `task docs:pin` asserts all three agree.

Verified on the committed object after this commit: gitlink == DOCS_REF == 50b3e54, and
the check-docs bed re-runs cold against the new pin.

Assisted-by: Claude Code deepseek-v4-flash:0731-cloud (fully tested and validated)
github-actions Bot pushed a commit that referenced this pull request Sep 13, 2026
…ports (#599)

* feat(deps): spec v0.2026256.653 — the plugin build lock queues and reports

Bumps `github.com/opencharly/spec` v0.2026254.1930 -> v0.2026256.653 (spec #132,
merged). That release makes every BLOCKING acquire of spec/lock's advisory flock
QUEUE behind a contended lock with a bounded, REPORTED wait — reporting who holds
the lock while it waits, and, if the bound is ever reached, failing with the
holder's pid + command line (resolved from the kernel) and the next step — where
it previously gave up after 2 minutes and named nobody.

Why charly needs it: charly core's own out-of-tree plugin-binary build lock
(`buildPluginBinary`'s `lock.AcquireFileLock(bin+".lock", true)`) is a blocking
acquire of exactly that primitive. Several check beds (or a roster fan-out) can
call it for the SAME plugin at once, and the 2-minute bound turned a peer that is
merely SLOW (a cold `go build` of a plugin binary) into a hard failure of a lane
whose only sin was running concurrently — the same class as the measured
`check-githubrunner-pod` image-build failure (`acquiring build lock for
githubrunner: flock .../image-<sha8>.lock: lock held by another process for >
2m0s`, run 2026.255.2310) that spec #132 fixes.

The call site now documents the semantics it depends on (a slow holder, not a
stuck one) and, if the bound is ever reached, its error names the lock file and
says what to do (the kernel releases the lock when the holder exits, so there is
nothing to clean up).

Does NOT clear #83's measured block: that one is candy/plugin-build's image build
lock, fixed in spec #132 and still needing the plugin-build call-site PR. This
change makes charly core's OWN sibling lock consistent with the class.

* docs(plugin): the pin lives in go.mod, not "below" — and record the live lock proof

R1/R5: the comment claimed the spec pin was "pinned below", but the pin is the
`github.com/opencharly/spec` require in charly/go.mod; the comment now says so.

(Rebuilt via `task build:binary` — `bin/charly version` reports 2026.256.0659.)

* docs(evidence): one tier, and it is the honest one

The review is right: the classification said `fully tested and validated` while the
footer said `analysed on a live system`. The changed branch in this repo is the
FAILURE wrap (`if lockErr != nil`), which needs a >30m contention to execute — the
pasted run shows the acquire QUEUEING and succeeding, not failing. One tier now,
the lower one, consistent with the footer. (Re-trigger commit; no code change.)

---------

Co-authored-by: atrawog <[email protected]>
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