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(review): address round 2 Copilot feedback on API error skip logic

[._.]/ Adam Eivya28401348336
diff --git a/server/services/subAgentSpawner.js b/server/services/subAgentSpawner.js
index e797c5c32b..d29aaba157 100644
--- a/server/services/subAgentSpawner.js
+++ b/server/services/subAgentSpawner.js
@@ -986,7 +986,7 @@ async function maybeCreateInvestigationTask(agentId, task, analysis) {
return;
}
await createInvestigationTask(agentId, task, analysis).catch(err => {
- emitLog('warn', `Failed to create investigation task: ${err.message}`, { agentId });
+ emitLog('warn', `Failed to create investigation task: ${err.message}`, { agentId, taskId: task.id, category: analysis?.category });
});
}
@@ -998,7 +998,7 @@ async function maybeCreateInvestigationTask(agentId, task, analysis) {
* Returns { status, metadata } to apply to the task.
*/
async function resolveFailedTaskUpdate(task, errorAnalysis, agentId) {
- // Actionable errors get blocked immediately with investigation
+ // Actionable errors get blocked immediately (investigation task created unless API access is denied)
if (errorAnalysis?.actionable) {
emitLog('warn', `🚫 Task ${task.id} blocked: ${errorAnalysis.message} (${errorAnalysis.category})`, {
taskId: task.id, category: errorAnalysis.category
diff --git a/server/services/subAgentSpawner.test.js b/server/services/subAgentSpawner.test.js
index 863cf5b823..ecf6d9d3bc 100644
--- a/server/services/subAgentSpawner.test.js
+++ b/server/services/subAgentSpawner.test.js
@@ -477,12 +477,18 @@ describe('Spawn Arguments Building', () => {
describe('Task Failure Retry Logic', () => {
const MAX_TASK_RETRIES = 3;
+ const API_ACCESS_ERROR_CATEGORIES = new Set([
+ 'auth-error',
+ 'forbidden',
+ 'usage-limit',
+ ]);
+
/**
* Inline copy of resolveFailedTaskUpdate decision logic (sans async I/O).
* Returns { status, metadata, shouldCreateInvestigation }
*/
function resolveFailedTaskStatus(task, errorAnalysis) {
- // Actionable errors get blocked immediately
+ // Actionable errors get blocked immediately (skip investigation for API access errors)
if (errorAnalysis?.actionable) {
return {
status: 'blocked',
@@ -492,7 +498,7 @@ describe('Task Failure Retry Logic', () => {
blockedCategory: errorAnalysis.category,
blockedAt: 'test-timestamp'
},
- shouldCreateInvestigation: true
+ shouldCreateInvestigation: !API_ACCESS_ERROR_CATEGORIES.has(errorAnalysis.category)
};
}
@@ -531,15 +537,25 @@ describe('Task Failure Retry Logic', () => {
describe('Actionable errors', () => {
it('should block immediately on actionable error (first failure)', () => {
const task = { id: 'task-1', description: 'test', metadata: {} };
- const errorAnalysis = { actionable: true, category: 'auth-error', message: 'Auth failed' };
+ const errorAnalysis = { actionable: true, category: 'model-not-found', message: 'Model not found' };
const result = resolveFailedTaskStatus(task, errorAnalysis);
expect(result.status).toBe('blocked');
- expect(result.metadata.blockedCategory).toBe('auth-error');
+ expect(result.metadata.blockedCategory).toBe('model-not-found');
expect(result.shouldCreateInvestigation).toBe(true);
});
+ it('should skip investigation for API access error categories', () => {
+ const task = { id: 'task-1', description: 'test', metadata: {} };
+
+ for (const category of ['auth-error', 'forbidden', 'usage-limit']) {
+ const result = resolveFailedTaskStatus(task, { actionable: true, category, message: `${category} error` });
+ expect(result.status).toBe('blocked');
+ expect(result.shouldCreateInvestigation).toBe(false);
+ }
+ });
+
it('should block immediately regardless of failure count', () => {
const task = { id: 'task-1', description: 'test', metadata: { failureCount: 0 } };
const errorAnalysis = { actionable: true, category: 'model-not-found', message: 'Model not found' };
@@ -655,48 +671,4 @@ describe('Task Failure Retry Logic', () => {
});
});
- describe('API access error categories skip investigation', () => {
- const API_ACCESS_ERROR_CATEGORIES = new Set([
- 'auth-error',
- 'forbidden',
- 'usage-limit',
- ]);
-
- function shouldSkipInvestigation(analysis) {
- return API_ACCESS_ERROR_CATEGORIES.has(analysis?.category);
- }
-
- it('should skip investigation for auth-error category', () => {
- const analysis = { actionable: true, category: 'auth-error', message: 'Auth failed' };
- expect(shouldSkipInvestigation(analysis)).toBe(true);
- });
-
- it('should skip investigation for forbidden category', () => {
- const analysis = { actionable: true, category: 'forbidden', message: 'Forbidden' };
- expect(shouldSkipInvestigation(analysis)).toBe(true);
- });
-
- it('should skip investigation for usage-limit category', () => {
- const analysis = { actionable: true, category: 'usage-limit', message: 'Limit reached' };
- expect(shouldSkipInvestigation(analysis)).toBe(true);
- });
-
- it('should NOT skip investigation for other actionable categories', () => {
- const analysis = { actionable: true, category: 'model-not-found', message: 'Model not found' };
- expect(shouldSkipInvestigation(analysis)).toBe(false);
- });
-
- it('should NOT skip investigation for non-actionable categories', () => {
- const analysis = { actionable: false, category: 'rate-limit', message: 'Rate limited' };
- expect(shouldSkipInvestigation(analysis)).toBe(false);
- });
-
- it('should NOT skip investigation for null analysis', () => {
- expect(shouldSkipInvestigation(null)).toBe(false);
- });
-
- it('should NOT skip investigation for analysis without category', () => {
- expect(shouldSkipInvestigation({ actionable: true })).toBe(false);
- });
- });
});