H

Heaptrace Handbook

Enter access code to continue

Private engineering handbook · Heaptrace Technology

Doc 6 of 7 · Quality Gates

Quality Gates
What Every PR Must Pass

Five gates. No exceptions. No "this one is urgent." If a PR can't pass these, it can't merge. If it can, the team can rely on it shipping clean.

How these gates work

Gates pass or fail. There is no third option.

Five gates govern every PR that lands on this codebase. Each one has a specific, testable criterion. Each one names the blocking action when it fails. None of them are negotiable based on urgency, seniority, or "just this once."

Gates, not guidelines.

A guideline is a suggestion. A gate is enforced. The five gates below are non-negotiable for every PR — from a one-line CSS change to a quarter-long initiative. The skill you use scales with the work; the gates do not. We learned this the hard way: every time the team softened a gate to keep a deadline, we paid for it in the next sprint. Gates that bend, break. We don't bend them.

Gates layer with severity.

PR-level gates run on every pull request (Tier 1). Staging-level gates run when a PR targets staging (Tier 2). Production-level gates run on the path to production (Tier 3+). A PR can pass Tier 1 but get blocked at Tier 2 — that's working as designed. The cost of a finding rises sharply the closer you get to production; the gates rise with it. The same PR that's "fine for dev" can be "absolutely not for staging," and that's a feature, not a bug in the process.

The CI pipeline enforces what the team writes.

We have 5 GitHub Actions workflows that implement these gates as automated checks. The gates are not vague — they are testable, automated, and consistently applied. A reviewer who is in a hurry, who skipped lunch, who is biased toward a teammate, who is short on sleep — none of them get a vote on whether the gate passes. The CI does. Cross-reference the CI/CD Setup Guide for the workflow implementations.

The five

Every PR. Every time. Every gate.

Each gate below names what it checks, what blocks the PR, who can override (almost no one), and the skill that backs it. If you can't tick all five, the PR doesn't merge.

01
Gate One

The Plan Gate

Every PR starts with a plan in writing. The plan determines the skill; the skill determines the rigor. If the diff exceeds what the plan named, the plan is rewritten — not the diff stretched.

Trigger
Opens before code is written
Enforced by
Developer running /quick-plan or /feature-plan
Blocks if
PR description has no plan reference
✓ What this gate checks
  • For S/M tasks: /quick-plan output is in the PR description (or linked via a .heaptrace/ task file).
  • For L/XL tasks: /feature-plan output is in the PR description (or linked to /tasks/backlog/).
  • For bug fixes: /find-fix output precedes the plan — diagnosis first, then scope decision.
  • The diff doesn't exceed what the plan named — both file count and stated intent. A 3-file plan that ships a 12-file diff is a plan failure, not an "I found more."
  • The plan is dated and named. Anonymous plans pasted into a PR after the fact don't count.
✕ What blocks the merge
  • PR description has no plan reference → reviewer rejects on sight, no second pass.
  • Diff touches files the plan didn't list → reviewer asks for a re-plan or a scope explanation in writing.
  • Plan claimed S, diff is clearly L → reviewer asks for /feature-plan replan. "I underestimated" is not a substitute for a real plan.
  • Plan references a stale ticket that's since changed scope → plan must be re-run against the current acceptance criteria.
! Who can override
No one. Even trivial PRs reference a 30-second plan. The cost of running /quick-plan on a typo fix is roughly four seconds; the cost of the team normalizing "I'll skip the plan this time" is months of decay. We pay the four seconds.
→ Backing skills
/quick-plan /feature-plan /find-fix
Anti-patterns this gate prevents: #01 (no plan), #03 (wrong-size plan), #04 (diverge from plan). See Anti-Patterns for the full pattern descriptions.
02
Gate Two

The Review Gate

The diff runs through /code-review before a human looks at it. Warnings are resolved or accepted in writing. There is no "the reviewer will catch it."

Trigger
Before PR is opened for human review
Enforced by
/code-review skill + reviewer attention
Blocks if
Missing /code-review output or unresolved warnings
✓ What this gate checks
  • /code-review has been run on the diff — not on yesterday's version, on this diff.
  • Output is in the PR description, not pasted as a comment after review starts.
  • All warnings are either fixed or explicitly accepted, with the reason written in the PR description.
  • Test coverage is named for the change — which tests exist, which were added, which were updated. "Tests pass" is not test coverage.
  • Reviewer is not the author. Self-reviewed PRs don't pass this gate.
✕ What blocks the merge
  • PR description missing /code-review output → returned at first review — the reviewer doesn't run the skill on the author's behalf.
  • /code-review flagged blocking issues that are not addressed → blocked until each finding is either fixed or accepted in writing.
  • Warnings stacked as "fix later" with no Tech Lead exemption → blocked. "Fix later" is how a codebase rots; we don't allow it on the rails.
  • Author added new test coverage but the tests don't fail when the code is broken → blocked. Coverage that doesn't fail is theatre.
! Who can override
Tech Lead in writing, for a specific waiver, with a documented reason in the PR description, on a per-finding basis. Blanket waivers ("we accept all warnings on this PR") are not granted. Every accepted warning gets its own one-line justification — if you can't write one, you can't accept it.
→ Backing skills
/code-review /test-gen /test-coverage /code-standards
Anti-patterns this gate prevents: #11 (no /code-review), #12 ("fix later"), #14 (poor description), #27 (rubber-stamp review). See Anti-Patterns for the patterns.
03
Gate Three

The Security Gate

Code paths that touch auth, payments, PII, or infra trigger an audit skill. The audit runs in the PR, not after. HIGH or CRITICAL findings block the merge until resolved or accepted by Compliance.

Trigger
Auto-detected based on which files the PR touches
Enforced by
CI workflow + skill outputs + reviewer
Blocks if
Required audit output missing OR HIGH/CRITICAL unresolved
✓ What this gate checks (tiered by code area)
Code area Required output
Auth / Login / Session /sec-audit
Payments / Billing /sec-audit + /pci-audit (if processing card data)
PII / User Data /sec-audit + /privacy-review
New Dependencies /dep-vuln
Cloud infra changes /cloud-security + /infra-harden
Network / firewall changes /network-audit
HIPAA-scoped data /hipaa-audit
GDPR-scoped data /gdpr-audit
SOC 2 compliance /soc2-audit
Secrets / keys handling /secrets-scan
Container changes /infra-harden
Access control / RBAC /access-audit
Audit logging / immutable trails /audit-log
✕ What blocks the merge
  • File path matches a regulated category AND the required skill output is missing → CI Tier 2 blocks the merge. The CI is non-negotiable on this; there is no manual override at the runner level.
  • Skill flagged HIGH or CRITICAL severity AND the finding is not explicitly resolved or accepted with a Compliance sign-off → blocked.
  • Dependency added with a known CVE at HIGH or above → blocked until the dependency is replaced, pinned to a patched version, or the CVE is documented as not applicable to our usage.
  • Secrets detected in the diff by /secrets-scan → blocked, the PR cannot merge until the secret is rotated (not just removed from the diff).
! Who can override
Only with explicit Compliance Manager sign-off, documented in the PR. Sign-off is per-finding, not per-PR. The Compliance Manager writes the reason, the date, and their name. The override is logged for quarterly review. Tech Lead cannot override the Security Gate. Engineering Manager cannot override the Security Gate. Only Compliance, in writing.
→ Backing skills
/sec-audit /hipaa-audit /gdpr-audit /soc2-audit /pci-audit /cloud-security /infra-harden /network-audit /secrets-scan /dep-vuln /privacy-review /access-audit /audit-log /compliance-report
Anti-patterns this gate prevents: #15 (no /sec-audit), #21 (no /dep-vuln), #23 (unresolved findings), #24 (hardcoded secrets). See Anti-Patterns for the patterns.
Cross-reference. This gate is implemented via the Tiered CI/CD Security Pipeline — workflows security-pr.yml, security-staging.yml, and security-production.yml. The severity matrix is in .github/security/severity-matrix.json.
04
Gate Four

The Verification Gate

Acceptance criteria from the plan are verified before the PR is marked "Ready for Review." Each criterion gets a method of verification — not "I trust the AI." Verification is the developer's job, every time.

Trigger
Before PR is marked "Ready for Review"
Enforced by
Developer + reviewer
Blocks if
Acceptance criteria not verified or method missing
✓ What this gate checks
  • Every acceptance criterion in the plan has been verified — and the method of verification is named.
  • For UI changes: visually confirmed in browser/simulator/device. Screenshots in the PR if the change is user-visible.
  • For DB changes: schema applied locally, no destructive operations (DROP, TRUNCATE, ALTER without backfill) without an explicit review note.
  • For API changes: contract tests pass, request/response shapes match the plan, breaking changes are flagged in the PR title.
  • For bug fixes: the test fails on the broken code and passes on the fix. Both directions verified — "the test passes now" is half a verification.
  • For migrations: rollback plan documented in the PR. If a rollback would be impossible, that's stated explicitly.
✕ What blocks the merge
  • Plan's acceptance criteria checkboxes unchecked → returned. Unchecked boxes mean the criterion wasn't met, not that it was forgotten.
  • PR description doesn't say HOW each criterion was verified → returned. "Verified" alone isn't a verification.
  • Bug fix without a test that fails-on-broken-code-passes-on-fix → returned. No exceptions, including "I tested it manually" — manual testing is verification, not regression protection.
  • UI change with no screenshot when the user is the verifier → returned. The reviewer should not have to re-run the app to see what changed.
! Who can override
No one. Verification is the developer's job. If you can't verify the change works, you don't ship the change — you ship the investigation. We have shipped exactly one production incident attributable to AI in the last twelve months, and it was a missed verification step on a generated migration. The model wasn't at fault. We were.
→ Backing skills
/test-gen /e2e-test /api-test /regression-check
Anti-patterns this gate prevents: #07 (trust without verify), #08 (fake tests), #10 (unread migrations). See Anti-Patterns for the patterns.
05
Gate Five

The Commit Gate

Commit messages follow conventional commits. One commit per logical unit of change. The squash commit on merge follows the same rules. "Fix bug" doesn't ship; we know what changed because we read the message.

Trigger
Before pushing the final commit
Enforced by
/smart-commit + Tech Lead at merge
Blocks if
Poor commit messages or mixed-purpose commits
✓ What this gate checks
  • Commit message follows conventional commits: feat:, fix:, chore:, docs:, refactor:, perf:, test:.
  • Commit scope matches the file area changed — feat(auth):, fix(billing):, refactor(api):.
  • Commit message describes WHAT changed and WHY, not just "fix bug" or "address review."
  • Single commit per logical unit of change. No "WIP" or "checkpoint" commits merged into main.
  • Co-authored attribution is included if pairing — Co-Authored-By: trailer with email.
  • The squash commit on merge follows the same rules — the original branch history doesn't excuse a sloppy squash message.
✕ What blocks the merge
  • Generic commit messages ("fix bug," "wip," "stuff") → Tech Lead asks for /smart-commit re-run before merge.
  • Multiple unrelated changes in one commit → squash or split. "Refactored while I was in there" is not a commit message; it's an anti-pattern.
  • Conventional commit type doesn't match the change ("feat:" on a bug fix, "fix:" on a refactor) → corrected before merge.
  • Co-author missing when pairing was clearly involved (per the plan or PR description) → corrected before merge. Credit is engineering, not generosity.
! Who can override
Squash-on-merge is the project policy. The squash commit message must still be clean — generated by /smart-commit, reviewed by the merger. There is no override for "good enough" commit messages. The git log is the long-term documentation; sloppy messages are technical debt we pay for at every blame.
→ Backing skills
/smart-commit /release-notes
Anti-patterns this gate prevents: #04 (diverge from plan), #13 (adjacent refactor), #14 ("fixes bug"). See Anti-Patterns for the patterns.
The template

Every PR description follows this shape.

Copy it. Paste it. Fill it in. The template is pinned in the repo as .github/PULL_REQUEST_TEMPLATE.md. If your PR doesn't have these sections, it doesn't pass the Review Gate.

.github/PULL_REQUEST_TEMPLATE.md
## Summary
<2-3 sentence overview of what this PR does and why>

## Plan
- Plan source: /quick-plan (or /feature-plan for L/XL work)
- Plan output: <paste plan or link to /tasks/backlog/TASK-NNN.md>

## Changes
- `path/to/file1.ts` — <what changed>
- `path/to/file2.tsx` — <what changed>

## Verification
- [ ] Acceptance criterion 1 — verified by <how>
- [ ] Acceptance criterion 2 — verified by <how>
- [ ] Tests pass: <command/output>

## Skill Outputs
- /code-review: <pass / warnings addressed / link to output>
- /sec-audit: <required? if so, output included>
- /dep-vuln: <if dependencies changed>

## Notes for Reviewer
<anything reviewer should focus on, surprises, decisions made>
Why these five sections. Summary anchors the reviewer on why. Plan proves you ran Gate 1. Changes lets a reviewer scan the diff with intent. Verification proves you ran Gate 4. Skill Outputs prove you ran Gates 2 and 3. Notes for Reviewer is where you do Principle 6 — Communication is engineering. Every section maps to a gate. No section is decorative.
When a gate fails

Failure is feedback, not punishment.

A gate failure names the specific gap. The developer fixes the gap and re-submits on the same PR. There is no shame in a gate catch — the catch is the gate doing its job.

┌────────────────────────────────────────────────────────────┐
│                   GATE FAILURE FLOW                        │
│                                                            │
│  PR fails Gate                                             │
│      │                                                     │
│      ▼                                                     │
│  Reviewer/CI flags the specific gate failure               │
│      │                                                     │
│      ▼                                                     │
│  Developer addresses (skill re-run, code change, etc.)     │
│      │                                                     │
│      ▼                                                     │
│  Developer re-submits with documented fix                  │
│      │                                                     │
│      ▼                                                     │
│  Re-review on the SAME PR (no new PR needed)               │
│      │                                                     │
│      ▼                                                     │
│  Pass → merge.   Fail → repeat from "address."             │
└────────────────────────────────────────────────────────────┘
  1. The gate identifies the specific failure. Not "your PR is bad" but "Gate 3: /sec-audit missing for auth flow." Specificity is the point. A gate that says "something is wrong" without naming what is broken is a gate that bends. We don't ship those gates.
  2. Developer addresses the gap. Runs the skill, fixes the code, adds the verification step, or requests an exemption with a documented reason. The developer doesn't argue with the gate — gates aren't political. They argue with the application of the gate, in writing, if they think the gate is wrong for this case.
  3. Re-submit on the SAME PR. No new PR. No rebase wars. No closing-and-reopening. Push the fix to the same branch and request re-review. The PR's history captures the gate failure and the resolution — both are useful when we read the log later.
  4. Re-review on changes only. The Tech Lead doesn't re-review the whole PR. They review the gap fix. If the fix is solid and no other gates failed, the PR merges. If a second gate failed during the fix, the flow restarts on that gate — but not on the gates that already passed.
  5. Pass → merge. Fail → repeat. There is no third state. We don't merge "with reservations." We don't merge "and we'll fix it after." We merge clean or we don't merge.
Exemptions

Gates can be exempted. Rarely. With paperwork.

Sometimes a gate genuinely doesn't apply — a copy-only change touches no security paths, an experimental spike doesn't need a full plan. Here's how the exemption flow works, and why it has to be visible.

STEP 1 Document the exemption in the PR description
Write it down where everyone sees it.
The exemption goes in the PR description, in its own section, with the specific gate, the reason, the approver, and the date. No Slack DMs. No verbal approvals in standup. If it's not in the PR description, the exemption didn't happen.
## Gate Exemption - Gate: 3 (Security) - Exemption: /sec-audit not run - Reason: This PR only changes copy in a marketing component; no auth, payment, or PII paths touched. - Approved by: @tech-lead-handle - Date: 2026-04-24
STEP 2 Tech Lead approves in the PR thread
Approval lives in the PR, not in chat.
The Tech Lead posts a comment confirming the exemption in writing, in the PR thread. The comment is short, factual, and reasoned. Example: "Approving exemption: copy-only change confirmed; no security path touched. — Tech Lead" The audit trail starts in the PR and ends in the PR. If the exemption requires Compliance sign-off (Gate 3), that comment comes from Compliance, not from the Tech Lead.
STEP 3 Exemption is logged and reviewed quarterly
Patterns of exemption point to broken gates.
Every quarter, Engineering Leadership reviews the list of granted exemptions. If a gate is being exempted more than 20% of the time, the gate is wrong, not the team. We rewrite the gate. If a single developer is requesting exemptions at twice the team average, that's a 1:1 conversation — usually about whether the developer has access to the right skills, not about discipline. The quarterly review is what keeps the gates honest.
Metrics

What we measure to know the gates are working.

Six metrics. Reviewed monthly. The gates exist to move these numbers — if they don't move the numbers, the gates change. Outcomes are the proof, not effort.

Metric Target Why we measure it
PR first-review pass rate > 85% Indicates skills are catching issues before human review. A drop here means the team isn't running the skills, or the skills don't catch what we need.
Mean time from PR open to merge < 4h (S/M), < 2d (L/XL) Indicates gates aren't bottlenecks. Gates that delay merges past these targets are gates that the team will route around — we'd rather fix the gate than watch it get bypassed.
Gate failure rate < 15% per gate If a gate fails too often, the team isn't running the skill that prevents the failure. We fix the skill, the training, or the gate — never the developer.
Exemption rate < 5% of PRs High exemption rate means the gate is wrong or being abused. Either way, it's a leadership signal — the gate gets rewritten or the abuse gets addressed.
Production defect rate (per merged PR) < 1% The ultimate measure of gate effectiveness. If gates are working, defects are rare. If defects rise, a gate is missing or being bypassed — we audit and add or repair.
Time from defect detected to root-cause known < 30 min Indicates /find-fix + audit logs are working. Long root-cause times mean we lack the diagnostic skills or our logging is insufficient.
Cross-reference · CI/CD implementation

The gates above are implemented as automated CI checks.

  • Tier 1 · Every PR
    security-pr.yml — Gates 1, 2, 5 + /sec-audit and /dep-vuln on relevant paths. Runs in under 2 minutes. Designed to be fast enough that no developer waits on it.
  • Tier 2 · Staging
    security-staging.yml — adds /cloud-security, /infra-harden, and /network-audit on infra-touching PRs. Roughly 7 minutes. Runs on the path from main → staging.
  • Tier 3 · Production
    security-production.yml — adds /hipaa-audit, /gdpr-audit, /soc2-audit, /pci-audit, and /compliance-report. Roughly 20 minutes. Runs on the path from staging → production.
  • Scheduled · Weekly
    security-deep-scan.yml — runs the full audit suite against the main branch on a weekly cadence. Catches drift between PR-time and ambient-state findings.
  • On-Demand · Manual
    security-demand.yml — manually triggered for ad-hoc audits, pre-release sweeps, or incident response. Same skills, different cadence.
Read the CI/CD Security Setup Guide
Where to next

Pick your next read.

The gates are the contract. These three docs are the context — the principles behind the gates, the skills that power them, and the client-facing version for engagement conversations.

─────────────────────────────────────────────────────────
Effective: April 2026
Version: 1.0 (Initial Release)
Maintained by: Heaptrace Engineering Leadership
─────────────────────────────────────────────────────────