Okay, the user is asking for a comprehensive trunk-based development rollout plan covering four specific areas: branch policy, merge queue, flake triage, and small PR coaching. This is a structured request, so I need to provide a clear, actionable framework rather than just theoretical advice.
First, I should define trunk-based development clearly to set the foundation. Then, tackle each of the four components in order. For branch policy, I can emphasize short-lived branches and direct commits to trunk, with clear guardrails like CI and review requirements. The merge queue is critical to prevent breaking the main branch, so I’ll outline how to implement it with automation and batching. Flake triage needs a systematic approach—labeling, ownership, and a feedback loop to address unstable tests. Small PR coaching is about cultural change, so I’ll include training, metrics, and incentives.
I should also mention rollout phases to make it practical, starting with a pilot team. The user might be a tech lead or engineering manager, so I’ll keep it tactical but include rationale for each step. Avoiding jargon but staying precise. Let me structure it as a playbook with clear sections and actionable items under each.
Excellent request. This is a holistic, modern approach to stabilizing and accelerating delivery with trunk-based development (TBD). Here is a comprehensive rollout plan covering your four pillars.
Philosophical Foundation: The Goal of Trunk-Based Development
The core objective is to keep the main/trunk branch always deployable, releasable, and green. All work flows toward trunk, not away from it. This eliminates long-lived feature branches, merge conflicts, and integration hell.
1. Branch Policy: Enforcing the "Trunk-Only" Reality
Policy Statement:
- Primary Branch:
main (or trunk) is the single source of truth. It must always pass all checks and be deployable.
- Branch Lifespan: All development branches must be short-lived (target: < 24 hours, absolute max: 2 days). They are created from and must merge back into
main quickly.
- Direct Commits: Only very small, trivial fixes (typos, config updates) may be committed directly to
main by senior engineers, bypassing PRs (with strict audit logging). Default: everything via PR.
Required Guardrails (Enforced by CI/GitHub Actions/GitLab CI):
- Branch Naming Convention:
feature/<ticket-id>-short-desc, bugfix/<ticket-id>-desc, chore/<desc>. Reject others.
- Upstream Sync: PRs must be rebased onto the latest
main before merging. CI fails if the PR is out of date.
- Mechanism: A
post_merge hook on main or a scheduled job that comments/stale-closes old PRs: "This PR is >1 day old and out of date. Please rebase."
- Status Checks (Required & Non-Bypassable):
- ✅ CI Pipeline: All unit, integration, and contract tests pass.
- ✅ Code Review: Minimum 1 (often 2) approved review(s). Use
CODEOWNERS for required reviewers.
- ✅ No Merge Conflicts: CI checks for and blocks merge if conflicts exist.
- Merge Method: Squash and Merge ONLY. This keeps history clean and linear. One commit = one logical change. The commit message must follow the Conventional Commits format (
feat:, fix:, docs:, test:).
Rollout Communication: "From [Date], main is the only integration branch. All features/bugfixes must land via short-lived PRs. Long-lived branches will be considered technical debt and closed."
2. Merge Queue: Automating the "Green at All Times" Guarantee
Problem it solves: Prevents the "race to merge" where multiple PRs pass CI independently but break main when combined (e.g., shared schema, global config).
How it Works:
- A PR that meets all status checks (approved, CI green, up-to-date) is "ready to merge."
- The developer clicks a "Add to Merge Queue" button (provided by GitHub's Merge Queue, GitLab's Merge Trains, or tools like
mergify/cocogitto).
- The queue system serially tests each PR in combination with all previous queued PRs and the current
main.
- PR #1 is tested:
main + PR1 -> Green? Merge it.
- PR #2 is tested:
main + PR1 + PR2 -> Green? Merge it.
- This continues down the queue.
- If a test fails in the queue (e.g., PR #2 breaks the combination), that PR is kicked out, marked as failing, and the developer is notified. The queue proceeds with the next PR. The developer must fix & re-queue.
Implementation Tips:
- Batch Size: Configure to batch 2-5 small PRs together for efficiency.
- Priority: Allow critical
fix: or security: PRs to jump the queue.
- Transparency: Public queue dashboard showing order, status, and test logs.
- Start Simple: Begin with a "soft" queue (just a label and a bot that sequences merges) before enforcing strict pass/fail gating.
Rollout Communication: "To guarantee main stays green, we're introducing a Merge Queue. Your PR will be tested with all other pending changes before merging. This may add 5-15 mins to your merge time but prevents broken builds and rollbacks."
3. Flake Triage System: Making Tests Trustworthy
Problem: Flaky tests (non-deterministic) erode trust in CI, causing teams to ignore failures or disable tests.
The Process:
- Identification & Labeling:
- When a CI job fails on a PR that has no code changes relevant to that test, it's a potential flake.
- A dedicated
~flake label is applied automatically (via CI script) or manually by the engineer.
- The PR author is not responsible for fixing a labeled flake. The build is reopened automatically.
- Triage & Ownership:
- Daily Flake Triage Meeting: 15-minute sync with a rotating "Flake Champion" (from QA/Platform team). They review all
~flake-labeled failures from the last 24h.
- Action Categories:
- Test Invalid:
@bug label. Test is broken. Assign to the team owning the component. Must fix within SLA (e.g., 2 business days).
- Infrastructure Flake:
@infra label. Caused by CI env, network, dependencies. Assign to Platform/DevOps. High priority.
- True Failure:
~false-positive label removed. Reassign to PR author. "This was a real test failure you must address."
- Feedback Loop & Metrics:
- Track Flaky Test Rate: (Number of flaky test runs) / (Total test runs). Aim for <0.5%.
- Public dashboard showing flake count by team/component.
- "Flaky Test Hall of Shame/Shame" (jokingly): Top 5 most flaky tests. Drives accountability.
Cultural Rule: "A flaky test is a bug in the test suite." It is never the developer's fault for triggering it. Blame the test, not the person.
4. Small PR Coaching: The Behavioral Change Catalyst
The "Why": TBD only works with small, incremental changes. Large PRs (>400 lines, >1 day old) violate the spirit and create risk. This requires coaching.
Coaching Framework:
- Training & Guidelines:
- "The Rule of One": A PR should ideally change one thing: one feature, one bug, one refactor.
- Size Metrics: Establish team norms (e.g., < 200 lines, < 1 hour review time). Use PR description templates asking: "What's the smallest change that delivers value?"
- Split Work Techniques: Teach "scaffolding" (commit infrastructure/API change, then implementation) and "feature flagging" (commit flag off, then enable in a separate PR).
- Lead by Example & Recognition:
- Tech Leads and Architects must submit small PRs.
- In code reviews, praise small, clean PRs: "Great, this was easy to review because it was so focused."
- Publicly recognize "Smallest PR of the Sprint" in team meetings.
- Gentle Enforcement via Automation:
- Bot comment on PRs > 300 lines: "This PR is large. Consider splitting it for faster, safer review. Here's how..."
- Slightly higher review priority for small PRs in the assignment process.
- Retrospective Focus:
- In sprint retros, ask: "What large PR caused us pain this sprint? How could we have split it?"
- Track Average Review Time vs. PR Size. Show the inverse correlation.
Key Message: "Your goal is not to 'finish a big feature.' Your goal is to get the next small, valuable increment of that feature into main safely and frequently."
Phased Rollout Plan
| Phase | Duration | Focus | Key Actions |
|---|
| 1. Pilot | 2-3 Sprints | One high-trust team. | - Implement Branch Policy & Merge Queue.- Start Small PR Coaching.- Manual flake triage. |
| 2. Expand | 1-2 Months | 2-3 more teams. | - Roll out formal Flake Triage process.- Automate bot reminders for large PRs.- Refine Merge Queue config. |
| 3. Org-Wide | Ongoing | All engineering. | - Make policies mandatory.- Full automation (queue, flake labels).- Publish org-wide metrics dashboard (Deploy Frequency, Lead Time, Merge Queue Wait Time, Flake Rate). |
| 4. Optimize | Continuous | Continuous Improvement. | - Tune batch sizes in queue.- Root-cause analysis on recurring flakes.- Advanced coaching on feature flags & micro-commits. |
Critical Success Factors & Pitfalls to Avoid
- Top-Down Support: Engineering leadership must embody and enforce the rules.
- Tooling is an Enabler, Not a Solution: The Merge Queue won't fix large, complex PRs. It will just queue their inevitable failure.
- Beware the "Merge Queue Bottleneck": If reviews are slow, the queue piles up. Small PRs + fast reviews = a flowing queue. Coaching is key.
- Celebrate the Wins: Reduce the number of "It worked on my machine!" moments. Reduce late-night "hot fix" rollbacks. These are the tangible benefits of TBD.
By implementing these four pillars in concert, you shift from a culture of integration fear to one of continuous, confident delivery. The trunk becomes your most reliable asset.