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

reconcile never-pushed branches instead of parking on "no branches in flight"

[._.]/ Adam Eivyfa8b4a51f8d0
diff --git a/server/services/branchReconcile.js b/server/services/branchReconcile.js
index c14890bdd3..7f94b834a7 100644
--- a/server/services/branchReconcile.js
+++ b/server/services/branchReconcile.js
@@ -121,10 +121,14 @@ const PR_LIST_LIMIT = 200;
* MERGED — work is fully in the default branch → deterministic cleanup
* CONFLICTED — open PR with merge conflicts → agent resolves
* IN_REVIEW — open PR, otherwise → agent drives to merge
- * NEEDS_PR — pushed, not merged, no PR, clean → agent verifies + opens PR
- * WIP — local-only, dirty, or LIVE-owned → skip + report (never touch)
+ * NEEDS_PR — unmerged work, no PR, clean → agent verifies + opens PR
+ * (pushed-with-no-PR, or never pushed but holding commits)
+ * WIP — bare pointer, dirty, or LIVE-owned → skip + report (never touch)
*
- * @param {{ hasUpstream:boolean, isMerged:boolean, worktreeDirty:boolean, abandonedAgentWorktree?:boolean, liveOwnerReason?:string|null, openPr:({mergeable?:string}|null), prStateUnavailable?:boolean }} input
+ * @param {{ hasUpstream:boolean, ahead?:number|null, isMerged:boolean, worktreeDirty:boolean, abandonedAgentWorktree?:boolean, liveOwnerReason?:string|null, openPr:({mergeable?:string}|null), prStateUnavailable?:boolean }} input
+ * `ahead` is the branch's own commit count over the default branch (null =
+ * unreadable). It is what makes a never-pushed branch actionable — see the
+ * NEEDS_PR gate below.
* `prStateUnavailable` means the forge could not be READ this cycle — distinct
* from `openPr: null` ("the forge answered: no open PR").
* `liveOwnerReason` is `resolveLiveOwnerReason`'s verdict for the branch — non-null
@@ -133,7 +137,7 @@ const PR_LIST_LIMIT = 200;
* dirty claim trees still remain WIP through the ordinary dirty-tree guard.
* @returns {'ABANDONED_WIP'|'MERGED'|'CONFLICTED'|'IN_REVIEW'|'NEEDS_PR'|'WIP'}
*/
-export function classifyBranch({ hasUpstream, isMerged, worktreeDirty, abandonedAgentWorktree, liveOwnerReason = null, openPr, prStateUnavailable = false }) {
+export function classifyBranch({ hasUpstream, ahead = null, isMerged, worktreeDirty, abandonedAgentWorktree, liveOwnerReason = null, openPr, prStateUnavailable = false }) {
// A dead agent's worktree that still holds uncommitted work is the ONE dirty
// case that must be driven rather than skipped — and it must be caught BEFORE
// the `isMerged` test, because an agent that exited without committing leaves
@@ -166,7 +170,20 @@ export function classifyBranch({ hasUpstream, isMerged, worktreeDirty, abandoned
// (skip + never touch) rather than dispatching an agent to open a PR that may
// already exist. MERGED above is unaffected: that verdict is pure git truth.
if (prStateUnavailable) return 'WIP';
- if (hasUpstream) return 'NEEDS_PR';
+ // Unmerged commits that nothing else owns are in-flight work whether or not
+ // they were ever PUSHED. Gating this on `hasUpstream` alone is what made a
+ // whole shelf of `claim/*` branches invisible: a /claim session that dies
+ // before its `git push -u` leaves commits ahead of the default branch with no
+ // upstream, so every run classified them WIP and parked on "no branches in
+ // flight" while the work sat there. NEEDS_PR already tells the agent to push
+ // (`/do:pr`, or `git push -u origin <branch>` by hand), so the un-pushed case
+ // needs no separate state — only to stop being skipped.
+ //
+ // `ahead` is the discriminator the upstream check was standing in for: a branch
+ // with NO commits of its own is a bare pointer with nothing to ship, and stays
+ // WIP. Unknown (`null`, an unreadable rev-list) also stays WIP — a git failure
+ // must never manufacture work.
+ if (hasUpstream || (typeof ahead === 'number' && ahead > 0)) return 'NEEDS_PR';
return 'WIP';
}
@@ -1234,6 +1251,12 @@ export function formatInFlightForPrompt(inFlight, { defaultBranch, actions, bran
const pr = b.openPr ? ` — PR #${b.openPr.number} (${b.openPr.mergeable})${b.openPr.url ? ` ${b.openPr.url}` : ''}` : ' — no PR';
lines.push(`### \`${b.branch}\` [${b.state}]${pr}`);
if (b.worktreePath) lines.push(`- Worktree: \`${b.worktreePath}\`${b.state === 'ABANDONED_WIP' ? ' (holds UNCOMMITTED work — read it before doing anything)' : ''}`);
+ // A never-pushed NEEDS_PR branch reads identically to a pushed one in this
+ // block, and the difference decides whether the push needs `-u`. State it
+ // rather than making the agent infer it from a missing PR link.
+ if (b.hasUpstream === false && b.state === 'NEEDS_PR') {
+ lines.push('- Never pushed: no upstream on `origin` — the push that opens the PR must create one (`git push -u origin <branch>`).');
+ }
if (typeof b.behind === 'number') {
lines.push(`- Drift: ${b.behind} commit(s) behind \`${defaultBranch}\`${typeof b.ahead === 'number' ? `, ${b.ahead} ahead` : ''}`);
}
diff --git a/server/services/branchReconcile.test.js b/server/services/branchReconcile.test.js
index ad02b54347..70313e5d37 100644
--- a/server/services/branchReconcile.test.js
+++ b/server/services/branchReconcile.test.js
@@ -140,8 +140,42 @@ describe('classifyBranch', () => {
liveOwnerReason: null, openPr: null
})).toBe('ABANDONED_WIP');
});
- it('local-only (no upstream), no PR → WIP', () => {
+ it('local-only bare pointer (no upstream, no commits of its own) → WIP', () => {
expect(classifyBranch({ isMerged: false, openPr: null, hasUpstream: false, worktreeDirty: false })).toBe('WIP');
+ expect(classifyBranch({ isMerged: false, openPr: null, hasUpstream: false, worktreeDirty: false, ahead: 0 })).toBe('WIP');
+ });
+
+ // The shape of eight `claim/*` branches that sat unreconciled: each /claim
+ // session committed real work and died before its `git push -u`, so the branch
+ // had commits ahead of `main` and no upstream — classified WIP, never in-flight,
+ // and every run parked on "no branches in flight" with the work still sitting there.
+ it('classifies a never-pushed branch holding commits as NEEDS_PR', () => {
+ expect(classifyBranch({
+ isMerged: false, openPr: null, hasUpstream: false, worktreeDirty: false, ahead: 2
+ })).toBe('NEEDS_PR');
+ });
+
+ it('leaves a never-pushed branch WIP when its commit count is unreadable', () => {
+ expect(classifyBranch({
+ isMerged: false, openPr: null, hasUpstream: false, worktreeDirty: false, ahead: null
+ })).toBe('WIP');
+ });
+
+ it('still protects a never-pushed branch that is dirty or live-owned', () => {
+ expect(classifyBranch({
+ isMerged: false, openPr: null, hasUpstream: false, worktreeDirty: true, ahead: 3
+ })).toBe('WIP');
+ expect(classifyBranch({
+ isMerged: false, openPr: null, hasUpstream: false, worktreeDirty: false, ahead: 3,
+ liveOwnerReason: 'worktree-active-agent'
+ })).toBe('WIP');
+ });
+
+ it('does not conclude "no PR" for a never-pushed branch when the forge was unreadable', () => {
+ expect(classifyBranch({
+ isMerged: false, openPr: null, hasUpstream: false, worktreeDirty: false, ahead: 3,
+ prStateUnavailable: true
+ })).toBe('WIP');
});
// The exact shape of the three branches that went unreconciled for weeks: a CoS
@@ -1298,6 +1332,16 @@ describe('formatInFlightForPrompt', () => {
expect(block).toContain('- Do: ');
});
+ it('flags a never-pushed NEEDS_PR branch so the agent knows the push needs -u', () => {
+ const block = formatInFlightForPrompt([
+ { branch: 'claim/issue-1', state: 'NEEDS_PR', hasUpstream: false },
+ { branch: 'claim/issue-2', state: 'NEEDS_PR', hasUpstream: true }
+ ], { defaultBranch: 'main', actions: {} });
+ const [first, second] = block.split('### `claim/issue-2`');
+ expect(first).toContain('Never pushed: no upstream on `origin`');
+ expect(second).not.toContain('Never pushed');
+ });
+
it('states the configured batch limit when supplied', () => {
const block = formatInFlightForPrompt(
[{ branch: 'next/issue-1', state: 'NEEDS_PR' }],