Skip to content

fix(hooks): keep the pre-commit-gate lint cache on the root fs - #263

Merged
atrawog merged 4 commits into
mainfrom
feat/hook-gate-lint
Aug 13, 2026
Merged

atrawog merged 4 commits into
mainfrom
feat/hook-gate-lint

Conversation

@atrawog

@atrawog atrawog commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Change class

Code/config (the pre-commit-gate hook + its behavioral test suite).

What

The pre-commit-gate hook's golangci-lint run forced GOCACHE into a tempfile.TemporaryDirectory under /tmp and left Go's $WORK at the default /tmp. On hosts where /tmp is a small tmpfs (or a sandbox caps its writes), the lint build exceeds the quota and the gate fails environmentally — a clean tree cannot commit. This redirects the lint temp dirs to a per-user root-fs cache (~/.cache/charly-gate-lint/) and sets GOTMPDIR/TMPDIR so Go's build work and golangci-lint's own temp files follow.

  • .claude/hooks/pre-commit-gate.sh: lint_staged_go creates ~/.cache/charly-gate-lint/ and runs each module's golangci-lint inside a TemporaryDirectory rooted there, with GOCACHE/GOLANGCI_LINT_CACHE/GOTMPDIR/TMPDIR set to subdirs it creates first. The subdir creation is load-bearing: golangci-lint v2 locks at $TMPDIR/golangci-lint.lock, and a missing TMPDIR makes the lock open fail with ENOENT, which golangci-lint reports as "parallel golangci-lint is running" — a false positive that blocks every commit on hosts where the dir does not pre-exist. The cache-root creation is fail-open: a HOME that cannot be written falls back to the system temp dir (the pre-fix behavior) rather than blocking the commit.
  • .claude/hooks/gate_test.py: a red/green pair proving the lint cache lands on the root fs — with HOME redirected to a temp dir, a lint-clean Go commit passes the gate AND ~/.cache/charly-gate-lint/ is created under the redirected HOME (the pre-fix hook never created it). 37 cases, 0 failures.
  • candy/charly-hooks/charly.yml (the source of truth): both hook entities — the pre-commit-gate: content and the gate_test.py AUX entity — carry the same fix. .claude/hooks/* are GENERATED from these entities by charly marketplace generate; a regeneration after a hand-edit-only fix would have reverted it (verified: the first regenerate dropped the new gate_test.py case). With the candy updated, charly marketplace generate is a no-op on this tree — the emitted files are byte-identical to the committed ones, so the fix survives regeneration.
  • CHANGELOG/2026.225.0000.md: the cutover entry (placeholder CalVer, finalized by the pr-validator at merge).

How R10-tested

The hook is a deterministic command-mechanics gate; the change-class gate is the behavioral test suite that drives the actual hook script against fixture repos. Run from the worktree with a root-fs TMPDIR (the test's temp HOME must not sit on the capped /tmp):

python3 .claude/hooks/gate_test.py:

[PASS] want=ALLOW got=ALLOW commit: lint-clean Go with redirected HOME allowed
[PASS] want=True  got=True  commit: lint cache dir created under the redirected HOME
...
37 case(s), 0 failure(s)

Red arm (the new cache-redirect case against the pre-fix hook — the assertion that ~/.cache/charly-gate-lint/ is created under the redirected HOME fails, proving the test would fail without the change):

[FAIL] want=True  got=False commit: lint cache dir created under the redirected HOME
37 case(s), 1 failure(s)

Live: the spec follow-up commit (opencharly/spec#26) passed through the fixed hook with golangci-lint running clean on the staged Go module.

Attribution tier

analysed on a live system — the changed runtime path (the hook's lint-temp-dir redirect) ran live: the full behavioral gate suite passed with pasted output above, and the red/green pair proves the new coverage fails without the change. The complete fresh-rebuild R10 (a disposable bed) does not apply to a hook change — the hook is exercised by the gate suite itself.

Harness rulebook compliance

  • R0 — Skills first: loaded /charly-internals:go-quality (the pre-commit-gate hook paragraph + the golangci-lint lock finding) before editing the hook.
  • R1 — RCA every anomaly: the environmental failure (a clean tree cannot commit on a sandboxed-/tmp host) was RCA'd to the hook forcing GOCACHE/$WORK onto the capped /tmp; the fix redirects them to the root fs. The "parallel golangci-lint is running" false positive was RCA'd to golangci-lint v2's $TMPDIR/golangci-lint.lock ENOENT lock-open error.
  • R2 — Finish the whole cutover: the hook fix + the test coverage + the CHANGELOG land in this one PR; the skill codification of the same finding is the cross-repo docs cutover (plugins fix(command): restore nested CLI grammar for check/box-list (F-CLI-NEST) #160 + charly chore(settings): drop the PreToolUse Bash hooks + docs(internals): sandboxed-/tmp env constraints #264).
  • R3 — No duplication: the cache-redirect behavior is implemented once in the hook and asserted once in the gate suite.
  • R4 — No workarounds: the fix is a real redirect of the lint temp dirs to the root fs, not a sleep/retry/shim.
  • R4a — Fix the product first: the hook (the product) is fixed; no docs route around the defect.
  • R5 — Delete legacy completely: no removed identifiers; the pre-fix behavior (system temp dir) survives only as the fail-open fallback.
  • R6 — Git safety: branch-per-change (feat/hook-gate-lint), no force-push, no direct push to main; PR-only landing.
  • R7 — Prove behavior, not compilation: the gate suite drives the actual hook script against fixture repos (behavioral), not a compile check.
  • R8 — Verify emitted artifacts: N/A — the hook emits no Containerfile/labels.
  • R9 — Binary equals source: N/A — the hook is a shell/Python script, not a built binary.
  • R10 — Fresh disposable proof: the hook is a deterministic command-mechanics gate; its change-class gate is the behavioral gate suite, which passed at zero failures with the red/green pair proving the coverage fails without the change.
  • Hooks doctrine: the hook remains a deterministic command-mechanics gate only — no reminder layer, no rule-body restatement.

Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)

The pre-commit-gate hook's golangci-lint run forced GOCACHE into a
tempfile.TemporaryDirectory under /tmp and left Go's $WORK at the default
/tmp. On hosts where /tmp is a small tmpfs (or a sandbox caps /tmp writes),
the lint build exceeds the quota and the gate fails environmentally — a
clean tree cannot commit. This redirects the lint temp dirs to a per-user
root-fs cache (~/.cache/charly-gate-lint/) and sets GOTMPDIR/TMPDIR so Go's
build work and golangci-lint's own temp files follow.

Also create the TMPDIR/GOTMPDIR subdirs before running golangci-lint:
golangci-lint v2 locks at $TMPDIR/golangci-lint.lock, and a missing TMPDIR
makes the lock open fail with ENOENT, which golangci-lint reports as
"parallel golangci-lint is running" — a false positive that blocks every
commit on hosts where the dir does not pre-exist.

Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)
@atrawog

atrawog commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

pr-validator — CHANGES REQUESTED ❌

Change class: hook/workflow (dev-tooling gate — .claude/hooks/pre-commit-gate.sh)

Head SHA validated: d56dc1ca293d751a50e132d006e17c12e522861c

The change itself is technically sound — I independently verified it (details below). But the PR FAILS on three checklist items: the body does not follow the mandatory PR template, the change ships no test coverage for its new behavior, and no CHANGELOG entry is staged. Per the rulebook, a single failed item blocks the merge.

Checklist

  • [PASS] 0. Security & anti-tampering (T1–T4). The diff is a focused, 20-line hook change. No exfiltration, no scope mismatch (the diff matches the description exactly), no supply-chain change, no embedded directives aimed at me. The change touches the pre-commit-gate hook (a security gate) but strengthens it — it makes the gate work on hosts where /tmp is a capped tmpfs — and matches its stated intent. No T4 concern.
  • [FAIL] 1. Description completeness. The body does not follow the mandatory PR template (opencharly/.github/.github/PULL_REQUEST_TEMPLATE.md). It is a free-form prose description with none of the required sections: no ## Summary of changes, no ## Change class, no ## How R10-tested (with pasted output), no ## Attribution tier, and no ## Harness rulebook compliance (R0–R10 answered with a one-line HOW). The only verification claim — "Verified live: the spec follow-up commit (feat(spec)!: complete the packaging contract — Packaging() accessor + CandyDir + LocalPkgBuildContext spec#26) passed through the fixed hook" — carries no pasted output. The template states the validator FAILS a body that "pastes no R10 output" or "leaves any applicable section blank". The *Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)* footer is present and correctly formed, but the rest of the template is absent.
  • [FAIL] 2. Change-class gate. The class (hook/workflow → non-runtime standards + live hook run) is correctly identified, but the body supplies no pasted evidence of the gate run. The template requires the exact recipe + pasted output, not a summary.
  • [PASS] 3. Attribution tier. The claimed analysed on a live system is the correct ceiling for this change class (the changed hook path ran live — I re-ran it myself and it works), and the identity (Claude Code deepseek-v4-flash:cloud) matches the authoring runtime. Not inflated. (The missing pasted proof is item 1's failure.)
  • [PASS] 4. R0 skills. Honors /charly-internals:go-quality (which documents the pre-commit-gate hook as the mechanical lint backstop) and /charly-internals:agents (hooks doctrine). No contradiction with any skill.
  • [PASS] 5. R1 RCA. The change is itself an RCA-driven fix with a clear root cause (tmpfs quota on the lint build + golangci-lint v2's ENOENT lock-open reported as "parallel golangci-lint is running"). No warnings introduced.
  • [PASS] 6. R2. No out-of-scope split; the change is one focused fix.
  • [PASS] 7. R3. No duplication introduced.
  • [PASS] 8. R4. The fix is a root-cause fix (cache relocation + subdir creation), not a sleep/retry/magic-number workaround.
  • [PASS] 9. R5. No removed/renamed identifiers, no transitional/dual-mode path.
  • [PASS] 10. R6/R8/R9. N/A — no destructive git action, no generation change, no binary change.
  • [FAIL] 11. R10 coverage. The change ships no test coverage for its new behavior. .claude/hooks/gate_test.py (290 lines) has zero references to lint_staged_go, TemporaryDirectory, GOCACHE, GOTMPDIR, TMPDIR, or cache — the new cache-redirect + subdir-creation behavior has no test that would fail without it. The body's live-run claim has no pasted output. (The existing gate_test.py still passes 35/35 with the change — I ran it — but that proves no regression, not the new behavior.)
  • [PASS] 12. RDD/ADE/SDD. N/A — no candy/schema changes.
  • [PASS] 13. Concurrency mandate. N/A — no shared-state path touched; the hook is a local dev gate.
  • [PASS] 14. Hard cutover. One atomic commit; no Phase-2/TODO.
  • [PASS] 15. Architecture gate. placement: CORRECT — the change is dev tooling in .claude/hooks/, the right layer. No charly/*.go changes, so no per-item trace is required.
  • [PASS] 16. Disposable-only. N/A — no destroy/rebuild.
  • [PASS] 17. Clean architecture + Go gates. N/A — no Go changes (shell/Python hook only).
  • [FAIL] 18. CHANGELOG. No CHANGELOG/<CalVer>.md staged. The established convention requires a CHANGELOG entry for hook/workflow changes (precedent: commits 0df28105 and 8754530e, and CHANGELOG entry 2026.193.2003 which codified "a CHANGELOG entry at EVERY legal tier").

What I independently verified (the change works)

  • The cache-redirect logic: tempfile.TemporaryDirectory(prefix="charly-gate-lint-", dir=cache_root) creates the temp dir under ~/.cache/charly-gate-lint/ (root fs, not /tmp), and the go-build/golangci-lint/go-work/tmp subdirs are created before golangci-lint runs.
  • The hook end-to-end: with a staged Go change in the self-consistent spec module, the fixed hook ran golangci-lint with the new env vars and exited 0 (commit allowed). (A test in the main tree's charly module blocked on typecheck errors — but those are from the in-flight spec#26 cutover, where the main tree's charly/sdk code references spec.LocalPkg fields not yet in the checked-out spec at Phase 0a; that is a pre-existing cross-repo condition, not a defect in this PR.)
  • bash -n and the hook's embedded Python both parse clean; gate_test.py passes 35/35.

Secondary observation (not blocking on its own)

os.makedirs(cache_root, exist_ok=True) sits outside the try/except in lint_staged_go. In the original code the TemporaryDirectory creation was inside the try, so a temp-dir failure was caught by except Exception: continue (fail-open). Now a cache-dir creation failure (e.g. an unwritable ~/.cache) would propagate unhandled and crash the hook, blocking every commit — a narrowing of the hook's fail-open property for lint-infrastructure failures. Consider moving the makedirs inside the try (or wrapping it) when you revise.

Comments considered: none — the PR carries no comments.

Cross-PR interactions considered:

  • opencharly/charly#262 (docs factory, PROGRAM/factory-north-star.md) — no file overlap with this PR. verified-non-blocking.
  • opencharly/spec#26 (open, in-flight packaging contract) — the main tree's charly/sdk modules do not typecheck against the checked-out spec (Phase 0a) because they reference Phase 0b fields; that is a pre-existing in-flight cutover condition, not introduced by this PR, and the hook change does not interact with spec#26's content. verified-non-blocking.

Decision: FAIL — not merged. The author must:

  1. Rewrite the PR body to follow the mandatory template: ## Summary of changes, ## Change class, ## How R10-tested with pasted output of the live hook run (the exact command + output showing golangci-lint running clean through the fixed hook), ## Attribution tier, and the ## Harness rulebook compliance section with every applicable rule answered with a one-line HOW.
  2. Add test coverage that would fail without the change — a gate_test.py case exercising the cache-redirect/subdir-creation behavior (the existing suite has no coverage of lint_staged_go).
  3. Stage a CHANGELOG/<CalVer>.md entry (placeholder CalVer is fine; the validator finalizes it at merge).

Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)

…-open cache-root creation

The pre-commit-gate hook golangci-lint run forced GOCACHE into a
tempfile.TemporaryDirectory under /tmp and left Go $WORK at the default
/tmp. On hosts where /tmp is a small tmpfs (or a sandbox caps its writes),
the lint build exceeds the quota and the gate fails environmentally — a
clean tree cannot commit. This redirects the lint temp dirs to a per-user
root-fs cache (~/.cache/charly-gate-lint/) and sets GOTMPDIR/TMPDIR so Go
build work and golangci-lint temp files follow.

- lint_staged_go creates ~/.cache/charly-gate-lint/ and runs each module
  golangci-lint inside a TemporaryDirectory rooted there, with
  GOCACHE/GOLANGCI_LINT_CACHE/GOTMPDIR/TMPDIR set to subdirs it creates
  first (golangci-lint v2 locks at $TMPDIR/golangci-lint.lock — a missing
  TMPDIR makes the lock open fail with ENOENT, reported as "parallel
  golangci-lint is running").
- The cache-root creation is fail-open: a HOME that cannot be written falls
  back to the system temp dir (the pre-fix behavior) rather than blocking
  the commit.
- gate_test.py gains a red/green pair: with HOME redirected to a temp dir, a
  lint-clean Go commit passes the gate AND ~/.cache/charly-gate-lint/ is
  created under the redirected HOME (the pre-fix hook never created it).
  37 cases, 0 failures.

Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)
The previous commit fixed the generated .claude/hooks/pre-commit-gate.sh and
gate_test.py by hand. Both are GENERATED from the candy's hook entities by
`charly marketplace generate` — a regeneration would have reverted the fix
(verified: the first regenerate after the hand-edit dropped the new
gate_test.py cache-redirect case). This lands the same change in the source
of truth, candy/charly-hooks/charly.yml:

- the pre-commit-gate hook entity's content now creates
  ~/.cache/charly-gate-lint/ (fail-open on an unwritable HOME), roots the
  lint TemporaryDirectory there, and sets GOCACHE/GOLANGCI_LINT_CACHE/
  GOTMPDIR/TMPDIR to subdirs it creates first (golangci-lint v2 locks at
  $TMPDIR/golangci-lint.lock — a missing TMPDIR is its ENOENT "parallel
  golangci-lint is running" false positive);
- the gate_test.py AUX entity gains the red/green pair proving the lint
  cache lands under a redirected HOME.

`charly marketplace generate` is now a no-op on this tree (the emitted
.claude/hooks/* are byte-identical to the committed files), so the fix
survives regeneration.

Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)
@atrawog

atrawog commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

pr-validator — APPROVED ✅

Change class: hook/workflow (dev-tooling gate — .claude/hooks/pre-commit-gate.sh + its behavioral test suite)

Head SHA validated: 09a3ace0806436151e8781876eb632b1d679a3b7

Fresh independent evaluation — I re-derived every claim from the diff, the repo, and my own re-runs; none of the author's assertions were taken on trust.

Checklist

  • [PASS] 0. Security & anti-tampering (T1–T4). The diff is a focused hook change (4 files). No exfiltration, no scope mismatch (diff matches the description exactly), no supply-chain change, no embedded directives aimed at me. The change touches the pre-commit-gate hook (a security gate) but strengthens it — it makes the gate work on hosts where /tmp is a capped tmpfs — and matches its stated intent. No T4 concern.
  • [PASS] 1. Description complete. The body follows the mandatory template: ## Change class, ## What (accounting for every file), ## How R10-tested with pasted output (green 37/0 + red arm 37/1), ## Attribution tier, and ## Harness rulebook compliance with every applicable rule answered with a one-line HOW (R8/R9 correctly N/A). Ends with the correctly-formed *Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)* footer.
  • [PASS] 2. Change-class gate. Class is hook/workflow; the gate is the behavioral test suite that drives the actual hook script against fixture repos. Pasted output shows 37 cases / 0 failures, plus the red arm proving the new coverage fails without the change. I re-ran both arms myself from the worktree: green 37/0, red (pre-fix hook at 6e9260cd) exactly 1 failure — the new cache-redirect case. No dry-run, no rebuild-alone fraud.
  • [PASS] 3. Attribution tier. analysed on a live system is conservative and not inflated (the matrix ceiling for a hook/workflow change on a clean pass is fully tested and validated, but the PR's evidence supports the conservative claim). Identity matches the authoring runtime.
  • [PASS] 4. R0 skills. Honors /charly-internals:go-quality (the pre-commit-gate hook paragraph + the golangci-lint v2 $TMPDIR/golangci-lint.lock ENOENT finding) and /charly-internals:agents (hooks doctrine). No contradiction with any skill.
  • [PASS] 5. R1 RCA. The change is itself an RCA-driven fix with two named root causes: the hook forcing GOCACHE/$WORK onto a capped /tmp, and golangci-lint v2's lock-open ENOENT reported as "parallel golangci-lint is running". No warnings introduced; the gate suite runs at zero failures.
  • [PASS] 6. R2. No out-of-scope split. The fix + test coverage + CHANGELOG land in this one PR; the skill codification of the same finding is routed to its named batches (plugins fix(command): restore nested CLI grammar for check/box-list (F-CLI-NEST) #160 + charly chore(settings): drop the PreToolUse Bash hooks + docs(internals): sandboxed-/tmp env constraints #264, both OPEN).
  • [PASS] 7. R3. No duplication — the cache-redirect behavior is implemented once in the hook and asserted once in the gate suite.
  • [PASS] 8. R4. The fix is a real redirect of the lint temp dirs to the root fs, not a sleep/retry/magic-number/shim.
  • [PASS] 9. R5. No removed/renamed identifiers; the pre-fix behavior (system temp dir) survives only as the fail-open fallback, which is the intended design, not a transitional path.
  • [PASS] 10. R6/R8/R9. N/A — no destructive git action, no generation change (the hook emits no Containerfile/labels), no built binary.
  • [PASS] 11. R10. The behavioral gate suite is the change-class gate for a hook/workflow change; it passed at zero failures with the red/green pair proving the new coverage fails without the change. I re-ran it myself (green 37/0, red 37/1). The new gate_test.py case (lines 97–121) exercises the cache-redirect/subdir-creation behavior directly: with HOME redirected to a temp dir, a lint-clean Go commit passes the gate AND ~/.cache/charly-gate-lint/ is created under the redirected HOME.
  • [PASS] 12. RDD/ADE/SDD. The candy change (candy/charly-hooks/charly.yml) is a source-of-truth mirror of the hook content — documentation-only, no install content. The candy carries a non-empty description: and a plan: with a check: step (ADE compliant). I verified charly marketplace generate is a no-op on this tree (git status clean after) and all 4 hook entities in the candy are byte-identical to the committed .claude/hooks/*. Note: charly box validate on the candy reports a schema-version mismatch (schema 2026.223.1018 is required (found "")) — I confirmed this is pre-existing and systemic: all candies (charly-hooks, charly-internals, plugin-marketplace) fail identically, the spec gitlink is the same at base and head, and the system charly (2026.223.1347) fails the same way. Not introduced by this PR; does not affect the PR's claim (the candy's function — marketplace generate — works).
  • [PASS] 13. Concurrency mandate. N/A — no shared-state path touched; the hook is a local dev gate.
  • [PASS] 14. Hard cutover. One atomic change; no Phase-2/TODO; the plan is executed as written.
  • [PASS] 15. Architecture gate. placement: CORRECT — the change is dev tooling in .claude/hooks/, the right layer. No charly/*.go changes, so no per-item trace is required.
  • [PASS] 16. Disposable-only. N/A — no destroy/rebuild.
  • [PASS] 17. Clean architecture + Go gates. N/A — no Go changes (shell/Python hook only). I ran bash -n on the hook and a Python parse on the embedded script and gate_test.py — all clean.
  • [PASS] 18. CHANGELOG. CHANGELOG/2026.225.0000.md staged and well-formed: filename matches ^\d{4}\.\d{3}\.\d{4}\.md$, H1 # 2026.225.0000 — keep the pre-commit-gate lint cache on the root fs matches, no v2026.225.0000 tag or CHANGELOG/2026.225.0000.md on main.

Comments considered

  • atrawog (prior pr-validator, CHANGES REQUESTED) — verified-non-blocking. All three demands are addressed in the current head: (1) the body now follows the mandatory template with pasted R10 output; (2) the new gate_test.py case (lines 97–121) provides the red/green coverage that fails without the change — I re-ran both arms myself; (3) CHANGELOG/2026.225.0000.md is staged. The secondary observation (cache-root makedirs outside the try) is also addressed: the current hook wraps os.makedirs(cache_root, exist_ok=True) in try/except OSError with a fail-open fallback to the system temp dir.

Cross-PR interactions considered

  • opencharly/charly#264 (docs internals, skill-env-constraints) — touches candy/charly-internals/charly.yml + the plugins submodule; no file overlap with this PR. verified-non-blocking.
  • opencharly/charly#262 (docs factory, PROGRAM/factory-north-star.md) — no file overlap with this PR. verified-non-blocking.
  • opencharly/spec#26 (open, in-flight packaging contract) — the main tree's charly/sdk modules reference Phase 0b fields not yet in the checked-out spec; a pre-existing in-flight cutover condition, not introduced by this PR, and the hook change does not interact with spec#26's content. verified-non-blocking.

Decision

PASS — the change is in full compliance. The hook fix is root-cause-driven, the red/green test pair proves the new coverage fails without the change, the source-of-truth candy is byte-identical to the committed hooks, and the CHANGELOG is staged. Proceeding to merge-time CalVer finalization, squash-merge, and tag.

Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)

Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)
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