Skip to content
Merged
5 changes: 5 additions & 0 deletions changelog.d/pan-5995.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#### Fixed

- **A half-merged UAT batch survives a dashboard restart and can be finished:** when a polyrepo batch merge stops after some repos landed, the batch is no longer voided, replaced or cleaned up, and no new batch is built for that project until it is finished. The board shows it as "partially promoted: resume promote". Merging it again checks that the landed repos really merged, that each remaining repo's batch branch is unchanged since it was built, and that its members' pull requests there are still open, at the reviewed heads, and have no changes requested. A repo whose push landed before a crash but was never recorded counts as landed. It then publishes only the remaining repos and runs the normal post-merge steps. If any check fails, it refuses with the reason and changes nothing. A batch that can never be finished can be abandoned with `pan merge void <batch> --abandon-partial --reason <text>`: landed repos keep their merges, the batch's branches are cleaned up, and new batches can be built again. ([#5995](https://github.com/eltmon/overdeck/issues/5995))
- **A ready feature keeps its batch with the merge train off:** an older merged PR on a reused feature branch no longer voids a batch whose member is ready now. ([#5995](https://github.com/eltmon/overdeck/issues/5995))
- **Failed UAT batch cleanup backs off:** a cleanup that keeps failing now waits 1 minute, doubling per failure up to 1 hour, instead of retrying every tick. ([#5995](https://github.com/eltmon/overdeck/issues/5995))
97 changes: 86 additions & 11 deletions docs/MERGE-TRAIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,22 @@ never deleted, and `safeGenerationWorktreePath` accepts only a `uat-*` folder
under `workspaces/`, so a `feature-*` workspace is never removed. Every cleanup
git call has a 60-second timeout (`CLEANUP_GIT_TIMEOUT_MS`). A step succeeds
only when git succeeds or says the target is already gone (`removeOrAlreadyGone`:
"remote ref does not exist", "branch … not found", "is not a working tree").
Any other failure, including a timeout, leaves `cleaned_at` unset, so the next
tick retries and no origin `uat/*` branch is silently leaked. There is no
backoff: a batch whose cleanup keeps failing is retried, and logged, every
tick. A failed stack teardown skips that batch's worktree and branch removal
for the tick, so the worktree is never removed under a running `compose down`.
For a polyrepo batch, a member repo the batch never recorded (a failed
assembly) has its leftover `<wrapper>/<repo>` worktree removed before its
branch is deleted. Stack teardown in
"remote ref does not exist", "branch … not found", or git's exact LC_ALL=C line
`fatal: '<path>' is not a working tree`). Any other failure, including a
timeout, leaves `cleaned_at` unset, so a later tick retries and no origin
`uat/*` branch is silently leaked. A failed attempt backs that batch off
(PAN-5995): `cleanup_attempts` counts the failures and
`cleanup_next_attempt_at` holds the next try, 1 minute after the first failure,
doubling per failure, capped at 1 hour (`cleanupBackoffMs`). A success clears
both. Neither write moves `updated_at`, so a failing cleanup never restarts a
superseded batch's 24-hour grace period. A failed stack teardown skips that
batch's worktree and branch removal for the tick, so the worktree is never
removed under a running `compose down`. For a polyrepo batch, a member repo
the batch never recorded (a failed assembly) has its leftover
`<wrapper>/<repo>` worktree removed before its branch is deleted. That sweep
refuses to run when any such repo key is not one plain path segment (it
contains `/`, `\` or `..`), so a key can never reach outside its own
`workspaces/uat-*` folder. Stack teardown in
the reconciler and in cleanup is bounded at 120 seconds
(`UAT_TEARDOWN_DEADLINE_MS`), below compose's own 300-second cap.

Expand All @@ -279,6 +286,59 @@ neither stamps nor invalidates a marked generation, cleanup does not reap it,
and the void verb refuses it, so promote's final `promoted` write never
overwrites a void.

**Partially promoted batches (PAN-5995).** The in-process set is lost when the
dashboard restarts. A polyrepo promote publishes one member repo at a time and
stamps each repo's `promoted_at` as it lands, so the durable record of a
half-finished promote is a batch that is not `promoted` but has at least one
repo with `promoted_at` (`isUatGenerationPartiallyPromoted`). Whatever the train
setting or the departure evidence, such a batch is never invalidated by the
reconciler, superseded by a new assembly, voided by another batch's promote or
by `pan merge void` (409), or reaped by cleanup. While a `ready` one exists the
reconciler assembles nothing for the project, even when forced (action
`partially-promoted`); the hold lifts once the row reads `promoted`. The
reconciler logs it and the board shows it as "partially promoted: resume
promote".

To finish it, merge the batch again. The normal member gate cannot pass: a
member whose repo already landed reads as merged and leaves the ready set. So
for a partially promoted batch, and only for one, `uat-promote-members.ts`
replaces that gate, and the promote checks the rest:

- every stamped repo is confirmed merged on its target (`findLandedMerge`
finds a merge containing the `uat/*` head assembly recorded; a current tip
that differs from that head, a rewritten branch, never counts as landed, and
a repo with no recorded head cannot be proven, so the resume refuses);
- every pending repo's `uat/*` branch on origin is still at the head assembly
recorded (`uat_generation_repos.head_sha`, PAN-5995; a row without one is
refused);
- in every pending repo, each member's PR or MR is open, has no changes
requested (GitHub `CHANGES_REQUESTED`, GitLab `requested_changes`), and is
at the head the batch bundled. A PR that is no longer open passes only when
its repo already landed without its stamp (`findLandedMerge` finds the merge:
a push the remote accepted before a crash or a timeout). Promote's recovery
then stamps that repo before anything else runs;
- a member with work in a pending repo still lands only at the heads its
review approved (the PAN-5786 reviewed-heads check, which reads review
records rather than the PR). The merge gate (approval and CI per PR) and
the ready-set check are not used: they judge PRs the landed repos merged;
- each pending repo's target is unchanged over the batch's files and the
trial merge is clean (the normal phase A checks).

Any failure refuses with the reason and publishes nothing. Otherwise the
promote skips the stamped repos, lands the rest, finalizes the batch and runs
the normal per-member post-merge path. The reconciler never stamps a
partially promoted batch `promoted` on containment evidence, even when every
repo landed: the resumed promote finalizes it, so post-merge runs.
`uatBranchHead` fetches the `uat/*` ref before it reads it, and the trial merge
merges that verified SHA, not the ref name, so a fetch in between cannot swap
what lands. A batch assembled before PAN-5995 has no recorded head, so its
resume is refused.

If a partially promoted batch cannot be resumed (a remaining PR was closed for
good, a target moved over the batch's files, the `uat/*` branch moved), the
operator abandons it: `pan merge void <generation> --abandon-partial --reason
<text>` (see "Voiding a batch"). Nothing else ends a partially promoted batch.

### When the train is off

Turning the train off stops new batches; it does not freeze the existing ones
Expand All @@ -290,7 +350,9 @@ forge or git read. With a live batch it runs the reconciler with

- stamps a batch whose branch is contained in main `promoted`;
- invalidates a batch, and stops its stack, only on positive evidence that a
member left it: the member merged outside the batch, its PR or MR is no
member left it. A member in the ready set right now is never departed
(PAN-5995: checked before the merged-ids evidence, so an older merged PR on a
reused `feature/<id>` branch cannot void it). Otherwise: the member merged outside the batch, its PR or MR is no
longer open, changes were requested, or its branch head moved
(`departureEvidence`, `uat-departure-evidence.ts`, reading the same cached
listings as the ready set). A member that is merely not ready right now
Expand Down Expand Up @@ -321,7 +383,20 @@ void. The journal entry is written before the teardown. Voiding a batch that is
already `invalidated` succeeds and changes nothing (`alreadyVoided: true`), so
a retry after a lost answer is safe. It refuses an `assembling` batch, because
the engine's final write would overwrite the void; a batch a promote is
merging, for the same reason; and a `promoted` or `failed` batch. The next tick's
merging, for the same reason; a partially promoted batch (PAN-5995), whose
promote must be resumed; and a `promoted` or `failed` batch.

`--abandon-partial` (PAN-5995, needs `--reason`; body `{ abandonPartial: true,
reason }` on the same admin-only route) is the operator's exit for a partially
promoted batch that cannot be resumed. It never reverts a landed repo and
never touches a target branch. It writes the activity entry first and is
refused (503, nothing changed) when that write fails, since the entry is the
record of what was left landed. The row then becomes `invalidated` with a reason
naming the landed and the unlanded repos; the landed repos keep their
`promoted_at` and merge SHA rows as the record. An `invalidated` row no longer
counts as partially promoted, so the assembly hold lifts, and cleanup reaps
the batch's `uat/*` branches and worktrees like any voided batch. The activity
entry says it was abandoned and what landed. The next tick's
cleanup removes the worktree and branches, whether the train is on or off.
With the train on, that same tick may assemble a fresh batch from the features
that are still ready: a void retires that tree, and does not hold the
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/composer-commands.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ export const COMPOSER_COMMAND_MANIFEST: ComposerCommandManifestEntry[] = [
{"id":"pan-flywheel-stats","path":["flywheel","stats"],"display":"/pan flywheel stats","description":"Substrate-bug discovery rate and P0 count, computed from the tracker and forge","args":[],"options":[{"flags":"--json","description":"Output as JSON","required":false,"valueHint":null},{"flags":"--window <days>","description":"Window in days (default 30)","required":true,"valueHint":"days"}],"aliases":[],"category":"Flywheel"},
{"id":"pan-merge","path":["merge"],"display":"/pan merge","description":"Merge an issue through the dashboard merge door, or manage Flywheel auto-merge","args":[{"name":"id","required":false,"variadic":false}],"options":[],"aliases":[],"category":"Review"},
{"id":"pan-merge-cancel","path":["merge","cancel"],"display":"/pan merge cancel","description":"Cancel a pending Flywheel auto-merge during its cooldown window","args":[{"name":"id","required":true,"variadic":false}],"options":[],"aliases":[],"category":"Review"},
{"id":"pan-merge-void","path":["merge","void"],"display":"/pan merge void","description":"Void a UAT batch so it can never merge; the next merge-train tick removes its worktree and uat/* branches (with the train on, it may assemble a fresh batch from features still ready)","args":[{"name":"generation","required":true,"variadic":false}],"options":[{"flags":"--reason <text>","description":"why the batch is voided (stored on the batch and journaled)","required":true,"valueHint":"text"}],"aliases":[],"category":"Review"},
{"id":"pan-merge-void","path":["merge","void"],"display":"/pan merge void","description":"Void a UAT batch so it can never merge; the next merge-train tick removes its worktree and uat/* branches (with the train on, it may assemble a fresh batch from features still ready)","args":[{"name":"generation","required":true,"variadic":false}],"options":[{"flags":"--reason <text>","description":"why the batch is voided (stored on the batch and journaled)","required":true,"valueHint":"text"},{"flags":"--abandon-partial","description":"abandon a partially promoted batch that cannot be resumed; landed repos keep their merges (needs --reason)","required":false,"valueHint":null}],"aliases":[],"category":"Review"},
{"id":"pan-artifacts","path":["artifacts"],"display":"/pan artifacts","description":"Create, publish, validate, inspect, and open shared HTML artifacts","args":[],"options":[],"aliases":[],"category":"Data"},
{"id":"pan-artifacts-create","path":["artifacts","create"],"display":"/pan artifacts create","description":"Validate and publish an HTML artifact","args":[{"name":"file","required":true,"variadic":false}],"options":[{"flags":"--issue <id>","description":"Issue ID for artifact provenance","required":true,"valueHint":"id"},{"flags":"--workspace <id>","description":"Workspace ID for artifact provenance","required":true,"valueHint":"id"},{"flags":"--agent-role <role>","description":"Agent role: plan, work, review, test, ship, flywheel, or user","required":true,"valueHint":"role"},{"flags":"--agent-harness <harness>","description":"Agent harness: claude-code, pi, ohmypi, codex, acp, kimi-code, opencode, muse, prime-agent, grok, antigravity, or user","required":true,"valueHint":"harness"},{"flags":"--run-id <id>","description":"Run ID for artifact provenance","required":true,"valueHint":"id"},{"flags":"--session-id <id>","description":"Session ID for artifact provenance","required":true,"valueHint":"id"},{"flags":"--title <title>","description":"Artifact title","required":true,"valueHint":"title"},{"flags":"--description <text>","description":"Artifact description","required":true,"valueHint":"text"},{"flags":"--strict","description":"Enable strict validation warnings","required":false,"valueHint":null},{"flags":"--json","description":"Emit JSON result","required":false,"valueHint":null}],"aliases":[],"category":"Data"},
{"id":"pan-artifacts-publish","path":["artifacts","publish"],"display":"/pan artifacts publish","description":"Revalidate and republish an existing artifact when changes are pending","args":[{"name":"file","required":true,"variadic":false}],"options":[{"flags":"--strict","description":"Enable strict validation warnings","required":false,"valueHint":null},{"flags":"--json","description":"Emit JSON result","required":false,"valueHint":null}],"aliases":[],"category":"Data"},
Expand Down
28 changes: 26 additions & 2 deletions src/cli/commands/__tests__/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,36 @@ describe('merge CLI', () => {
expect(process.exitCode).toBe(1);
});

it('is registered as `pan merge void <generation> --reason`', async () => {
it('is registered as `pan merge void <generation> --reason [--abandon-partial]`', async () => {
const program = new Command();
registerMergeCommands(program);
const merge = program.commands.find((c) => c.name() === 'merge')!;
const voidCmd = merge.commands.find((c) => c.name() === 'void')!;
expect(voidCmd.options.map((o) => o.long)).toContain('--reason');
expect(voidCmd.options.map((o) => o.long)).toEqual(expect.arrayContaining(['--reason', '--abandon-partial']));
});

it('PAN-5995: --abandon-partial posts abandonPartial with the reason and reports the abandon', async () => {
const call = vi.fn().mockResolvedValue({
ok: true, status: 200,
json: async () => ({ voided: 'uat/min-dune-1128-3', statusReason: 'abandoned by the operator while partially promoted (landed: fe@m1; not landed: api): x', stackTeardown: 'done', abandoned: true }),
});

await mergeVoidCommand('uat/min-dune-1128-3', { reason: 'x', abandonPartial: true }, call as never);

expect(call).toHaveBeenCalledWith('/api/merge-train/generations/min-dune-1128-3/void', expect.objectContaining({
method: 'POST', body: { reason: 'x', abandonPartial: true },
}));
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('Abandoned uat/min-dune-1128-3'));
expect(process.exitCode).toBeUndefined();
});

it('PAN-5995: --abandon-partial without --reason fails before calling the dashboard', async () => {
const call = vi.fn();

await mergeVoidCommand('uat/min-dune-1128-3', { abandonPartial: true }, call as never);

expect(call).not.toHaveBeenCalled();
expect(process.exitCode).toBe(1);
});
});

Expand Down
25 changes: 20 additions & 5 deletions src/cli/commands/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,14 @@ const GENERATION_NAME_SHAPE = /^(uat\/)?[A-Za-z0-9][A-Za-z0-9._-]*$/;
* The dashboard's next merge-train tick removes its uat-* worktree and uat/*
* branches; with the train on, that tick may assemble a fresh batch from the
* features that are still ready. Nothing calls this automatically.
*
* PAN-5995: `--abandon-partial` (with a required `--reason`) is the operator's
* exit for a partially promoted batch that cannot be resumed. Landed repos
* keep their merges; the batch becomes `invalidated` and cleanup reaps it.
*/
export async function mergeVoidCommand(
generation: string,
options: { reason?: string } = {},
options: { reason?: string; abandonPartial?: boolean } = {},
call: typeof callDashboard = callDashboard,
): Promise<void> {
const name = generation.trim();
Expand All @@ -208,23 +212,33 @@ export async function mergeVoidCommand(
process.exitCode = 1;
return;
}
if (options.abandonPartial && !options.reason?.trim()) {
console.error('--abandon-partial needs --reason <text>: say why the rest of the batch will not land');
process.exitCode = 1;
return;
}
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), MERGE_VOID_REQUEST_TIMEOUT_MS);
try {
// The route re-adds `uat/`; sending it bare keeps an encoded slash out of the URL.
const res = await call(`/api/merge-train/generations/${encodeURIComponent(name.replace(/^uat\//, ''))}/void`, {
method: 'POST',
body: options.reason ? { reason: options.reason } : {},
body: {
...(options.reason ? { reason: options.reason } : {}),
...(options.abandonPartial ? { abandonPartial: true } : {}),
},
signal: controller.signal,
});
const payload = await res.json().catch(() => ({})) as { voided?: unknown; statusReason?: unknown; stackTeardown?: unknown; alreadyVoided?: unknown; error?: unknown };
const payload = await res.json().catch(() => ({})) as { voided?: unknown; statusReason?: unknown; stackTeardown?: unknown; alreadyVoided?: unknown; abandoned?: unknown; error?: unknown };
if (res.ok && typeof payload.voided === 'string' && payload.alreadyVoided === true) {
console.log(`${payload.voided} was already voided (${String(payload.statusReason)}); nothing changed.`);
return;
}
if (res.ok && typeof payload.voided === 'string') {
const teardown = payload.stackTeardown === 'failed' ? ' Its UAT stack did not stop; cleanup retries it.' : '';
console.log(`Voided ${payload.voided} (${String(payload.statusReason)}). The next merge-train tick removes its worktree and branches.${teardown}`);
console.log(payload.abandoned === true
? `Abandoned ${payload.voided} (${String(payload.statusReason)}). Landed repos keep their merges; the next merge-train tick removes its worktrees and uat/* branches, and new batches may assemble.${teardown}`
: `Voided ${payload.voided} (${String(payload.statusReason)}). The next merge-train tick removes its worktree and branches.${teardown}`);
return;
}
console.error(`Void refused for ${name}: ${typeof payload.error === 'string' ? payload.error : `Dashboard returned HTTP ${res.status}`}`);
Expand Down Expand Up @@ -268,5 +282,6 @@ export function registerMergeCommands(program: Command): void {
.command('void <generation>')
.description('Void a UAT batch so it can never merge; the next merge-train tick removes its worktree and uat/* branches (with the train on, it may assemble a fresh batch from features still ready)')
.option('--reason <text>', 'why the batch is voided (stored on the batch and journaled)')
.action((generation: string, opts: { reason?: string }) => mergeVoidCommand(generation, opts));
.option('--abandon-partial', 'abandon a partially promoted batch that cannot be resumed; landed repos keep their merges (needs --reason)')
.action((generation: string, opts: { reason?: string; abandonPartial?: boolean }) => mergeVoidCommand(generation, opts));
}
Loading
Loading