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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: probe GitHub before Layered Intelligence filing (#7695)
[._.]/ Adam Eivyb67e6a2c02ad
diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.js b/server/services/autonomousJobs/layeredIntelligenceHooks.jsindex d33a98f18c..190682e255 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.js@@ -78,7 +78,7 @@ import { recordFiledProposal, listOutcomesResult, reconcileOutcomes, listOutcomefunction outcomesTrackerSupported(filer) {return filer === 'forge' || filer === 'jira' || filer === 'plan'}-import { resolveAppWorkTracker } from '../../lib/workTracker.js'+import { resolveAppWorkTracker, resolveRepoForgeTarget } from '../../lib/workTracker.js'import { tryReadFile } from '../../lib/fileUtils.js'import { resolveAgentProviderPin } from '../appTaskProviderPin.js'import { PROGRAMMATIC_OUTPUT_COMPLETION_HEADING } from '../../lib/agentSentinel.js'@@ -109,11 +109,16 @@ async function resolveLiContext(app) {const filer = filerForTracker(tracker.resolved)const forgeCli = tracker.forge // 'gh' | 'glab' | nullconst cwd = app.repoPath+ const preferredForge = (tracker.resolved === 'github' || tracker.resolved === 'gitlab')+ ? tracker.resolved+ : null+ const forgeTarget = await resolveRepoForgeTarget(cwd, { preferredForge })+ const apiHost = forgeTarget?.apiHost || nullconst jira = (filer === 'jira' && app.jira?.enabled && app.jira?.instanceId && app.jira?.projectKey)? { instanceId: app.jira.instanceId, projectKey: app.jira.projectKey, issueType: app.jira.issueType || 'Task' }: null- return { isPortos, config, tracker, filer, forgeCli, cwd, jira }+ return { isPortos, config, tracker, filer, forgeCli, cwd, apiHost, jira }}/**@@ -238,7 +243,7 @@ function buildCompletionContract() {export async function buildTaskInput({ app } = {}) {if (!app) return { skip: { reason: 'no-app' } }const ctx = await resolveLiContext(app)- const { isPortos, config, tracker, filer, forgeCli, cwd, jira } = ctx+ const { isPortos, config, tracker, filer, forgeCli, cwd, apiHost, jira } = ctx// A skip means no agent spawns, so processTaskOutput never records the run —// record the last-run outcome HERE (mirrors the old handler's settle()) so the@@ -264,14 +269,11 @@ export async function buildTaskInput({ app } = {}) {// forge, so running the reasoner now would burn a provider call on a proposal// we could neither dedup nor file. Skip with the probe's single log line.if (filer === 'forge' && forgeCli === 'gh') {- const [{ ensureForgeReachable }, { githubApiHost }] = await Promise.all([- import('../github.js'),- import('../../lib/workTracker.js')- ])- // Probed against the app's OWN forge host (`tracker.host`), not gh's+ const { ensureForgeReachable } = await import('../github.js')+ // Probed against the app's OWN forge API host, not gh's// default: a bare probe would skip a healthy GitHub Enterprise app whenever// github.com is unreachable, and run one whose enterprise host is down.- const forge = await ensureForgeReachable('layered-intelligence', { hostname: githubApiHost(tracker.host) })+ const forge = await ensureForgeReachable('layered-intelligence', { hostname: apiHost })if (!forge.ok) return skip('skipped', 'forge-unreachable')}@@ -444,10 +446,11 @@ async function resolveProposalPlanner(agentId) {/*** File the proposal via the resolved tracker's filer (forge / jira / plan).*/-async function fileProposal({ filer, forgeCli, cwd, app, proposal, jira, planner }) {+async function fileProposal({ filer, forgeCli, cwd, apiHost, app, proposal, jira, planner }) {if (filer === 'forge' && forgeCli) {return fileProposalToForge({- cli: forgeCli, cwd, title: proposal.title, body: proposal.body, slug: proposal.slug,+ cli: forgeCli, cwd, hostname: forgeCli === 'gh' ? apiHost : null,+ title: proposal.title, body: proposal.body, slug: proposal.slug,model: proposal.model, effort: proposal.effort,goodFirstIssue: proposal.goodFirstIssue, helpWanted: proposal.helpWanted, planner})@@ -556,7 +559,7 @@ export async function processTaskOutput({ appId, success, payload, agentId } = {if (success === false) return settle({ action: 'no-op', reason: 'agent-failed' })const ctx = await resolveLiContext(app)- const { isPortos, config, tracker, filer, forgeCli, cwd, jira } = ctx+ const { isPortos, config, tracker, filer, forgeCli, cwd, apiHost, jira } = ctx// The payload IS the reasoner's JSON object (parsed from the sentinel). A null/// malformed payload is the "returned nothing usable" case.@@ -663,7 +666,7 @@ export async function processTaskOutput({ appId, success, payload, agentId } = {// that was scheduled. Unresolvable (a pre-upgrade record, or no agentId) ⇒// no planner label, never a guess.const planner = await resolveProposalPlanner(agentId)- const filed = await fileProposal({ filer, forgeCli, cwd, app, proposal, jira, planner })+ const filed = await fileProposal({ filer, forgeCli, cwd, apiHost, app, proposal, jira, planner })if (filed.success && filed.duplicate) {// The tracker already carries this slug's tag (a checked PLAN item the// reasoner re-proposed — normally caught by the dedup guard since #2620,diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js b/server/services/autonomousJobs/layeredIntelligenceHooks.test.jsindex a01fad1c3b..4af7a2b4c0 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.test.js@@ -14,7 +14,8 @@ vi.mock('../../lib/workTracker.js', async (importActual) => {// Real pure host→API-host mapping so the forge gate is exercised through// the exact enterprise-aware resolution production uses (#3358).githubApiHost: actual.githubApiHost,- resolveAppWorkTracker: vi.fn().mockResolvedValue({ resolved: 'github', forge: 'gh', host: 'github.com' })+ resolveAppWorkTracker: vi.fn().mockResolvedValue({ resolved: 'github', forge: 'gh', host: 'github.com' }),+ resolveRepoForgeTarget: vi.fn().mockResolvedValue({ forge: 'github', apiHost: 'github.com' })};});@@ -133,7 +134,7 @@ import { buildTaskInput, isTaskOutputPayload, processTaskOutput } from './layereimport * as li from '../layeredIntelligence.js';import { recordFiledProposal, listOutcomesResult, reconcileOutcomes, listOutcomes } from '../layeredIntelligenceOutcomes.js';import * as apps from '../apps.js';-import { resolveAppWorkTracker } from '../../lib/workTracker.js';+import { resolveAppWorkTracker, resolveRepoForgeTarget } from '../../lib/workTracker.js';import { tryReadFile } from '../../lib/fileUtils.js';import { getProviderById } from '../providers.js';import { getTaskInterval } from '../taskSchedule.js';@@ -150,6 +151,7 @@ const APP = { id: 'app-1', name: 'App One', repoPath: '/repo', taskTypeOverridesbeforeEach(() => {vi.clearAllMocks();resolveAppWorkTracker.mockResolvedValue({ resolved: 'github', forge: 'gh' });+ resolveRepoForgeTarget.mockResolvedValue({ forge: 'github', apiHost: 'github.com' });getProviderById.mockImplementation(async (id) => ({ id, type: 'cli' }));getTaskInterval.mockResolvedValue({ providerId: null, model: null });li.getEffectiveConfig.mockReturnValue({ providerId: 'ollama', model: 'qwen', allowedScopes: ['app-improvement'], sources: {} });@@ -693,6 +695,7 @@ describe('processTaskOutput', () => {li.fileProposalToForge.mockResolvedValue({ success: true, number: 77 });const out = await processTaskOutput({ appId: 'app-1', success: true, payload: { proposal: {} } });expect(li.fileProposalToForge).toHaveBeenCalled();+ expect(li.fileProposalToForge).toHaveBeenCalledWith(expect.objectContaining({ hostname: 'github.com' }));expect(out).toMatchObject({ action: 'filed', filedNumber: 77, reason: null });expect(apps.updateAppLayeredIntelligence).toHaveBeenCalledWith('app-1', expect.objectContaining({ lastRunAction: 'filed', lastRunRef: '#77' }));});diff --git a/server/services/layeredIntelligence/forgeFiler.js b/server/services/layeredIntelligence/forgeFiler.jsindex 38cc6ae8d9..52957ea289 100644--- a/server/services/layeredIntelligence/forgeFiler.js+++ b/server/services/layeredIntelligence/forgeFiler.js@@ -247,7 +247,7 @@ export async function ensureForgeLabels({ cli, cwd, env, extraLabels = [], exec* `planner:<model>` (`planner::<model>` on GitLab).*/export async function fileProposalToForge({- cli, cwd, env, title, body, slug, model, effort, goodFirstIssue, helpWanted, planner, exec = runCli+ cli, cwd, env, hostname, title, body, slug, model, effort, goodFirstIssue, helpWanted, planner, exec = runCli} = {}) {if (!isDispatchModel(model) || !isDispatchEffort(effort)) {return { success: false, error: 'Issue filing requires valid model and effort dispatch labels; investigate and supply both before retrying' };@@ -255,7 +255,7 @@ export async function fileProposalToForge({const extras = forgeIssueLabels({ model, effort, goodFirstIssue, helpWanted, planner, cli }).map((name) => dispatchLabelSpec(name, { cli }));const labels = [LI_LABEL_SPEC, ...extras.filter(Boolean)];- const result = await fileForgeIssue({ cli, cwd, env, title, body: `${body}\n\n${slugMarker(slug)}`, labels, exec });+ const result = await fileForgeIssue({ cli, cwd, env, hostname, title, body: `${body}\n\n${slugMarker(slug)}`, labels, exec });return result.ok? { success: true, number: result.number, url: result.url }: { success: false, error: result.error };diff --git a/server/services/layeredIntelligence/forgeFiler.test.js b/server/services/layeredIntelligence/forgeFiler.test.jsnew file mode 100644index 0000000000..1d7be3a3f8--- /dev/null+++ b/server/services/layeredIntelligence/forgeFiler.test.js@@ -0,0 +1,29 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';++const fileForgeIssueMock = vi.fn();+vi.mock('../appIssues.js', () => ({+ fileForgeIssue: (...args) => fileForgeIssueMock(...args),+ ensureForgeIssueLabels: vi.fn()+}));++import { fileProposalToForge } from './forgeFiler.js';++describe('fileProposalToForge', () => {+ beforeEach(() => vi.clearAllMocks());++ it('forwards the GitHub API host so the shared filer can probe before exec', async () => {+ fileForgeIssueMock.mockResolvedValue({ ok: false, error: 'GitHub is not reachable (unreachable)' });+ const exec = vi.fn();++ const result = await fileProposalToForge({+ cli: 'gh', hostname: 'api.github.example', cwd: '/repo', title: 'T', body: 'B', slug: 's',+ model: 'light', effort: 'medium', exec+ });++ expect(result).toEqual({ success: false, error: expect.stringContaining('GitHub is not reachable') });+ expect(fileForgeIssueMock).toHaveBeenCalledWith(expect.objectContaining({+ cli: 'gh', hostname: 'api.github.example', exec+ }));+ expect(exec).not.toHaveBeenCalled();+ });+});