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]): cover both classifier vocabularies and fix error-share denominator (codex review)

[._.]/ Adam Eivy0f15fce23a7d
diff --git a/server/services/taskLearning/metrics.js b/server/services/taskLearning/metrics.js
index 4f09546dc2..14a48c59d8 100644
--- a/server/services/taskLearning/metrics.js
+++ b/server/services/taskLearning/metrics.js
@@ -46,13 +46,24 @@ const MAX_SIGNATURE_SAMPLES = 10;
// feed `errorPatterns` / `failureSignatures` — prompt recommendations and
// diagnostics appropriately consume those.
//
-// Deliberately EXCLUDES `timeout` and `unknown`: both can be genuine task/model
-// signal (a task too big for its tier times out; an uncategorized failure may be
-// anything). 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.
+// 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',
@@ -61,8 +72,14 @@ export const ENVIRONMENTAL_ERROR_CATEGORIES = new Set([
'forbidden',
'billing-error',
'connection',
+ 'network-error',
+ 'server-error',
+ 'claude-error',
'startup-failure',
- 'model-not-available'
+ 'spawn-error',
+ 'model-not-available',
+ 'model-not-found',
+ 'model-not-supported'
]);
/**
diff --git a/server/services/taskLearning/metrics.test.js b/server/services/taskLearning/metrics.test.js
index 3d683381b1..a738077465 100644
--- a/server/services/taskLearning/metrics.test.js
+++ b/server/services/taskLearning/metrics.test.js
@@ -400,25 +400,35 @@ describe('getWindowedStats (issue #2460)', () => {
});
describe('ENVIRONMENTAL_ERROR_CATEGORIES (issue #2618)', () => {
- it('contains exactly the environmental/infrastructure categories', () => {
+ it('contains exactly the environmental/infrastructure categories from both classifier vocabularies', () => {
expect([...ENVIRONMENTAL_ERROR_CATEGORIES].sort()).toEqual([
'auth',
'auth-error',
'billing-error',
+ 'claude-error',
'connection',
'forbidden',
'model-not-available',
+ 'model-not-found',
+ 'model-not-supported',
+ 'network-error',
'rate-limit',
+ 'server-error',
+ 'spawn-error',
'startup-failure',
'usage-limit'
]);
});
it('deliberately excludes categories that can be genuine task/model signal', () => {
- // timeout: a task too big for its tier legitimately times out; unknown: could
- // be anything — excluding them from learning would blind routing to real signal.
+ // 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.
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('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 534df4e1e6..dfcf497659 100644
--- a/server/services/taskLearning/promptRecommendations.js
+++ b/server/services/taskLearning/promptRecommendations.js
@@ -40,7 +40,14 @@ export async function getPromptImprovementRecommendations(taskType) {
return recommendations;
}
- // Analyze error patterns specific to this task type
+ // 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);
const taskErrors = [];
for (const [category, pattern] of Object.entries(data.errorPatterns)) {
const taskTypeCount = pattern.taskTypes[taskType] || 0;
@@ -48,7 +55,7 @@ export async function getPromptImprovementRecommendations(taskType) {
taskErrors.push({
category,
count: taskTypeCount,
- percentage: Math.round((taskTypeCount / metrics.failed) * 100)
+ percentage: Math.round((taskTypeCount / totalTypeErrors) * 100)
});
}
}