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: blocked-issue-reconcile resolves PR and older issue blockers (#12911)

Adam Eivye31897d72180
diff --git a/server/services/blockedIssueReconcile.js b/server/services/blockedIssueReconcile.js
index e23f3aa389..1fea519ee2 100644
--- a/server/services/blockedIssueReconcile.js
+++ b/server/services/blockedIssueReconcile.js
@@ -35,7 +35,6 @@ export const BLOCKED_LABEL = 'blocked';
// Bound the forge queries — single-user repos never realistically truncate at
// this size (mirrors issueReconcile.js's GH_LIST_LIMIT / GL_PER_PAGE).
const GH_LIST_LIMIT = 100;
-const GH_ALL_STATE_LIMIT = 300;
const GL_PER_PAGE = 100;
/**
@@ -66,47 +65,59 @@ export function parseBlockingIssueNumbers(body) {
return [...nums].sort((a, b) => a - b);
}
+/**
+ * Resolve one GitHub blocker number to 'closed' or 'open'. `issues/{n}` serves
+ * issues AND pull requests (they share a number space), at any age. A PR is
+ * satisfied only once merged: closed-unmerged means the dependency was
+ * abandoned, which needs a human rather than an automatic unblock. Returns
+ * null when the lookup fails, so the number stays absent and reads as open.
+ */
+async function resolveGithubBlockerState({ repoSpec, apiHost, fullName }, number) {
+ const raw = await execGh(['api', `repos/${fullName}/issues/${number}`, '--hostname', apiHost], undefined, { backoffKey: repoSpec }).catch((err) => {
+ console.error(`❌ blocked-issue-reconcile: blocker lookup #${number} failed for ${repoSpec}: ${err.message}`);
+ return null;
+ });
+ const blocker = safeJSONParse(raw, null);
+ if (!blocker || typeof blocker !== 'object') return null;
+ if (blocker.pull_request) return blocker.pull_request.merged_at ? 'closed' : 'open';
+ return normalizeIssueState(blocker.state);
+}
+
/**
* Fetch GitHub's open `blocked` issues plus a `number → state` map covering
- * every issue (open + closed, bounded by GH_ALL_STATE_LIMIT) so each blocker
- * reference can be resolved from one extra call rather than one `gh issue view`
- * per blocker. Returns null on any gh failure — the caller treats null as
- * "skip this cycle", never as "no blocked issues" or "every blocker is open".
+ * each distinct blocker they name, looked up individually so PR blockers and
+ * blockers of any age resolve. Returns null on a gh failure listing the blocked
+ * issues — the caller treats null as "skip this cycle", never as "no blocked
+ * issues". A failed per-blocker lookup is left out of the map (reads as open).
* @returns {Promise<{ blocked: object[], stateByNumber: Map<number,string> }|null>}
*/
async function getGithubBlockedState(repoSpec, apiHost, fullName) {
const forge = await ensureForgeReachable('blocked-issue-reconcile', { hostname: apiHost });
if (!forge.ok) return null;
- const ghList = (args, what) => execGh(args, undefined, { backoffKey: repoSpec }).catch((err) => {
- console.error(`❌ blocked-issue-reconcile: ${what} failed for ${repoSpec}: ${err.message}`);
+ const blockedRaw = await execGh(['issue', 'list', '--repo', repoSpec, '--state', 'open',
+ '--label', BLOCKED_LABEL, '--limit', String(GH_LIST_LIMIT),
+ '--json', 'number,title,body,url,author'], undefined, { backoffKey: repoSpec }).catch((err) => {
+ console.error(`❌ blocked-issue-reconcile: gh issue list --label blocked failed for ${repoSpec}: ${err.message}`);
return null;
});
- const [blockedRaw, allRaw] = await Promise.all([
- ghList(['issue', 'list', '--repo', repoSpec, '--state', 'open',
- '--label', BLOCKED_LABEL, '--limit', String(GH_LIST_LIMIT),
- '--json', 'number,title,body,url,author'], 'gh issue list --label blocked'),
- ghList(['issue', 'list', '--repo', repoSpec, '--state', 'all',
- '--limit', String(GH_ALL_STATE_LIMIT), '--json', 'number,state'], 'gh issue list --state all'),
- ]);
-
const blocked = safeJSONParse(blockedRaw, null);
if (!Array.isArray(blocked)) return null;
// The blocked list can legitimately be empty (nothing to unblock) — a caller
// reads that as "no candidates", not "gh failed", because it parsed fine.
- const all = safeJSONParse(allRaw, null);
- if (!Array.isArray(all)) return null;
const trust = await createGithubActorTrust({ runGh: execGh, host: apiHost, repoFullName: fullName });
const trustedBlocked = [];
for (const issue of blocked) {
if (await trust.isTrusted(issue.author?.login)) trustedBlocked.push(issue);
}
+ const blockerNumbers = new Set(trustedBlocked.flatMap((i) => parseBlockingIssueNumbers(i.body)));
const stateByNumber = new Map();
- for (const issue of all) {
- if (Number.isInteger(issue?.number)) stateByNumber.set(issue.number, normalizeIssueState(issue.state));
- }
+ await Promise.all([...blockerNumbers].map(async (n) => {
+ const state = await resolveGithubBlockerState({ repoSpec, apiHost, fullName }, n);
+ if (state) stateByNumber.set(n, state);
+ }));
return {
blocked: trustedBlocked.map((i) => ({ number: i.number, title: i.title || '', url: i.url || '', body: i.body || '' })),
stateByNumber,
diff --git a/server/services/blockedIssueReconcile.test.js b/server/services/blockedIssueReconcile.test.js
index d784dcb896..977c7ddc0f 100644
--- a/server/services/blockedIssueReconcile.test.js
+++ b/server/services/blockedIssueReconcile.test.js
@@ -115,43 +115,74 @@ describe('classifyBlockedIssues', () => {
});
describe('gatherBlockedIssueState (GitHub)', () => {
+ const blockedIssue = (body = 'Blocked by #10', login = 'maintainer') =>
+ ({ number: 5, author: { login }, title: 'Feature X', body, url: 'u' });
+ // Routes by argv: the blocked-issue list, `api repos/.../issues/N` blocker
+ // lookups (value or Error per number), and the trust helper's user lookup.
+ const mockGh = (list, blockers = {}) => {
+ execGhMock.mockImplementation(async (args) => {
+ if (args[0] === 'issue') return JSON.stringify(list);
+ if (args[0] === 'api' && args[1].startsWith('repos/')) {
+ const hit = blockers[Number(args[1].split('/').pop())];
+ if (hit instanceof Error) throw hit;
+ return hit === undefined ? '{}' : JSON.stringify(hit);
+ }
+ return args.at(-1) === 'user' ? JSON.stringify({ login: 'maintainer' }) : '[]';
+ });
+ };
+ const ready = async () => (await gatherBlockedIssueState('/repo')).ready;
+
it('returns ready=[] when the blocked list is empty', async () => {
- execGhMock.mockResolvedValueOnce('[]').mockResolvedValueOnce('[]');
+ mockGh([]);
const result = await gatherBlockedIssueState('/repo');
expect(result.forge).toBe('github');
expect(result.ready).toEqual([]);
- expect(execGhMock.mock.calls.slice(0, 2).map(([, , options]) => options)).toEqual([
- { backoffKey: 'github.com/atomantic/PortOS' },
- { backoffKey: 'github.com/atomantic/PortOS' },
- ]);
+ expect(execGhMock.mock.calls[0][2]).toEqual({ backoffKey: 'github.com/atomantic/PortOS' });
});
it('resolves a blocked issue whose named blocker is now closed', async () => {
- execGhMock
- .mockResolvedValueOnce(JSON.stringify([{ number: 5, author: { login: 'maintainer' }, title: 'Feature X', body: 'Blocked by #10', url: 'u' }]))
- .mockResolvedValueOnce(JSON.stringify([{ number: 10, state: 'CLOSED' }, { number: 5, state: 'OPEN' }]));
- const result = await gatherBlockedIssueState('/repo');
- expect(result.ready).toEqual([
+ mockGh([blockedIssue()], { 10: { state: 'closed' } });
+ expect(await ready()).toEqual([
expect.objectContaining({ number: 5, blockingNumbers: [10], closedBlockers: [10], openBlockers: [] }),
]);
+ const lookup = execGhMock.mock.calls.find(([args]) => args[0] === 'api' && args[1].startsWith('repos/'));
+ expect(lookup[0].slice(1)).toEqual(['repos/atomantic/PortOS/issues/10', '--hostname', 'github.com']);
+ expect(lookup[2]).toEqual({ backoffKey: 'github.com/atomantic/PortOS' });
+ });
+
+ it('unblocks on a merged PR blocker but not an open or closed-unmerged one', async () => {
+ const pr = (state, merged_at) => ({ state, pull_request: { merged_at } });
+ mockGh([blockedIssue('Blocked by #11')], { 11: pr('closed', '2026-10-01T00:00:00Z') });
+ expect(await ready()).toHaveLength(1);
+ mockGh([blockedIssue('Blocked by #11')], { 11: pr('open', null) });
+ expect(await ready()).toEqual([]);
+ mockGh([blockedIssue('Blocked by #11')], { 11: pr('closed', null) });
+ expect(await ready()).toEqual([]);
+ });
+
+ it('requires every named blocker, issue or PR, to be satisfied', async () => {
+ mockGh([blockedIssue('Blocked by #10, #11')], {
+ 10: { state: 'closed' }, 11: { state: 'open', pull_request: { merged_at: null } },
+ });
+ expect(await ready()).toEqual([]);
+ });
+
+ it('leaves the issue blocked when a blocker lookup fails', async () => {
+ mockGh([blockedIssue('Blocked by #10, #11')], { 10: { state: 'closed' }, 11: new Error('gh blip') });
+ expect(await ready()).toEqual([]);
});
it('does not unblock externally authored or unknown-author issues even with closed dependencies', async () => {
- execGhMock
- .mockResolvedValueOnce(JSON.stringify([
- { number: 5, author: { login: 'external' }, body: 'Blocked by #10' },
- { number: 6, body: 'Blocked by #10' },
- ]))
- .mockResolvedValueOnce(JSON.stringify([{ number: 10, state: 'CLOSED' }]));
- expect((await gatherBlockedIssueState('/repo')).ready).toEqual([]);
+ mockGh([
+ blockedIssue('Blocked by #10', 'external'),
+ { number: 6, body: 'Blocked by #10' },
+ ], { 10: { state: 'closed' } });
+ expect(await ready()).toEqual([]);
});
it('leaves a blocked issue out of ready when its blocker is still open', async () => {
- execGhMock
- .mockResolvedValueOnce(JSON.stringify([{ number: 5, author: { login: 'maintainer' }, title: 'Feature X', body: 'Blocked by #10', url: 'u' }]))
- .mockResolvedValueOnce(JSON.stringify([{ number: 10, state: 'OPEN' }]));
- const result = await gatherBlockedIssueState('/repo');
- expect(result.ready).toEqual([]);
+ mockGh([blockedIssue()], { 10: { state: 'open' } });
+ expect(await ready()).toEqual([]);
});
it('returns null (skip, not "nothing to unblock") when gh is unreachable', async () => {