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

parallelize per-branch dispatch-hint lookups in formatInFlightForPrompt

[._.]/ Adam Eivy437ef1918e53
diff --git a/server/services/branchReconcile.js b/server/services/branchReconcile.js
index a506ac14ae..87760444c1 100644
--- a/server/services/branchReconcile.js
+++ b/server/services/branchReconcile.js
@@ -1452,8 +1452,11 @@ export function limitBranchesForAgent(inFlight, branchesPerAgent) {
* The recommended `model:`/`effort:` line for one issue-derived branch, or ''
* when the branch is not issue-derived, the issue carries neither label, or
* the forge read fails. A failed read must never block or reshape
- * reconciliation — `getIssueDispatchHint` already collapses every failure mode
- * to `status: 'unavailable'`, so this just omits the line for that branch.
+ * reconciliation: `getIssueDispatchHint` already collapses every failure mode
+ * to `status: 'unavailable'` and never rejects, but the `.catch` here holds
+ * that guarantee even if a future forge implementation (or a test double)
+ * throws instead — this call site is the one place the "never block" rule
+ * actually has to hold, so it doesn't trust the callee alone to keep it.
* @param {string} branchName
* @param {string} [repoPath] - repo dir gh resolves the remote from
* @returns {Promise<string>}
@@ -1477,11 +1480,15 @@ async function dispatchHintLineForBranch(branchName, repoPath) {
* @returns {Promise<string>}
*/
export async function formatInFlightForPrompt(inFlight, { defaultBranch, actions, branchesPerAgent, repoPath } = {}) {
+ // One gh round-trip per issue-derived branch — resolved in parallel (not
+ // inline in the loop below) so N branches cost one round-trip's latency,
+ // not N of them in series.
+ const dispatchLines = await Promise.all(inFlight.map((b) => dispatchHintLineForBranch(b.branch, repoPath)));
const lines = [`Default branch: \`${defaultBranch}\`. Branches to reconcile (${inFlight.length}):`, ''];
if (Number.isInteger(branchesPerAgent) && branchesPerAgent > 0) {
lines.splice(1, 0, `This coordinator run is limited to up to ${branchesPerAgent} branch(es); finish every branch listed below before reporting done.`);
}
- for (const b of inFlight) {
+ inFlight.forEach((b, i) => {
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)' : ''}`);
@@ -1499,8 +1506,7 @@ export async function formatInFlightForPrompt(inFlight, { defaultBranch, actions
if (b.collisionPaths?.length) {
lines.push(`- Also changed on \`${defaultBranch}\` since this branch diverged (**read these first — they are where supersession shows up**): ${b.collisionPaths.map((p) => `\`${p}\``).join(', ')}`);
}
- const dispatchLine = await dispatchHintLineForBranch(b.branch, repoPath);
- if (dispatchLine) lines.push(dispatchLine);
+ if (dispatchLines[i]) lines.push(dispatchLines[i]);
lines.push(`- Do: ${desiredEndState(b.state, actions, {
prNumber: b.openPr?.number,
worktreePath: b.worktreePath,
@@ -1508,6 +1514,6 @@ export async function formatInFlightForPrompt(inFlight, { defaultBranch, actions
behind: b.behind
})}`);
lines.push('');
- }
+ });
return lines.join('\n');
}