ThreadWave integration and validation. Group a repo's open PRs by shared topic into independently testable batches of related PRs, build one local integration branch per batch, validate it, deploy it for QA, STOP for explicit QA approval, then land that batch's PRs one at a time (rebase + squash) before starting the next batch. Use when the user says "batch the open PRs", "integrate in batches", "group the PRs and QA each group", "bulk process the PRs", asks to plan, start, rebuild, validate ...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Integration By Batches?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ronenmars-integration-by-batches)
---
name: integration-by-batches
description: ThreadWave integration and validation. Group a repo's open PRs by shared topic into independently testable batches of related PRs, build one local integration branch per batch, validate it, deploy it for QA, STOP for explicit QA approval, then land that batch's PRs one at a time (rebase + squash) before starting the next batch. Use when the user says "batch the open PRs", "integrate in batches", "group the PRs and QA each group", "bulk process the PRs", asks to plan, start, rebuild, validate or report on a ThreadWave or Wave Run, or when one big integration branch would make a QA failure impossible to attribute. Sibling of `integration-branch` (one branch, all PRs); this one trades breadth for attribution. Repo-specific QA targets and landing details live in each repo's own skill.
---
# ThreadWave: integration by batches (shared core)
`integration-branch` merges *every* PR into one branch. When QA finds a defect in that branch you cannot say which PR caused it. This skill cuts the open PRs into **batches of related PRs**, QAs each batch alone, and lands it before the next one starts.
This method is **ThreadWave**: a batch is a ThreadWave, and one run of this skill is a Wave Run.
Read [threadwave.md](threadwave.md) when the user uses a Wave term, and before writing any title, label or text that others will read.
Reuse `integration-branch` for the mechanics it already proves (worktree, push guard, per-PR rebase + `merge --no-ff`, sweeps, cleanup). This file states what differs.
Each repo's own `integration-by-batches` skill holds its QA targets, build and gate commands, and landing differences. Read it too. Where it is stricter than this file, follow it.
## Hard rules
1. **Nothing merges to `main` before that batch's explicit QA approval.** Not a green CI, not a quiet user.
2. **One batch at a time.** Do not build, deploy or merge batch N+1 until batch N is approved *and* landed.
3. **A batch groups PRs that share a topic, area or element.** Never group unrelated or random PRs, whether to lower the batch count or to give a lone PR company.
4. **Never decide a product question silently.** Conflicts that are an either/or about behaviour (J-calls) stop the run and are put to the user with the options.
5. **The integration *branch* never reaches `origin`.** Push nothing unless QA needs an origin ref, and then only an annotated **test tag**, never the branch. Prove it before every report: `git ls-remote --heads origin "integration/*" | wc -l` → `0`.
6. **Never commit the plan, the log, the summary or `HANDOFF.md`.** They are working notes and live in the run directory `~/dev/ai-tools/tb-PRs-follow/integrations/<YYYY-MM-DD_HH-MM>/`, outside every repo and worktree (see Step 2).
7. **Preserve each PR's own history.** Land PRs individually; the batch branch is a test artifact only.
8. **Evidence over assumption.** Repo, CI and test output decide. Say "not verified" when it is not.
9. **Approval is a record, not a reading.** "QA passed", "land it" and "push" are three separate signals; each is the user's answer to its own question. A batch lands only after its `qa_verdict` line is in the log (Step 5), and `land-pr.sh` refuses without it.
10. **The tree QA saw is the tree that lands.** Every fix lives on its PR's branch before the batch is deployed. A fix that exists only on the integration branch, a cherry-pick past the tag, or a deploy run with `--force`, `--skip-tests` or a dirty tree is not QA of what will merge.
11. **Every decision for the user goes through the question tool** (`AskUserQuestion`), with options and a recommendation: QA target, J-calls, freeze, push. A question in prose is missed between status lines.
## Remote QA tracking
Each batch is also a GitHub issue on one shared Project, so QA can be done and read away from this machine. `tb-qa.mjs`, beside this file, does all of it; [github-tracking.md](github-tracking.md) is the reference. Read it before the first publish.
- **Checkpoints:** `publish` a spec (`$RUN_DIR/qa/<batch>.json`) when the plan is approved, then at each stage change; `pull` at the start of every QA conversation and every resumed session, before reading any result.
- **The tool is the only writer.** No hand-written `gh` calls for batch issues or the Project.
- **No tick, card stage or `/qa` comment authorizes a merge.** The `qa_verdict` line does, and only the user's answer to the freeze question creates it.
- **If the user has ruled out pushing or public writes,** that wins over every checkpoint: use only `pull`, `report`, `check`, `publish --dry-run` and `deps` without `--apply`, and say the remote record is behind.
- **A failed or refused tracking call is reported, never worked around** (conflict, gate, permission, sensitive content). If GitHub cannot be read, the remote state is unverified.
- No `tb-qa.mjs` beside this file means the installed skill predates tracking: say so and run the batch from the local files.
## Step 0 — Read the world, in both repos
```bash
git fetch origin --prune && git rev-parse --short origin/main # state this SHA
gh pr list --state open --json number,title,headRefName,baseRefName,isDraft,headRefOid
```
- **Per-PR, never bulk:** a list query returns `mergeable: UNKNOWN` for almost every row. Run `gh pr view <n> --json mergeable,mergeStateStatus,isDraft` per PR. `gh api repos/<o>/<r>/pulls/<n> --jq .mergeable_state` forces the recompute.
- **Read the counterpart repo's open PRs too.** A cross-repo dependency is often declared on *one* side ("Land this streamer PR first"). Pair across repos by the **endpoint or field actually called**, never by feature name.
- Capture each PR's file set: `gh pr diff <n> --name-only`. Overlaps drive the grouping.
- **Re-scan before acting.** A plan older than a day is a hypothesis; `main` moves and the open-PR count changes.
- **Read the earlier run directories first** (`ls ~/dev/ai-tools/tb-PRs-follow/integrations/`, newest last): plan, log and `HANDOFF.md` of each. An earlier run may own batches, worktrees or a verdict for some of these PRs; continue it in its own directory, or say why it is superseded.
- **Build the cross-repo pairing table before grouping,** not after the user asks for it: counterpart PR, the call that links them, which side lands first.
## Step 1 — Group
Group by **shared topic, area or element**: a screen, a component, a subsystem, a contract, the dependencies. Shared files are the strongest evidence, but PRs in one area can belong together without them. A shared label such as "low risk" or "CI only" is not a topic.
**The point of batching is speed:** testing related PRs together moves faster than testing each PR one by one. So group every PR that reasonably belongs with another. There is no minimum size: a PR with nothing in common with any other can be a batch of one. Don't force it into a group.
Then check each group against four questions:
| Question | If "no" |
|---|---|
| Can one QA pass of one flow cover the whole batch? | split it |
| Do the PRs share files (so rebasing separately costs the same conflicts)? | they probably belong together |
| Would a failure be attributable to a PR or a small pair? | split it |
| Does anything in it change what a user, a client or the counterpart repo can observe? | if not, CI alone — no QA deploy |
- **Forced pairs:** two PRs rewriting the same code and its tests cannot be separated across batches without one going `DIRTY`. Keep them together, and keep them *out of* a larger batch if their conflict is a product question — it should fail in a 2-PR batch, not a 6-PR one.
- **Docs and tooling PRs** are grouped by what they describe or build, like any other PR. If none in a batch changes observable behaviour, CI alone validates it.
- **Dependency bumps** are grouped as dependencies or by the tool they serve. A platform or test-runner major upgrade is **alone and last** so a regression is attributable.
- **Order batches:** behaviour first (conflict-dense PRs go stale fastest), tooling/docs next, deps last.
- **Drafts are batched like any open PR.** Group them, build them and QA them with the rest, and mark each draft in the plan table. A draft cannot be squash-merged, so landing stops at it with `HELD` until the author marks it ready; that stop is the author's.
- **Hold, don't merge, any PR with an unresolved security finding.** Report it, don't repair someone's PR without approval of the exact diff, and rebuild the batch without it. A batch QA'd with a local patch validates code that differs from what merges.
## Step 2 — Write the plan, then wait
Create the **run directory** once, before the first write, and record its absolute path at the top of every file in it:
```bash
RUN_DIR=~/dev/ai-tools/tb-PRs-follow/integrations/$(date +%Y-%m-%d_%H-%M) # run start, local time
mkdir -p "$RUN_DIR"
```
Everything this run writes goes there: the plan, the engineering log, the final summary and `HANDOFF.md`. A run that continues in a new session, or a later batch of the same run, reuses its directory; only a new run gets a new timestamp. The directory sits outside every git repo on purpose, so none of it can be staged.
Write `<date>-batched-qa-plan.md` in `$RUN_DIR` with: the PR table (PR, title, subsystem, key files), the overlap list, the ordering constraints, one block per batch (**goal · PRs in order · why together · order rationale · QA scenarios · risks**), the execution table (batch, PRs, QA deploy?, cross-repo dependency, blocking?), and the stop-and-ask list. Open with the decisions the user must answer (drafts, QA target), a legend for every abbreviation the plan uses, and the batch table first, with a column naming what each batch's PRs share. **Each QA scenario names the PR and the changed file it exercises**; a scenario with no line in the diff behind it is invented, so cut it. **Send it and stop.** A local rehearsal is neither a deploy nor a merge and may start early; the deploy may not.
Keep a second file in `$RUN_DIR`, the **engineering log** (`<date>-batched-qa-log.md`): §1 artifacts (every worktree, branch, ref, tag, with created/removed), §2 baseline, §3 scope, §4 order/constraints, §5 timestamped actions, §6 per-PR records (head before → rebased to → tip after), §7 conflicts (M mechanical / J judgment), §8 sweeps, §9 obstacles & numbered findings, §10 checkpoints, §11 decisions (who, why). Append after every action; obstacles are the first thing memory loses. Concise facts, no chain-of-thought.
Create the log and `$RUN_DIR/HANDOFF.md` (opened by a `## Kick-off` section, then goal, current step, next exact command) **before the first build command**, not after the first compaction. At the end of the run write the **summary** (`<date>-batched-qa-summary.md`) there too: batches and PRs in the order merged, how each conflict was resolved, what was and was not verified. A batch run spans days and several context resets; the files are the only state that survives them.
When the plan is approved, write one spec per batch and `publish` it.
## Step 3 — Build the batch (local)
`publish --stage Building` when a batch's build starts.
Per `integration-branch`: fresh worktree at an **absolute path outside the repo**, `git fetch` immediately before the cut, push guard armed (`branch.<b>.pushRemote=no_push_integration_branch`), a real install in the worktree, **baseline on untouched `main` first**, PR heads fetched to `refs/integration/pr/<n>`, each PR rebased onto the tip then `merge --no-ff`, one at a time.
- **A clean three-way merge is the case that produces wrong code silently.** Hand-read the composed result for any file touched by 2+ PRs (is each PR's addition *defined and wired*?). Log "checked, clean".
- **Suite counts:** reconcile new test files with `git diff --name-status` (`A` files).
- **Confirm any failure alone** before classifying it: passes alone = load artifact, fails alone = real. Both mistakes occurred.
- **Re-verify head SHAs** of every PR before each (re)build; a moved head invalidates that PR's record only.
- **Register new test files** in the repo's shard manifest, if it has one, or CI goes red while the code is fine.
## Step 4 — Validate
Typecheck, lint, and the full test suite on the baseline and on the batch; compare the **delta**, not the absolute. A batch with no observable impact is validated by CI plus one local run of its own tooling.
## Step 5 — Deploy to QA, then STOP
**Ask which QA target** (and which platform, where there is more than one). Never assume.
- **Pin the deployment identity to the batch** in the log: target, tip SHA, run id or version, deploy time. At the start of **every** QA conversation re-establish *which build is running* before reading any result as a verdict on the batch.
- **A cross-repo dependency is satisfied by a binary, not a merge:** it is met when the running counterpart contains it. Ask what is running before declaring a batch blocked.
- **Pairs.** A pair is a server half plus a client half behind a capability flag, so the client is inert until the flag appears. QA the pair **both ways** — new client on old server, old client on new server. For paired fixes, QA the **degrade-gracefully half first, against the unfixed counterpart**; against the fixed one the symptom is gone before the guard runs. Land the server half afterwards.
- **One checkpoint per pair batch, one approval for both halves.** Do not land one half while the other is untested.
- **Offer it for QA only after the deployment is verified** (the repo skill says how): add `build` to the spec and `publish --stage "Ready for QA"`.
- Report: batch, target, tip SHA, PRs, what to test (the plan's scenarios), caveats, the issue link and build key. **Stop and wait.**
- **Record the heads at deploy time,** one line per PR in log §10, full SHAs (`land-pr.sh` reads them):
```
qa_head: B2 #1320 3f9c...<40 hex>
```
A PR whose head moves after this line needs a redeploy and a new line, or it is held.
### Closing QA: the freeze
Run `pull` first and put the remote results, unticked scenarios and conflicts in the question.
QA ends with one `AskUserQuestion`, never with an inference from a quiet user or a "looks good" about one item:
| Option | Effect |
|---|---|
| **Freeze and land** (record the verdict) | append `qa_verdict: <batch> approved <ISO time> build <run id/version> <build key> "<the user's words>"` to log §10, `publish --stage Validated`, then Step 7 |
| **Fix first** | Step 6; the fix goes on its PR's branch, then rebuild, redeploy, new `qa_head` lines |
| **Add a PR** | it goes to the **next** batch; a frozen batch takes nothing new |
Scope the verdict to what was tested. "Yes, it works" about one flow approves that flow; ask about the rest.
## Step 6 — Handling QA findings
1. **Is the code path in the batch's file set?** `git diff --name-only <main>..<batch>` before accepting a finding against a batch.
2. **Cheap proof a defect predates the batch:** `git log <deployedSha>..<head> -- <paths>` and `git diff` over the same paths both empty → it is on `main`, not the batch.
3. A genuine `main` defect becomes its **own PR**, not a patch inside the batch. Trace it to `file:line`; fix the **root cause** where all callers route.
4. **Mutation-check every guard test:** revert the fix, confirm red, restore. A test that cannot fail is deleted. Test at the layer where the mechanism lives.
5. **A shared mock that degrades every dependency uniformly removes the asymmetry a bug lives in.** Model the healthy case explicitly.
6. QA failure → nothing merges; diagnose, update the integration branch, rebuild, redeploy.
7. Record it: add `knownIssues` and `publish --stage "Needs Fix"`. After the rebuild, publish the new `build`: old results move to history and the new build needs its own verdict.
## Step 7 — Land the batch (only on explicit approval)
`main` is protected with strict status checks: **every merge makes every remaining PR `BEHIND`**, and another session may merge in the gap, so green-and-current can go stale *during CI*. Land with **`land-pr.sh`, beside this file**, one PR at a time in plan order, from the PR's own worktree. The script is the procedure; its header lists every flag and `RESULT=` word. Hand-rolled landing loops were rewritten four times and pushed `main`'s tip onto a PR branch once, closing the PR.
**Before the first `land-pr.sh` of a batch,** run `publish --stage Landing`, then `deps --gate merge`. Either one exiting non-zero stops the landing; `land-pr.sh` does not check dependencies. After the last merge, record the squash SHAs under `release` and `publish --stage Merged`; use `Released` only once a published release contains them.
1. **Preflight once before the first PR, and again before leaving any run unattended:** `land-pr.sh --preflight` (gh auth, SSH, a signed test commit, disk). A signer that needs a human stalls an overnight loop for hours; ask the user to unlock it before they leave, or stop the run.
2. **Stacks:** retarget every child PR to `main` before its parent merges (`gh pr edit <child> --base main`). The script refuses with `CHILDREN` while any open PR is based on the branch.
3. **First pass without `--yes`:** guards, `git fetch`, rebase, the PR's tests, then `RESULT=READY`. Show the user the result and ask before the push. Then re-run with `--yes`: it pushes with a lease pinned to the checked head, waits and merges in one loop (`--match-head-commit`), and reads the PR state rather than `gh`'s exit code.
4. **Act on the result word:**
| `RESULT=` | Next |
|---|---|
| `MERGED` | log the squash SHA in §6; next PR |
| `STALE` | another merge moved `main`; run the script again |
| `HELD` | no verdict, a draft, or a head that changed since QA; report it |
| `RED` | re-run a flaky check **once**, then stop and report |
| `CONFLICT`, `EMPTY`, `TESTS`, `DIRTY`, `TIMEOUT`, `NOT_MERGED` | stop and report; nothing to retry blindly |
5. **Squash defeats ancestry checks.** `--is-ancestor <branch>` reads "unmerged" for every landed branch and `--is-ancestor <squash>` is tautological. Test content with `git diff --numstat origin/main <branch>`.
6. **Branch delete:** never unasked. Where the repo auto-deletes merged heads, do nothing. Otherwise gate any manual delete on `gh pr view <n> --json state` = `MERGED` (deleting after a *refused* merge **closes the open PR**).
7. After the last PR: verify `main` is green, delete the batch's test tag if one was pushed, log it, then clean up (Step 9).
**Unattended landing** (a background agent or a loop): one unnamed background agent, checked for first output within a few minutes; a named teammate that never started reads exactly like a slow one. Report on change only, never on a timer, and put one line in every status: `CI red on main: <check> since <time>` or `CI red on main: none`.
For a pair, land in the pair's order and record both PR numbers, both squash SHAs and the running QA build in one log row.
The dependabot trap: after `main` moves, a bot may rewrite its branch and retarget a newer or major version. `land-pr.sh` compares the PR's patch with the QA'd one and returns `HELD` on any difference; that hold is the answer, not something to route around.
## Step 8 — Next batch
Run `deps --apply` for every open batch that depends on the one just landed or redeployed.
Re-fetch `main`, **re-scan open PRs in both repos**, re-validate the next batch's plan (new PRs may now contend for its files — cost of delay compounds), rebuild it on the new `main`, repeat from Step 3.
## Step 9 — Cleanup (list first, approval, then delete)
Cleanup closes every session that built anything, including one that landed nothing or stopped mid-batch. Inventory from log §1 + `git worktree list`: worktrees, local integration/scratch branches, `refs/integration/pr/*`, test tags (local and remote). The run directory is never cleaned up (keep by default; delete only if the user asks). Exclude any worktree with uncommitted or unpushed work and any this run did not create. `git worktree remove` (never `rm -rf`), `git branch -D` only for approved branches, `git update-ref -d`, `git worktree prune`. Verify `git ls-remote --heads origin "integration/*"` → `0`, and that no QA target is left running an integration build.
## Traps that recurred
| Trap | Guard |
|---|---|
| "Never push the branch" vs needing something to QA | deploy from the worktree, or push a **tag**, never the branch |
| Bulk `mergeable` → `UNKNOWN` | per-PR query; REST API forces recompute |
| Every PR already `BEHIND` before any merge | budget one rebase + CI cycle per PR |
| `gh` exit status ≠ merge landed | read PR state |
| Squash commit is tautologically an ancestor | content diff, not `--is-ancestor` |
| zsh does not word-split unquoted vars | run multi-item logic as a `bash` script |
| `rebase && push` in one command after a conflict pushes `main`'s tip and closes the PR | `land-pr.sh` aborts the rebase and refuses an empty branch |
| A signing agent waiting for a human stalls an overnight loop | `land-pr.sh --preflight` before leaving it |
| A worktree borrowing another checkout's `node_modules` reports phantom type errors | a real install in every worktree |
| Re-keying a plan by PR number across days | PR numbers are stable; heads and `main` are not — re-scan |
## Report format (every checkpoint)
Batch · QA target · integration tip SHA · PRs in order · typecheck/lint/test delta vs baseline · what to test · caveats/holds · **the decision needed from the user, stated plainly**. Link PRs as full URLs.