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: handle unresolved PR host in detectForgeCli (#4007)

[._.]/ Adam Eivy2ee73e5f3b9d
diff --git a/.changelog/next/fixed-issue-4007.md b/.changelog/next/fixed-issue-4007.md
new file mode 100644
index 0000000000..5c356eb1f5
--- /dev/null
+++ b/.changelog/next/fixed-issue-4007.md
@@ -0,0 +1 @@
+- detectForgeCli defaults to unknown on an unresolved PR host (#4007)
diff --git a/server/lib/gitForge.js b/server/lib/gitForge.js
index 4501582217..78f06c30f5 100644
--- a/server/lib/gitForge.js
+++ b/server/lib/gitForge.js
@@ -43,12 +43,13 @@ export function pickGhAccountForOwner(ownerLogin, availableAccounts) {
/**
* Pick which forge CLI to use for a given remote host.
- * github.com → 'gh'
- * gitlab.com / *gitlab* → 'glab' (covers self-hosted GitLab like gitlab.example.com)
- * anything else → 'gh' (default; harmless when gh isn't authed for that host)
+ * github.com → 'gh'
+ * gitlab.com / *gitlab* → 'glab' (covers self-hosted GitLab like gitlab.example.com)
+ * falsy / null / undefined / '' → 'unknown' (unresolved host; cannot assume gh)
+ * anything else → 'gh' (default; harmless when gh isn't authed for that host)
*/
export function detectForgeCli(host) {
- if (!host) return 'gh';
+ if (!host) return 'unknown';
if (host === 'github.com') return 'gh';
if (host === 'gitlab.com' || /(^|\.)gitlab\./i.test(host)) return 'glab';
return 'gh';
diff --git a/server/lib/gitForge.test.js b/server/lib/gitForge.test.js
index 72e25d5efe..34c39c3119 100644
--- a/server/lib/gitForge.test.js
+++ b/server/lib/gitForge.test.js
@@ -62,10 +62,11 @@ describe('detectForgeCli', () => {
expect(detectForgeCli('GitLab.Internal.Co')).toBe('glab');
});
- it('defaults to gh for unknown or empty hosts', () => {
+ it('defaults to gh for unknown non-empty hosts, returns unknown for falsy hosts', () => {
expect(detectForgeCli('bitbucket.org')).toBe('gh');
- expect(detectForgeCli(null)).toBe('gh');
- expect(detectForgeCli('')).toBe('gh');
+ expect(detectForgeCli(null)).toBe('unknown');
+ expect(detectForgeCli(undefined)).toBe('unknown');
+ expect(detectForgeCli('')).toBe('unknown');
});
});
diff --git a/server/services/agentTuiSpawning.js b/server/services/agentTuiSpawning.js
index a407d04fea..ee043d53bb 100644
--- a/server/services/agentTuiSpawning.js
+++ b/server/services/agentTuiSpawning.js
@@ -861,7 +861,7 @@ export async function spawnTuiAgent({
// `merged` starts false and only a `known` MERGED answer flips it: a gh we
// could not run (firewalled, offline) is NOT evidence of anything and must
// leave the pre-existing verdicts untouched. GitHub only — `gh pr view`
- // against a GitLab MR answers nothing, so those follow-ups keep prior behavior.
+ // against a GitLab MR or an unresolved host answers nothing, so those follow-ups keep prior behavior.
const prFollowUpRef = isTruthyMetaFn(task.metadata?.reviewLoopFollowUp)
&& detectForgeCli(task.metadata?.reviewLoopPRHost) === 'gh'
? (task.metadata?.reviewLoopPRUrl || task.metadata?.reviewLoopPRNumber || null)
diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.js
index aa46baf043..c8e745ba7e 100644
--- a/server/services/agentTuiSpawning.test.js
+++ b/server/services/agentTuiSpawning.test.js
@@ -97,8 +97,14 @@ vi.mock('./agentState.js', async (importOriginal) => ({
// only `git.js` would leave the probe shelling out to real git. Sharing the spy
// keeps every `vi.mocked(gitService.execGit)` override in this file authoritative
// for the probe too.
-const { execGitMock } = vi.hoisted(() => ({ execGitMock: vi.fn() }));
+const { execGitMock, getPullRequestStateMock } = vi.hoisted(() => ({
+ execGitMock: vi.fn(),
+ getPullRequestStateMock: vi.fn().mockResolvedValue({ status: 'known', state: 'OPEN' }),
+}));
vi.mock('../lib/execGit.js', () => ({ execGit: execGitMock }));
+vi.mock('./github.js', () => ({
+ getPullRequestState: (...args) => getPullRequestStateMock(...args),
+}));
vi.mock('./git.js', () => ({
// Default: worktree has changes so idle-complete succeeds. Tests that want
@@ -2451,6 +2457,68 @@ describe('spawnTuiAgent runtime', () => {
})
);
});
+
+ it('skips PR state polling when review-loop follow-up has an unresolved PR host (#4007)', async () => {
+ runSpawn({
+ task: {
+ id: 'task-4007',
+ description: 'do the thing',
+ metadata: {
+ reviewLoopFollowUp: 'true',
+ reviewLoopPRHost: null,
+ reviewLoopPRUrl: 'https://unknown-forge.example.com/owner/repo/pull/4007',
+ },
+ },
+ });
+
+ await flushMicrotasks();
+ await capturedOnData(Buffer.from('Codex booting...\n'));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(2000);
+ await flushMicrotasks();
+ await capturedOnData(Buffer.from('do the thing\n'));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(3600);
+ await flushMicrotasks();
+ await capturedOnData(Buffer.from('(1s · thinking with high effort)\n'));
+ await vi.advanceTimersByTimeAsync(800);
+ await capturedOnData(Buffer.from('(2s · thinking with high effort)\n'));
+ await vi.advanceTimersByTimeAsync(16000);
+ await flushMicrotasks();
+
+ expect(getPullRequestStateMock).not.toHaveBeenCalled();
+ });
+
+ it('polls PR state when review-loop follow-up has a resolved github PR host (#4007)', async () => {
+ runSpawn({
+ task: {
+ id: 'task-4007-gh',
+ description: 'do the thing',
+ metadata: {
+ reviewLoopFollowUp: 'true',
+ reviewLoopPRHost: 'github.com',
+ reviewLoopPRUrl: 'https://github.com/owner/repo/pull/4007',
+ },
+ },
+ });
+
+ await flushMicrotasks();
+ await capturedOnData(Buffer.from('Codex booting...\n'));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(2000);
+ await flushMicrotasks();
+ await capturedOnData(Buffer.from('do the thing\n'));
+ await flushMicrotasks();
+ await vi.advanceTimersByTimeAsync(3600);
+ await flushMicrotasks();
+ await capturedOnData(Buffer.from('(1s · thinking with high effort)\n'));
+ await vi.advanceTimersByTimeAsync(800);
+ await capturedOnData(Buffer.from('(2s · thinking with high effort)\n'));
+ await vi.advanceTimersByTimeAsync(16000);
+ await flushMicrotasks();
+
+ expect(getPullRequestStateMock).toHaveBeenCalledWith('https://github.com/owner/repo/pull/4007', expect.anything());
+ });
});
});
diff --git a/server/services/git.test.js b/server/services/git.test.js
index 7953b05da7..4de54da7f8 100644
--- a/server/services/git.test.js
+++ b/server/services/git.test.js
@@ -56,10 +56,11 @@ describe('detectForgeCli', () => {
expect(detectForgeCli('GitLab.Internal.Co')).toBe('glab');
});
- it('defaults to gh for unknown or empty hosts', () => {
+ it('defaults to gh for unknown non-empty hosts, returns unknown for falsy hosts', () => {
expect(detectForgeCli('bitbucket.org')).toBe('gh');
- expect(detectForgeCli(null)).toBe('gh');
- expect(detectForgeCli('')).toBe('gh');
+ expect(detectForgeCli(null)).toBe('unknown');
+ expect(detectForgeCli(undefined)).toBe('unknown');
+ expect(detectForgeCli('')).toBe('unknown');
});
});