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

fix: in-flight claim detection surfaces failed PR listings and lists up to 500 PRs (#12981) (#13052)

[._.]/ec1d21861871
diff --git a/server/services/perpetualWork.js b/server/services/perpetualWork.js
index ddb2bcb0b1..d78f9651d1 100644
--- a/server/services/perpetualWork.js
+++ b/server/services/perpetualWork.js
@@ -156,11 +156,16 @@ async function resolveGitlabNamespace(repoPath) {
return segments.join('/');
}
+// gh pr list defaults to 30; match the issue listing cap
+const IN_FLIGHT_PR_LIMIT = 500;
+
/**
* Collect the set of issue numbers currently in flight, evidenced by an open
* `claim/issue-<num>` / `cos/.../issue-<num>/...` / `next/issue-<num>` (slashdo
* `/do:next`, #8161) branch (local or remote) or an open PR/MR source ref.
- * Best-effort — degrades to whatever evidence is reachable. `forge` selects
+ * Local branches are supplementary; a failed PR/MR listing (timeout, auth,
+ * rate limit) returns `{ error, detail }` rather than an under-counted set,
+ * since a short set makes issues with an open PR look claimable. `forge` selects
* how open changes are listed: GitHub PR head refs (`gh pr list`) vs GitLab
* MR source branches (`glab mr list`).
*/
@@ -169,11 +174,14 @@ async function inFlightIssueNumbers(repoPath, forge = 'github', env) {
// The branch list and the PR/MR list are independent CLI calls — run concurrently.
const prListCall = forge === 'gitlab'
? runCli('glab', withGlabJson(['mr', 'list', '--per-page', '100']), repoPath, env)
- : runCli('gh', ['pr', 'list', '--state', 'open', '--json', 'headRefName', '-q', '.[].headRefName'], repoPath, env);
+ : runCli('gh', ['pr', 'list', '--state', 'open', '--json', 'headRefName', '--limit', String(IN_FLIGHT_PR_LIMIT), '-q', '.[].headRefName'], repoPath, env);
const [branchRes, prRes] = await Promise.all([
runCli('git', ['branch', '-a', '--no-color', '--format=%(refname:short)'], repoPath, env),
prListCall
]);
+ if (prRes.code !== 0) {
+ return { error: `${forge === 'gitlab' ? 'glab' : 'gh'}-unavailable`, detail: redactCliDetail(prRes.stderr) };
+ }
const refs = (branchRes.stdout || '').split('\n').map((s) => s.trim()).filter(Boolean);
if (forge === 'gitlab') {
// glab returns MR objects as JSON; the in-flight ref is each MR's source_branch.
@@ -191,7 +199,7 @@ async function inFlightIssueNumbers(repoPath, forge = 'github', env) {
const n = issueNumberFromRef(ref);
if (n != null) nums.add(n);
}
- return nums;
+ return { nums };
}
/**
@@ -758,12 +766,17 @@ async function detectForgeIssues(forgeKey, app, { issueAuthorFilter = 'self', is
}
const hasAssignedIssue = issues.some((issue) => Array.isArray(issue.assignees) && issue.assignees.length > 0);
- const [inFlight, currentLoginResult] = await Promise.all([
+ const [inFlightResult, currentLoginResult] = await Promise.all([
inFlightIssueNumbers(repoPath, cfg.inFlightForge, resolvedEnv),
hasAssignedIssue
? resolveAuthenticatedLogin(cfg.cli, cfg.selfLoginArgs, repoPath, resolvedEnv)
: Promise.resolve({ login: null })
]);
+ if (inFlightResult.error) {
+ console.log(`⏭️ In-flight claim evidence unavailable (${inFlightResult.error}); skipping this dispatch`);
+ return forgeTransient(cfg, inFlightResult.error, null, inFlightResult.detail);
+ }
+ const inFlight = inFlightResult.nums;
if (currentLoginResult.error) return forgeTransient(cfg, currentLoginResult.error, null, currentLoginResult.detail);
const currentLogin = currentLoginResult.login || null;
const total = issues.length;
diff --git a/server/services/perpetualWork.test.js b/server/services/perpetualWork.test.js
index d069cb5232..7880ba8a8e 100644
--- a/server/services/perpetualWork.test.js
+++ b/server/services/perpetualWork.test.js
@@ -487,6 +487,34 @@ describe('perpetualWork', () => {
expect(out).toMatchObject({ actionable: false, reason: 'gh-unavailable', transient: true });
});
+ it('lists open PRs with an explicit limit and excludes PR-backed issues beyond the first 30', async () => {
+ const prRefs = Array.from({ length: 40 }, (_, i) => `claim/issue-${i + 100}`).join('\n');
+ routeSpawn({
+ 'gh issue': { stdout: JSON.stringify([
+ { number: 139, title: 'deep PR', assignees: [], labels: [] },
+ { number: 500, title: 'free', assignees: [], labels: [] }
+ ]) },
+ 'git branch': { stdout: 'main\n' },
+ 'gh pr': { stdout: prRefs }
+ });
+ const out = await detectGithubIssues(app, { issueAuthorFilter: 'any' });
+ expect(out.sample).toEqual([500]);
+ expect(out.inFlightCount).toBe(1);
+ const prCall = spawn.mock.calls.find(([cmd, args]) => cmd === 'gh' && args[0] === 'pr');
+ expect(prCall[1]).toEqual(expect.arrayContaining(['--limit', '500']));
+ });
+
+ it('stays transient instead of under-counting in-flight work when gh pr list fails', async () => {
+ routeSpawn({
+ 'gh issue': { stdout: JSON.stringify([{ number: 7, title: 'has a PR', assignees: [], labels: [] }]) },
+ 'git branch': { stdout: 'main\n' },
+ 'gh pr': { stdout: '', code: 1, stderr: 'API rate limit exceeded' }
+ });
+ const out = await detectGithubIssues(app, { issueAuthorFilter: 'any' });
+ expect(out).toMatchObject({ actionable: false, reason: 'gh-unavailable', transient: true });
+ expect(out.inFlightCount).toBeUndefined();
+ });
+
it('reports the open/in-flight breakdown when nothing is claimable (the "40 open but parked" case)', async () => {
routeSpawn({
'gh issue': { stdout: JSON.stringify([
@@ -940,6 +968,16 @@ describe('perpetualWork', () => {
expect(out).toMatchObject({ actionable: false, reason: 'glab-unavailable', transient: true });
});
+ it('stays transient instead of under-counting in-flight work when glab mr list fails', async () => {
+ routeSpawn({
+ 'glab issue': { stdout: JSON.stringify([{ iid: 10, title: 'has an MR', assignees: [], labels: [] }]) },
+ 'git branch': { stdout: 'main\n' },
+ 'glab mr': { stdout: '', code: 1, stderr: 'timeout' }
+ });
+ const out = await detectGitlabIssues(app, { issueAuthorFilter: 'any' });
+ expect(out).toMatchObject({ actionable: false, reason: 'glab-unavailable', transient: true });
+ });
+
it('reports a transient failure when glab exits non-zero', async () => {
routeSpawn({ 'glab issue': { stdout: '', code: 1 } });
const out = await detectGitlabIssues(app, { issueAuthorFilter: 'any' });