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: escalate on unexpected fallback-lookup throw via finally safety-net (#2342)

Adam Eivy66e8c9692bdb
diff --git a/server/lib/promptRunner.js b/server/lib/promptRunner.js
index 2d10ea394d..fc23efab0a 100644
--- a/server/lib/promptRunner.js
+++ b/server/lib/promptRunner.js
@@ -656,9 +656,17 @@ export async function runPromptThroughProvider(args) {
fallbackProvider: fallback,
};
} finally {
- // Safety net: release any key left suppressed-but-unresolved by an
- // unexpected throw, so the in-flight set can't leak the key.
- await releaseAllUnresolved();
+ // Safety net for an UNEXPECTED throw (e.g. coalesceFallbackMarkAndPick
+ // rejecting) that bypassed the explicit give-up handlers: those handlers
+ // resolve every suppressed key, so any key still unresolved HERE means a
+ // throw cancelled the primary's backstop task with no replacement queued.
+ // Escalate one investigation task (deduped — a no-op if an explicit branch
+ // already escalated) so the unrecovered failure still surfaces, then
+ // release the keys so the in-flight set can't leak.
+ if ([...suppressed.values()].some((entry) => !entry.resolved)) {
+ await escalatePrimaryFailure();
+ await releaseAllUnresolved();
+ }
}
}
}
diff --git a/server/lib/promptRunner.test.js b/server/lib/promptRunner.test.js
index 975e2b6e56..f04d6a1f36 100644
--- a/server/lib/promptRunner.test.js
+++ b/server/lib/promptRunner.test.js
@@ -1437,6 +1437,25 @@ describe('promptRunner — Tier 1 config/env correction (issue #2342)', () => {
expect(autoFixer.noteFallbackHandled).toHaveBeenCalledWith({ provider: 'Primary API', model: 'primary-model' });
});
+ it('escalates when the fallback lookup itself throws after Tier 1 suppressed the keys', async () => {
+ // coalesceFallbackMarkAndPick throwing (e.g. getFallbackProvider blowing up)
+ // after Tier 1 cancelled the primary's backstop task would otherwise leave
+ // zero investigation tasks — the finally safety-net must escalate one.
+ const status = mockToolkitWithFallback();
+ status.getFallbackProvider.mockImplementation(() => { throw new Error('provider registry corrupt'); });
+ const primary = apiProvider({ id: 'primary-api', name: 'Primary API', defaultModel: 'primary-model', models: ['primary-model', 'good-model'] });
+
+ runner.executeApiRun.mockImplementation(async ({ onComplete }) => {
+ onComplete({ success: false, error: 'model gone', errorAnalysis: { category: ERROR_CATEGORIES.MODEL_NOT_FOUND } });
+ });
+
+ await expect(runPromptThroughProvider({ provider: primary, prompt: 'p', source: 'test' })).rejects.toThrow();
+
+ expect(autoFixer.escalateProviderFailure).toHaveBeenCalledWith(expect.objectContaining({
+ context: expect.objectContaining({ provider: 'Primary API', model: 'primary-model' }),
+ }));
+ });
+
it('does NOT engage Tier 1 for a category-less failure even when the provider lists alternatives', async () => {
// Regression: a failure with no errorAnalysis has category === undefined,
// which must NOT match the model-not-found guard (the `undefined ===