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: refuse unresolved account pins within the spawn budget

Adam Eivye4aec1976bee
diff --git a/server/services/forgeAuth.js b/server/services/forgeAuth.js
index e9586e6f24..8d2f3385b3 100644
--- a/server/services/forgeAuth.js
+++ b/server/services/forgeAuth.js
@@ -184,6 +184,10 @@ export function resolveForgeForRepo(dir, opts = {}) {
async function resolveForgeWithPin(dir, { timeoutMs = DEFAULT_SPAWN_CLI_TIMEOUT_MS, signal, forgeAccount = null } = {}, pinState = {}) {
const explicitPin = (typeof forgeAccount === 'string' && forgeAccount.trim()) ? forgeAccount.trim() : null;
pinState.account = explicitPin || await resolveConfiguredAccount(dir);
+ pinState.resolved = true;
+ // The outer budget may expire while the registry or worktree lookup waits.
+ // It already refused the unknown pin; do not start late credential probes.
+ if (signal?.aborted) return { cli: 'gh', env: process.env, host: null, owner: null, account: null, identity: null };
return resolveForgeCredentials(dir, { timeoutMs, signal, pinned: pinState.account }).catch((error) => {
if (pinState.account) throw error;
return { cli: 'gh', env: process.env, host: null, owner: null, account: null, identity: null };
@@ -266,13 +270,14 @@ export async function resolveForgeTokenEnv(dir, { timeoutMs = 10000, forgeAccoun
// gh subprocess keeps its own timeout as a second bound for direct callers.
let timer;
const controller = new AbortController();
- const pinState = {};
+ const pinState = { resolved: false, account: null };
const resolved = await Promise.race([
resolveForgeWithPin(dir, { timeoutMs, signal: controller.signal, forgeAccount }, pinState),
new Promise((resolve, reject) => {
timer = setTimeout(() => {
controller.abort();
- if (pinState.account === null) return resolve(null);
+ // Unknown is not unpinned: a late registry read may reveal a pin.
+ if (pinState.resolved && !pinState.account) return resolve(null);
reject(new ServerError('Pinned GitHub account resolution timed out. Retry after checking gh auth status.', {
status: 503, code: 'FORGE_AUTH_TIMEOUT',
}));
diff --git a/server/services/forgeAuth.test.js b/server/services/forgeAuth.test.js
index c5694de00a..daf5da7c5a 100644
--- a/server/services/forgeAuth.test.js
+++ b/server/services/forgeAuth.test.js
@@ -400,3 +400,16 @@ it('keeps unpinned transient credential failures on ambient auth', async () => {
expect(options.env).toBe(process.env);
expect(options.customEnv).toBeNull();
});
+
+it('refuses an unresolved pin lookup and never starts late probes after its budget expires', async () => {
+ vi.useFakeTimers();
+ let finishRegistryRead;
+ listForgePinnedApps.mockImplementation(() => new Promise((resolve) => { finishRegistryRead = resolve; }));
+ const pending = resolveForgeTokenEnv('/example/repo', { timeoutMs: 10 });
+ const refused = expect(pending).rejects.toMatchObject({ code: 'FORGE_AUTH_TIMEOUT' });
+ await vi.advanceTimersByTimeAsync(10);
+ await refused;
+ finishRegistryRead([]);
+ await vi.advanceTimersByTimeAsync(0);
+ expect(spawn).not.toHaveBeenCalled();
+});
diff --git a/server/services/forgeScopeRefresh.test.js b/server/services/forgeScopeRefresh.test.js
index e27f6e6061..832862ebbe 100644
--- a/server/services/forgeScopeRefresh.test.js
+++ b/server/services/forgeScopeRefresh.test.js
@@ -44,6 +44,7 @@ beforeEach(() => {
});
afterEach(() => {
+ vi.unstubAllEnvs();
vi.useRealTimers();
});
@@ -166,7 +167,6 @@ describe('startForgeScopeRefresh', () => {
expect.any(Number), expect.objectContaining({ env: expect.not.objectContaining({ GH_ENTERPRISE_TOKEN: 'ambient-token' }) }),
);
await settle(jobId);
- vi.unstubAllEnvs();
});
it('refuses when the active account cannot be verified and releases the host reservation', async () => {