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([issue-2618]): keep environmental signatures out of tier avoidance, narrow mixed-provenance categories, count uncategorized failures in error shares (codex round 2)

[._.]/ Adam Eivy9b85864176c3
diff --git a/server/services/taskLearning/metrics.js b/server/services/taskLearning/metrics.js
index a06e8b2de7..817c04c7e5 100644
--- a/server/services/taskLearning/metrics.js
+++ b/server/services/taskLearning/metrics.js
@@ -24,7 +24,8 @@ import {
appendRecentOutcome,
computeWindowedStats,
DEFAULT_WINDOW_MAX_COUNT,
- DEFAULT_WINDOW_MAX_AGE_MS
+ DEFAULT_WINDOW_MAX_AGE_MS,
+ ENVIRONMENTAL_ERROR_CATEGORIES
} from './store.js';
import { deriveFailureSignalAvoidance, isNonRoutableLearnedTier } from './routing.js';
import { recordCorrelationSample } from './correlationQuality.js';
@@ -34,53 +35,11 @@ import { recordCorrelationSample } from './correlationQuality.js';
// trends (provider/model/tier correlation) without a full agent-archive scan.
const MAX_SIGNATURE_SAMPLES = 10;
-// Environmental/infrastructure error categories (issue #2618): failures that say
-// nothing about the task or the model — a provider outage, an exhausted quota, a
-// revoked key, a dead network, an agent that never started. These are EXCLUDED
-// from the success-rate aggregates (`byTaskType` / `byModelTier` /
-// `routingAccuracy` / `totals` / the `recentOutcomes` windowed ring / the
-// correlation window) so an hour of provider 529s can't crater a task type's
-// rate, steer routing off a healthy tier, or trip the <30% skip gate. They are
-// instead counted in `data.environmentalFailures[category]` (count +
-// lastOccurred + affected task types) so the events stay visible, and they STILL
-// feed `errorPatterns` / `failureSignatures` — prompt recommendations and
-// diagnostics appropriately consume those.
-//
-// Covers BOTH classifier vocabularies that can stamp `errorAnalysis.category`:
-// agentErrorAnalysis's ERROR_PATTERNS (`rate-limit`, `usage-limit`, `auth-error`,
-// `forbidden`, `billing-error`, `server-error` — where a provider 529 lands,
-// `network-error`, `claude-error` — `overloaded_error`, `spawn-error`,
-// `startup-failure`, `model-not-found`, `model-not-supported`) and
-// agentRunTracking's extractErrorFromOutput (`auth`, `connection`, `rate-limit`).
-// `model-not-available` is the legacy naming for the model-unavailability class
-// (still present in stored learning data / prompt insights).
-//
-// Deliberately EXCLUDES `timeout`, `unknown`, `process-killed`, and the generic
-// `api-error`: each can be genuine task/model signal (a task too big for its
-// tier times out or blows resource limits; an uncategorized or generic API
-// failure may be anything, including a task-induced bad request). Superset of
-// agentErrorAnalysis's `API_ACCESS_ERROR_CATEGORIES` (auth-error / forbidden /
-// usage-limit — asserted by a cross-check test in agentErrorAnalysis.test.js)
-// but defined here as its own leaf constant: importing agentErrorAnalysis.js
-// would drag the cos.js task-store graph into every taskLearning consumer and
-// suite.
-export const ENVIRONMENTAL_ERROR_CATEGORIES = new Set([
- 'rate-limit',
- 'usage-limit',
- 'auth-error',
- 'auth',
- 'forbidden',
- 'billing-error',
- 'connection',
- 'network-error',
- 'server-error',
- 'claude-error',
- 'startup-failure',
- 'spawn-error',
- 'model-not-available',
- 'model-not-found',
- 'model-not-supported'
-]);
+// ENVIRONMENTAL_ERROR_CATEGORIES lives in store.js (the leaf module) so both
+// this recorder and routing.js can consume it without deepening the existing
+// metrics⇄routing import cycle; re-exported here for back-compat.
+export { ENVIRONMENTAL_ERROR_CATEGORIES };
+
/**
* Record an environmental failure into `data.environmentalFailures` (issue
diff --git a/server/services/taskLearning/metrics.test.js b/server/services/taskLearning/metrics.test.js
index a738077465..4f271f07d1 100644
--- a/server/services/taskLearning/metrics.test.js
+++ b/server/services/taskLearning/metrics.test.js
@@ -413,8 +413,6 @@ describe('ENVIRONMENTAL_ERROR_CATEGORIES (issue #2618)', () => {
'model-not-supported',
'network-error',
'rate-limit',
- 'server-error',
- 'spawn-error',
'startup-failure',
'usage-limit'
]);
@@ -424,11 +422,16 @@ describe('ENVIRONMENTAL_ERROR_CATEGORIES (issue #2618)', () => {
// timeout / process-killed: a task too big for its tier legitimately times
// out or blows resource limits; unknown / api-error: could be anything,
// including a task-induced bad request — excluding them from learning would
- // blind routing to real signal.
+ // blind routing to real signal. server-error / spawn-error: their classifier
+ // regexes match ordinary task output ("Internal Server Error" from a failing
+ // app test, "command not found" from a broken build), so treating them as
+ // environmental would hide genuine failures from the rate.
expect(ENVIRONMENTAL_ERROR_CATEGORIES.has('timeout')).toBe(false);
expect(ENVIRONMENTAL_ERROR_CATEGORIES.has('unknown')).toBe(false);
expect(ENVIRONMENTAL_ERROR_CATEGORIES.has('process-killed')).toBe(false);
expect(ENVIRONMENTAL_ERROR_CATEGORIES.has('api-error')).toBe(false);
+ expect(ENVIRONMENTAL_ERROR_CATEGORIES.has('server-error')).toBe(false);
+ expect(ENVIRONMENTAL_ERROR_CATEGORIES.has('spawn-error')).toBe(false);
expect(ENVIRONMENTAL_ERROR_CATEGORIES.has('test-failure')).toBe(false);
expect(ENVIRONMENTAL_ERROR_CATEGORIES.has(null)).toBe(false);
});
diff --git a/server/services/taskLearning/promptRecommendations.js b/server/services/taskLearning/promptRecommendations.js
index dfcf497659..5e7387b254 100644
--- a/server/services/taskLearning/promptRecommendations.js
+++ b/server/services/taskLearning/promptRecommendations.js
@@ -41,13 +41,15 @@ export async function getPromptImprovementRecommendations(taskType) {
}
// Analyze error patterns specific to this task type. The percentage is each
- // category's share of ALL categorized error events recorded for this type —
- // NOT of `metrics.failed`: environmental failures (issue #2618) still record
- // into errorPatterns (they feed these insights) but no longer count into the
- // aggregate `failed`, so dividing by it could yield Infinity (only-environmental
- // history) or >100% shares.
- const totalTypeErrors = Object.values(data.errorPatterns)
- .reduce((sum, pattern) => sum + (pattern.taskTypes[taskType] || 0), 0);
+ // category's share of ALL failures recorded for this type: `metrics.failed`
+ // (every non-environmental failure, categorized or not — a validation miss
+ // has no errorPatterns entry but is still a failure) plus this type's
+ // environmental count (issue #2618: those still record into errorPatterns but
+ // no longer count into `failed`, so dividing by `failed` alone could yield
+ // Infinity or >100% shares).
+ const environmentalTypeErrors = Object.values(data.environmentalFailures || {})
+ .reduce((sum, bucket) => sum + (bucket.taskTypes?.[taskType] || 0), 0);
+ const totalTypeErrors = (metrics.failed || 0) + environmentalTypeErrors;
const taskErrors = [];
for (const [category, pattern] of Object.entries(data.errorPatterns)) {
const taskTypeCount = pattern.taskTypes[taskType] || 0;
@@ -55,7 +57,7 @@ export async function getPromptImprovementRecommendations(taskType) {
taskErrors.push({
category,
count: taskTypeCount,
- percentage: Math.round((taskTypeCount / totalTypeErrors) * 100)
+ percentage: totalTypeErrors > 0 ? Math.round((taskTypeCount / totalTypeErrors) * 100) : 0
});
}
}
diff --git a/server/services/taskLearning/routing.js b/server/services/taskLearning/routing.js
index c1bf41a38e..703bf58b19 100644
--- a/server/services/taskLearning/routing.js
+++ b/server/services/taskLearning/routing.js
@@ -9,7 +9,7 @@
* module.
*/
-import { loadLearningData, emitLog, isSandboxedTaskType, computeEffectiveSuccessRate, computeWindowedStats, isSkipCandidate, DEFAULT_WINDOW_MAX_AGE_MS } from './store.js';
+import { loadLearningData, emitLog, isSandboxedTaskType, computeEffectiveSuccessRate, computeWindowedStats, isSkipCandidate, DEFAULT_WINDOW_MAX_AGE_MS, ENVIRONMENTAL_ERROR_CATEGORIES } from './store.js';
import { resetTaskTypeLearning } from './metrics.js';
import { computeCorrelationQuality, isCorrelationProven } from './correlationQuality.js';
@@ -139,10 +139,15 @@ export function deriveFailureSignalAvoidance(data, taskType, {
const routing = data?.routingAccuracy?.[taskType] || {};
const ageCutoff = Number.isFinite(maxAgeMs) && maxAgeMs > 0 ? now - maxAgeMs : null;
- // Gather recent failure samples scoped to this task type across all categories.
+ // Gather recent failure samples scoped to this task type across all
+ // categories — except environmental ones (issue #2618): failureSignatures
+ // deliberately still records outage-class samples for diagnostics, but a
+ // burst of rate-limit failures says nothing about the tier, so it must not
+ // reach avoidTiers through this secondary signal either.
const byTier = {};
let sampleCount = 0;
- for (const bucket of Object.values(signatures)) {
+ for (const [category, bucket] of Object.entries(signatures)) {
+ if (ENVIRONMENTAL_ERROR_CATEGORIES.has(category)) continue;
for (const sample of bucket?.recent || []) {
if (sample?.taskType !== taskType || !sample.modelTier) continue;
if (NON_ROUTABLE_LEARNED_TIERS.has(sample.modelTier)) continue;
@@ -204,7 +209,9 @@ function mergeAvoidTiers(...lists) {
*/
function tiersWithRecentFailures(data, taskType, { now = Date.now(), maxAgeMs = DEFAULT_WINDOW_MAX_AGE_MS } = {}) {
const tiers = new Set();
- for (const bucket of Object.values(data?.failureSignatures || {})) {
+ for (const [category, bucket] of Object.entries(data?.failureSignatures || {})) {
+ // Environmental categories can't mark a tier as recently-failing (#2618).
+ if (ENVIRONMENTAL_ERROR_CATEGORIES.has(category)) continue;
for (const sample of bucket?.recent || []) {
if (sample?.taskType !== taskType || !sample.modelTier) continue;
const t = Date.parse(sample.recordedAt);
diff --git a/server/services/taskLearning/routing.test.js b/server/services/taskLearning/routing.test.js
index 1371f663b2..21ab087705 100644
--- a/server/services/taskLearning/routing.test.js
+++ b/server/services/taskLearning/routing.test.js
@@ -46,6 +46,32 @@ describe('deriveFailureSignalAvoidance (#2329)', () => {
expect(out.sampleCount).toBe(2);
});
+ it('ignores environmental-category signatures entirely (issue #2618)', () => {
+ // An hour of provider rate-limiting piles samples into the 'rate-limit'
+ // bucket; those must not reach avoidTiers through the signature signal.
+ const data = {
+ failureSignatures: {
+ 'rate-limit': { count: 5, recent: [sample(), sample(), sample(), sample(), sample()] }
+ },
+ routingAccuracy: {}
+ };
+ const out = deriveFailureSignalAvoidance(data, 'user-task');
+ expect(out.avoidTiers).toEqual([]);
+ expect(out.sampleCount).toBe(0);
+
+ // Mixed buckets: only the non-environmental samples count.
+ const mixed = {
+ failureSignatures: {
+ 'rate-limit': { count: 3, recent: [sample(), sample(), sample()] },
+ 'test-failure': { count: 2, recent: [sample(), sample()] }
+ },
+ routingAccuracy: {}
+ };
+ const outMixed = deriveFailureSignalAvoidance(mixed, 'user-task');
+ expect(outMixed.sampleCount).toBe(2); // below MIN_FAILURE_SAMPLES(3)
+ expect(outMixed.avoidTiers).toEqual([]);
+ });
+
it('flags an unproven tier with enough recent failures and attributes provider/model', () => {
const data = dataWith([
sample({ modelTier: 'heavy', provider: 'claude', model: 'opus' }),
diff --git a/server/services/taskLearning/store.js b/server/services/taskLearning/store.js
index 9e4501f4ab..d7532cedee 100644
--- a/server/services/taskLearning/store.js
+++ b/server/services/taskLearning/store.js
@@ -183,6 +183,56 @@ export function isSkipCandidate(metrics) {
/**
* Default learning data structure
*/
+// Environmental/infrastructure error categories (issue #2618): failures that say
+// nothing about the task or the model — a provider outage, an exhausted quota, a
+// revoked key, a dead network, an agent that never started. These are EXCLUDED
+// from the success-rate aggregates (`byTaskType` / `byModelTier` /
+// `routingAccuracy` / `totals` / the `recentOutcomes` windowed ring / the
+// correlation window) so an hour of provider 529s can't crater a task type's
+// rate, steer routing off a healthy tier, or trip the <30% skip gate. They are
+// instead counted in `data.environmentalFailures[category]` (count +
+// lastOccurred + affected task types) so the events stay visible, and they STILL
+// feed `errorPatterns` / `failureSignatures` — prompt recommendations and
+// diagnostics appropriately consume those.
+//
+// Covers BOTH classifier vocabularies that can stamp `errorAnalysis.category`:
+// agentErrorAnalysis's ERROR_PATTERNS (`rate-limit`, `usage-limit`, `auth-error`,
+// `forbidden`, `billing-error`, `network-error`, `claude-error` —
+// `overloaded_error`, `startup-failure`, `model-not-found`,
+// `model-not-supported`) and agentRunTracking's extractErrorFromOutput (`auth`,
+// `connection`, `rate-limit`). `model-not-available` is the legacy naming for
+// the model-unavailability class (still present in stored learning data /
+// prompt insights).
+//
+// Deliberately EXCLUDES `timeout`, `unknown`, `process-killed`, and the generic
+// `api-error`: each can be genuine task/model signal (a task too big for its
+// tier times out or blows resource limits; an uncategorized or generic API
+// failure may be anything, including a task-induced bad request). Also EXCLUDES
+// the mixed-provenance categories `server-error` and `spawn-error`: their
+// classifier regexes (`/server error|internal error/`, `command not found`)
+// match ordinary task output too — a genuinely failing app test printing
+// "Internal Server Error" must keep denting the rate, not vanish as an
+// "outage". Superset of agentErrorAnalysis's `API_ACCESS_ERROR_CATEGORIES`
+// (auth-error / forbidden / usage-limit — asserted by a cross-check test in
+// agentErrorAnalysis.test.js) but defined here as its own leaf constant:
+// importing agentErrorAnalysis.js would drag the cos.js task-store graph into
+// every taskLearning consumer and suite.
+export const ENVIRONMENTAL_ERROR_CATEGORIES = new Set([
+ 'rate-limit',
+ 'usage-limit',
+ 'auth-error',
+ 'auth',
+ 'forbidden',
+ 'billing-error',
+ 'connection',
+ 'network-error',
+ 'claude-error',
+ 'startup-failure',
+ 'model-not-available',
+ 'model-not-found',
+ 'model-not-supported'
+]);
+
const DEFAULT_LEARNING_DATA = {
// v2 (issue #2460): each byTaskType bucket carries a bounded `recentOutcomes`
// ring so the signal LI reads can be recency-windowed (see appendRecentOutcome