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

feat(cos): recovery tasks emit forge-correct CLI commands (gh / glab)

Adam Eivy2d6091646667
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.js
index 86b67c72c4..d908735d25 100644
--- a/server/services/agentLifecycle.js
+++ b/server/services/agentLifecycle.js
@@ -1261,21 +1261,33 @@ export async function spawnMergeRecoveryTask(cleanupWarnings, agentId, task, app
});
emitLog('info', `🔧 Auto-created merge recovery task for stale branch ${staleBranch}`, { agentId, appName });
} else {
- // PR creation failed — spawn an agent to investigate and retry
+ // PR/MR creation failed — spawn an agent to investigate and retry. Pick gh vs
+ // glab based on the repo's forge so the recovery agent gets commands that
+ // actually work against this remote.
+ const { cli } = await git.resolveForgeForRepo(sourceWorkspace).catch(() => ({ cli: 'gh' }));
+ const isGitLab = cli === 'glab';
+ const reqWord = isGitLab ? 'MR' : 'PR';
+ const listCmd = isGitLab
+ ? `glab mr list --source-branch ${staleBranch}`
+ : `gh pr list --head ${staleBranch}`;
+ const createCmd = isGitLab
+ ? `glab mr create --source-branch ${staleBranch} --target-branch main --title '...' --description '...'`
+ : `gh pr create --head ${staleBranch} --base main --title '...' --body '...'`;
+
addTask({
- description: `${RECOVERY_TASK_PREFIX} Investigate and retry failed PR for branch ${staleBranch} in ${appName}`,
+ description: `${RECOVERY_TASK_PREFIX} Investigate and retry failed ${reqWord} for branch ${staleBranch} in ${appName}`,
priority: 'HIGH',
app: appId,
isRecovery: true,
- context: `An agent pushed branch "${staleBranch}" to ${sourceWorkspace} but automated PR creation failed. `
- + `Investigate by: (1) checking if a PR already exists for this branch: "gh pr list --head ${staleBranch}"; `
- + `(2) if no PR exists, review the branch changes and create one: "gh pr create --head ${staleBranch} --base main --title '...' --body '...'"; `
+ context: `An agent pushed branch "${staleBranch}" to ${sourceWorkspace} but automated ${reqWord} creation failed. `
+ + `Investigate by: (1) checking if a ${reqWord} already exists for this branch: "${listCmd}"; `
+ + `(2) if no ${reqWord} exists, review the branch changes and create one: "${createCmd}"; `
+ `(3) if the branch is stale or changes are already on main, delete the remote branch: "git push origin --delete ${staleBranch}". `
+ `Original agent: ${agentId}, original task: ${task?.description || 'unknown'}.`,
useWorktree: false,
}, 'user').catch(err => {
- emitLog('warn', `Failed to create PR recovery task: ${err.message}`, { agentId, staleBranch });
+ emitLog('warn', `Failed to create ${reqWord} recovery task: ${err.message}`, { agentId, staleBranch });
});
- emitLog('info', `🔧 Auto-created PR recovery task for branch ${staleBranch}`, { agentId, appName });
+ emitLog('info', `🔧 Auto-created ${reqWord} recovery task for branch ${staleBranch}`, { agentId, appName, cli });
}
}
diff --git a/server/services/cleanupAgentWorktree.test.js b/server/services/cleanupAgentWorktree.test.js
index 2596007bd1..1a5e5e5821 100644
--- a/server/services/cleanupAgentWorktree.test.js
+++ b/server/services/cleanupAgentWorktree.test.js
@@ -160,7 +160,8 @@ vi.mock('./git.js', () => ({
getRepoBranches: vi.fn(),
createPR: vi.fn(),
generatePRDescription: vi.fn(),
- deleteBranch: vi.fn().mockResolvedValue(undefined)
+ deleteBranch: vi.fn().mockResolvedValue(undefined),
+ resolveForgeForRepo: vi.fn().mockResolvedValue({ cli: 'gh', env: process.env, host: 'github.com', owner: null, account: null })
}));
vi.mock('./runner.js', () => ({
@@ -513,4 +514,20 @@ describe('spawnMergeRecoveryTask', () => {
expect(addTask).not.toHaveBeenCalled();
});
+
+ it('emits glab/MR commands when the source workspace is a GitLab repo', async () => {
+ git.resolveForgeForRepo.mockResolvedValueOnce({ cli: 'glab', env: process.env, host: 'gitlab.com', owner: 'mygroup', account: null });
+
+ const warnings = ['PR creation failed for branch feature/x: glab error. Worktree preserved for manual PR creation.'];
+ const task = { id: 'task-gl', description: 'Add thing', metadata: { app: 'gl-app' } };
+
+ await spawnMergeRecoveryTask(warnings, 'agent-gl', task, 'GitLabApp', '/mock/gl-workspace');
+
+ expect(addTask).toHaveBeenCalledTimes(1);
+ const call = addTask.mock.calls[0][0];
+ expect(call.description).toContain('MR');
+ expect(call.context).toContain('glab mr list --source-branch feature/x');
+ expect(call.context).toContain('glab mr create --source-branch feature/x --target-branch main');
+ expect(call.context).not.toContain('gh pr ');
+ });
});