Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (claude): keep the merge gate in-session and unpin the merge method

[._.]/ Adam Eivy2a906dc3dc01
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 8853fdf8fe..2f5606fdc3 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -36,3 +36,4 @@
- **A branch the reconciler picks up is now driven all the way to merged, not just to "PR opened."** When the task verified a branch was ready and opened its pull request, it reported success and exited within a minute — while CI was still running. The pull request then sat green and mergeable until the next scheduled run noticed it again. The agent now waits out the check run in-session, fixes what goes red, and merges once every required check passes and the pull request is mergeable.
- The reconciler's blanket "never merge unreviewed work" rule read as a veto on the merge step it was supposed to perform, so it has been replaced by the explicit gate each branch already carries (required CI green, mergeable, and the review it names). Merging still only ever happens through `gh pr merge` on a branch the task was handed.
- Waiting for a Copilot review on an in-review pull request is now time-boxed to 10 minutes — on a repository without Copilot review enabled, the old unbounded wait could strand a green pull request open indefinitely.
+- The merge itself is no longer pinned to a merge commit: on a repository that disallows one, the agent retries with squash and then rebase instead of stranding the branch. It also merges from the repository root and tears the worktree down before deleting the branch, so the cleanup can't fail on a branch that's still checked out.
diff --git a/server/services/branchReconcile.js b/server/services/branchReconcile.js
index b9c5d471aa..9bd6a97e83 100644
--- a/server/services/branchReconcile.js
+++ b/server/services/branchReconcile.js
@@ -356,10 +356,10 @@ export function filterActionable(inFlight, actions) {
// placeholder the agent fills in after opening it.
const driveToMerge = (pr) => [
'Opening (or approving) the PR is NOT the end state — a green PR left open is still an unfinished branch that this task will simply re-drive on its next run.',
- `Wait for CI in-session: \`gh pr checks ${pr} --required --watch --fail-fast\`, or re-poll \`gh pr checks ${pr}\` every 30s — allow up to 20 minutes for the run to finish.`,
+ `Wait for CI in-session by re-polling \`gh pr checks ${pr} --required\` every 30s — each poll prints output, which keeps this run clear of the idle reaper the way a silent \`--watch\` does not. Budget 15 minutes for the run; past that, leave the PR open and report that CI was still pending.`,
'If a required check FAILS, fix it on the branch, push, and re-poll (max 3 rounds); if it is still red after that, leave the PR open and report exactly which check failed.',
- `Once every required check is green AND the PR is MERGEABLE, merge it: \`gh pr merge ${pr} --merge --delete-branch\`.`,
- 'After the merge, delete the local branch and remove its worktree.'
+ `Once every required check is green AND the PR is MERGEABLE, merge it — from the repo root, NOT from inside the branch's worktree (\`gh\` can't delete a branch that is checked out elsewhere): \`gh pr merge ${pr} --merge --delete-branch\`. Repos differ in which methods they allow, so on a "not allowed" error retry with \`--squash\`, then \`--rebase\`. Never \`--auto\`: a queued auto-merge outlives this run, so a check that goes red afterward has nobody left to fix it.`,
+ 'After the merge, remove the branch\'s worktree first, then delete the local branch — the delete fails while a worktree still has it checked out.'
].join(' ');
/**
@@ -372,15 +372,19 @@ export function desiredEndState(state, actions, { prNumber } = {}) {
const pr = prNumber ? String(prNumber) : '<num>';
if (state === 'NEEDS_PR') {
const verify = 'Verify the branch\'s work is complete and ready (tests pass, no stubs/TODO markers, changelog present). If NOT ready, report it as incomplete and leave the branch untouched — do not open a half-baked PR.';
- // `--merge` / `--no-merge` are passed explicitly rather than inherited from
- // this machine's saved slashdo defaults, so the task's own autoMerge toggle
- // decides the outcome on every install. A spawned sub-agent can't always
- // expand a slash command, hence the by-hand equivalent.
- const byHand = 'by hand, if slash commands aren\'t available in your context: self-review the diff, `git push -u origin <branch>`, then `gh pr create` with a Summary + Test plan';
+ // `--no-merge` is passed explicitly on BOTH paths — not to disable merging,
+ // but to keep the merge decision here rather than inside slashdo. Under
+ // `--merge`, /do:pr first tries GitHub-native auto-merge and reports the PR
+ // as "queued", ending the run with CI still pending — the same unattended
+ // exit this whole change exists to close. So /do:pr runs its reviewer loop
+ // and opens the PR; the merge gate below is what finishes the branch. The
+ // flag is also stated explicitly so this machine's saved slashdo defaults
+ // (which may set `merge: true`) can't decide it either way.
+ const openPr = '`/do:pr --no-merge` — its reviewer loop runs, and the PR is left for the gate below rather than queued for auto-merge (by hand, if slash commands aren\'t available in your context: self-review the diff and fix what you find, `git push -u origin <branch>`, then `gh pr create` with a Summary + Test plan)';
if (!actionOn(actions, 'autoMerge')) {
- return `${verify} If ready, ship it with \`/do:pr --no-merge\` (${byHand}). Do NOT merge (auto-merge is disabled) — stop once the PR is open and report its URL.`;
+ return `${verify} If ready, ship it with ${openPr}. Do NOT merge (auto-merge is disabled) — stop once the PR is open and report its URL.`;
}
- return `${verify} If ready, ship it end-to-end with \`/do:pr --merge\` (${byHand}). ${driveToMerge(pr)}`;
+ return `${verify} If ready, ship it with ${openPr}. ${driveToMerge(pr)}`;
}
if (state === 'CONFLICTED') {
return 'Rebase the branch onto the default branch, resolve all conflicts, run the tests, and push.';
diff --git a/server/services/branchReconcile.test.js b/server/services/branchReconcile.test.js
index 0f62352346..bfdb54b18b 100644
--- a/server/services/branchReconcile.test.js
+++ b/server/services/branchReconcile.test.js
@@ -329,30 +329,51 @@ describe('desiredEndState', () => {
// task was supposed to finish. "PR opened" is a step, not the end state.
it('drives NEEDS_PR past the PR to a merge when autoMerge is on', () => {
const instruction = desiredEndState('NEEDS_PR', {});
- expect(instruction).toContain('/do:pr --merge');
- expect(instruction).toContain('gh pr checks <num>');
+ expect(instruction).toContain('gh pr checks <num> --required');
expect(instruction).toContain('gh pr merge <num> --merge --delete-branch');
expect(instruction).toContain('NOT the end state');
});
it('stops NEEDS_PR at an open PR when autoMerge is off', () => {
const instruction = desiredEndState('NEEDS_PR', { autoMerge: false });
- expect(instruction).toContain('/do:pr --no-merge');
expect(instruction).toContain('Do NOT merge');
expect(instruction).not.toContain('gh pr merge');
});
- it('makes both merge-bound states wait for CI in-session rather than queueing --auto', () => {
+ // `/do:pr --merge` hands the merge to slashdo, which tries GitHub-native
+ // auto-merge first and reports the PR as "queued" — ending the run with CI
+ // still pending, the exact unattended exit this instruction closes. So the PR
+ // is always opened with `--no-merge` and the merge gate stays in the Do: line.
+ it('always opens the PR with --no-merge so the merge gate stays in-session', () => {
+ for (const actions of [{}, { autoMerge: false }]) {
+ const instruction = desiredEndState('NEEDS_PR', actions);
+ expect(instruction).toContain('/do:pr --no-merge');
+ expect(instruction).not.toContain('/do:pr --merge');
+ }
+ });
+
+ it('makes both merge-bound states wait for CI in-session and forbid queued auto-merge', () => {
for (const state of ['NEEDS_PR', 'IN_REVIEW']) {
const instruction = desiredEndState(state, {});
- expect(instruction).toContain('--required --watch --fail-fast');
- expect(instruction).not.toContain('--auto');
+ expect(instruction).toContain('gh pr checks <num> --required');
+ expect(instruction).toContain('Never `--auto`');
}
});
+ // branch-reconcile runs against ANY managed app; a repo that disallows merge
+ // commits would strand the branch on a hardcoded `--merge`.
+ it('gives the merge a method fallback and keeps it out of the branch worktree', () => {
+ const instruction = desiredEndState('IN_REVIEW', {});
+ expect(instruction).toContain('`--squash`');
+ expect(instruction).toContain('`--rebase`');
+ expect(instruction).toContain('NOT from inside the branch\'s worktree');
+ // Worktree first, then the branch — the delete fails while it's checked out.
+ expect(instruction).toContain('remove the branch\'s worktree first, then delete the local branch');
+ });
+
it('names the real PR number when the branch already has one', () => {
const instruction = desiredEndState('IN_REVIEW', {}, { prNumber: 42 });
- expect(instruction).toContain('gh pr checks 42 --required --watch --fail-fast');
+ expect(instruction).toContain('gh pr checks 42 --required');
expect(instruction).toContain('gh pr merge 42 --merge --delete-branch');
expect(instruction).not.toContain('<num>');
});
diff --git a/server/services/taskPromptDefaults/integrity.snapshot.json b/server/services/taskPromptDefaults/integrity.snapshot.json
index 1410a83a58..46e3603267 100644
--- a/server/services/taskPromptDefaults/integrity.snapshot.json
+++ b/server/services/taskPromptDefaults/integrity.snapshot.json
@@ -24,7 +24,7 @@
"do-replan": "59a57f1bb445138c30ab4fa23630c6f8",
"jira-status-report": "9d374a9d8ccb92c5c8fd0aa9899e79a5",
"branch-cleanup": "8fdeb4acc2749816a47ca318b6602721",
- "branch-reconcile": "b4502b930deb020fa3a31c082c44da9e",
+ "branch-reconcile": "ecb0621588a751b1383ecd89cf514382",
"issue-reconcile": "a30f5d76b980bc9016f576047c9d5bb1",
"pr-reviewer": "add27b67daa6aa2c75717ac96a6bd625",
"pr-reviewer-security": "2050297d1cdb081a8576a781828ee44f",
diff --git a/server/services/taskPromptDefaults/prompts.js b/server/services/taskPromptDefaults/prompts.js
index 4f4c979708..708e3435a7 100644
--- a/server/services/taskPromptDefaults/prompts.js
+++ b/server/services/taskPromptDefaults/prompts.js
@@ -1274,7 +1274,7 @@ Spawn ONE sub-agent per branch (they are independent — run them in parallel) t
- Work ONLY on the branches listed above. Never touch a branch that is not listed.
- Never force-push the default branch.
- **A branch whose "Do:" line ends in a merge is not finished until it IS merged.** Its sub-agent stays alive through CI — waiting out the check run, fixing what goes red, then merging — and reports back only when the PR is merged or a specific check/review is blocking it. "PR opened, left open for review" is a completed STEP, not a completed branch: the PR just sits green until the next run re-drives it. Do not end your own run while a sub-agent is still waiting on CI.
-- Merging is gated by the "Do:" line itself (required CI green + MERGEABLE + the review it names) — that gate, not a blanket ban, is what keeps unreviewed work out of the default branch. Merge only via \`gh pr merge\`, never a local \`git merge\` into the default branch.
+- Merging is gated by the "Do:" line itself — required CI green, MERGEABLE, and the review that branch's flow ran (\`/do:pr\`'s reviewer loop for a PR this task opens; the named review for one already in review). That gate, not a blanket ban, is what keeps unreviewed work out of the default branch. Merge only via \`gh pr merge\`, never a local \`git merge\` into the default branch.
- If a sub-agent reports a branch is incomplete or blocked, leave it as-is and note it in your summary.
- Summarize what each branch ended up doing (merged / PR opened but blocked on <what> / conflicts resolved / left incomplete). When a PR is left open, name the check or review that blocked it.`,