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

address review (agy): gate the provider bench on provenance alone

[._.]/ Adam Eivyd8c2f40b485b
diff --git a/server/services/agentFinalization.js b/server/services/agentFinalization.js
index c1a803b08a..188429b6d3 100644
--- a/server/services/agentFinalization.js
+++ b/server/services/agentFinalization.js
@@ -628,10 +628,15 @@ export async function finalizeAgent({
// promptRunner) picks the window and declines to bench request-specific
// failures; the cooldown then routes the retry to a fallback
// (agentProviderResolution.js) and auto-expires without anyone intervening.
- const isProviderFault = errorAnalysis.origin === 'provider'
- || errorAnalysis.category === 'usage-limit'
- || errorAnalysis.category === 'rate-limit';
- const bench = isProviderFault ? resolveProviderBench(errorAnalysis) : null;
+ // Provenance is the WHOLE gate — deliberately not `|| category === 'usage-limit'
+ // || category === 'rate-limit'`, which is what this used to key on. Those
+ // categories have loose alternatives (a bare "rate limit" / "quota exceeded" an
+ // agent's own failing test can print), so a category-only check benches a
+ // healthy provider off the agent's transcript. Genuine limits already carry
+ // `origin: 'provider'` via their `structuredMarker`, so nothing real is lost.
+ // Every finalizeAgent caller analyzes through analyzeAgentFailure or
+ // detectImmediateFallbackSignal, and both stamp an origin on every branch.
+ const bench = errorAnalysis.origin === 'provider' ? resolveProviderBench(errorAnalysis) : null;
// Lazy provider lookup — resolve the active provider only when a marker
// fires AND the caller didn't already know the id, keeping the ordinary
// failure path free of a settings-file read.
diff --git a/server/services/agentFinalization.providerBench.test.js b/server/services/agentFinalization.providerBench.test.js
index 88d630e4e7..88a235d231 100644
--- a/server/services/agentFinalization.providerBench.test.js
+++ b/server/services/agentFinalization.providerBench.test.js
@@ -125,13 +125,20 @@ describe('finalizeAgent provider sidelining', () => {
// The provenance gate (#2642): a repainted TUI transcript is a whole session
// of text the agent itself wrote, so a loose keyword match must never bench a
// healthy provider — only structured provider chrome does.
- it('does not bench an output-scan failure that merely looks provider-ish', async () => {
- await failedRun({ hasError: true, category: 'auth-error', origin: 'output-scan', message: 'unauthorized' });
- expect(markProviderUnavailableMock).not.toHaveBeenCalled();
- expect(markProviderUsageLimitMock).not.toHaveBeenCalled();
- // No marker fired, so the lazy active-provider lookup must stay unread.
- expect(getActiveProviderMock).not.toHaveBeenCalled();
- });
+ // `rate-limit` and `usage-limit` are the load-bearing cases: their patterns have
+ // loose alternatives (a bare "rate limit" / "quota exceeded" a failing test in
+ // the agent's own workspace can print), and this gate used to key on the
+ // category alone — so an agent's transcript could bench a healthy provider.
+ it.each(['auth-error', 'rate-limit', 'usage-limit'])(
+ 'does not bench an output-scan %s that merely looks provider-ish',
+ async (category) => {
+ await failedRun({ hasError: true, category, origin: 'output-scan', message: 'looks provider-ish', requiresFallback: true });
+ expect(markProviderUnavailableMock).not.toHaveBeenCalled();
+ expect(markProviderUsageLimitMock).not.toHaveBeenCalled();
+ // No marker fired, so the lazy active-provider lookup must stay unread.
+ expect(getActiveProviderMock).not.toHaveBeenCalled();
+ }
+ );
it('does not bench an ordinary agent-work failure', async () => {
await failedRun({ hasError: true, category: 'test-failure', origin: 'output-scan', message: 'suite failed' });