- Category: A. Data-Intensive Design
- English term: Snapshot Verification and Head Pinning
- Related: CI/CD Gate and Automated Merge · Compare-and-Swap (CAS) and Optimistic Concurrency Control · Content-Addressable Hash Verification · Deterministic Verification · Distinguishing 'Implemented' from 'Running' (Definition of Done)
General Meaning
Snapshot verification and head pinning captures the exact immutable state—such as a 40-character Git commit SHA—that successfully passed automated testing and security audits, ensuring that subsequent merges or production releases operate strictly on that identical state.
Operating against dynamic branch names like main or feature branches introduces a Time-of-Check to Time-of-Use (TOCTOU) vulnerability: a rogue or broken commit pushed between test completion and merge execution could slip into production untested. Pinning against the exact commit SHA guarantees that any intermediate divergence is immediately caught and blocked.
Why It Matters
- Preventing injection of untested commits: Halts merge operations automatically if new commits are pushed to the target branch after CI checks have passed.
- Ensuring parity between verified snapshots and deployed code: Mathematically guarantees that the code verified by automated test suites is the exact code integrated into main.
- Hardening automated unattended pipelines: Provides fail-safe protection for automated merge bots operating without manual human gatekeeping.
How the Site Factory Uses It
In the Site Factory, the autonomous watchdog runner (ops/watchdog/pr_merge.py) enforces head pinning during automated PR squash merges. When retrieving passing CI checks from the GitHub API, it concurrently queries the 40-character headRefOid commit SHA.
The bot executes gh pr merge <number> --squash --match-head-commit <SHA> using that pinned hash. If the PR branch advances in the interval, GitHub immediately rejects the merge, prompting the watchdog to halt integration and re-verify the new commit on its next patrol cycle, as verified by ops/watchdog/tests/test_pr_head_boundary.py.
Caveats & Operational Rules
- Never merge by branch name alone: Invoking merge commands without
--match-head-commitallows newly added, uninspected commits to merge without undergoing CI validation. - Avoid truncated commit hashes: Shortened hashes risk collisions as repositories grow; boundary checks must enforce full 40-character SHA digests.
- Verify live post-merge state: A successful PR merge does not equate to live production delivery; the Site Factory follows up merges with HTTP status code and content hash checks.
Related Terms
- CI/CD Gate and Automated Merge
- Compare-and-Swap (CAS) and Optimistic Concurrency Control
- Content-Addressable Hash Verification
- Deterministic Verification
- Distinguishing 'Implemented' from 'Running' (Definition of Done)
References
- Book: Martin Kleppmann, *Designing Data-Intensive Applications*, Chapter 7 (Transactions: Race Conditions and Atomicity)
Verified: 2026-11-08