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

Stop toasting API refusals made by agents in every open tab

Claude0e778838fd6b
diff --git a/server/services/socket.js b/server/services/socket.js
index a7fe7ed751..83e4170ebf 100644
--- a/server/services/socket.js
+++ b/server/services/socket.js
@@ -579,6 +579,8 @@ function setupCosEventForwarding() {
}
}
+const isClientRefusal = (error) => error.status >= 400 && error.status < 500 && error.severity !== 'critical';
+
// Set up error event forwarding
function setupErrorEventForwarding() {
// Forward error events to error subscribers. Use `safeContext` (second arg
@@ -587,6 +589,10 @@ function setupErrorEventForwarding() {
// directly (bypassing `emitErrorEvent`), `safeContext` is undefined; in that
// case sanitize the raw context defensively rather than passing it through.
errorEvents.on('error', (error, safeContext) => {
+ // A 4xx refusal is answered to its own caller: the browser's request()
+ // already toasts its failures, and most refusals come from agents and
+ // scripts calling the API, which would otherwise red-toast every open tab.
+ if (isClientRefusal(error)) return;
const context = safeContext !== undefined
? safeContext
: sanitizeContext(error.context);
diff --git a/server/services/socket.test.js b/server/services/socket.test.js
index f9981a9ee9..f7411aed45 100644
--- a/server/services/socket.test.js
+++ b/server/services/socket.test.js
@@ -16,7 +16,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
// Preserve installed once-only listeners across Vitest's per-test mock-call
// clearing, just as the process-wide event buses retain their subscriptions.
-const queueListeners = vi.hoisted(() => ({ cos: [], review: [], brain: [], twin: [] }));
+const queueListeners = vi.hoisted(() => ({ cos: [], review: [], brain: [], twin: [], errors: [] }));
/**
* Tests for socket.js initSocket behavior.
@@ -36,7 +36,7 @@ vi.mock('./apps.js', () => ({ appsEvents: { on: vi.fn() }, getAppById: vi.fn(),
vi.mock('./appProcessStatus.js', () => ({ resolvePm2HomeForProcess: vi.fn() }));
// logAction appends to the real history file — mock it or this suite writes to data/.
vi.mock('./history.js', () => ({ logAction: vi.fn(async () => {}) }));
-vi.mock('../lib/errorHandler.js', () => ({ errorEvents: { on: vi.fn() } }));
+vi.mock('../lib/errorHandler.js', () => ({ errorEvents: { on: vi.fn((...args) => queueListeners.errors.push(args)) } }));
vi.mock('./autoFixer.js', () => ({ handleErrorRecovery: vi.fn() }));
vi.mock('./pm2Standardizer.js', () => ({ analyzeApp: vi.fn(), createGitBackup: vi.fn(), applyStandardization: vi.fn(), runStandardizeFlow: vi.fn(), standardizeRefusalFor: vi.fn(() => null) }));
vi.mock('./notifications.js', () => ({ notificationEvents: { on: vi.fn() }, getNotifications: vi.fn(async () => []) }));
@@ -823,6 +823,23 @@ describe('socket.js — initSocket', () => {
expect(socket.emitted.some(([ev]) => ev === 'errors:subscribed')).toBe(true);
});
+ it('notifies error subscribers of server faults but not of 4xx refusals answered to their caller', () => {
+ const socket = makeSocket('err-notify');
+ createdSockets.push(socket);
+ io.connect(socket);
+ socket.handlers['errors:subscribe']();
+ const [, onError] = queueListeners.errors.find(([event]) => event === 'error');
+ const notified = () => socket.emitted.filter(([ev]) => ev === 'error:notified').map(([, payload]) => payload.code);
+
+ onError({ status: 409, code: 'CHECKOUT_REVIEW_REFUSED', message: 'Checkout review refused' }, {});
+ onError({ status: 400, code: 'VALIDATION_ERROR', message: 'Validation failed' }, {});
+ onError({ status: 404, code: 'NOT_FOUND', message: 'App not found', severity: 'critical' }, {});
+ onError({ status: 500, code: 'INTERNAL_ERROR', message: 'timeout exceeded when trying to connect' }, {});
+ onError({ code: 'AI_PROVIDER_EXECUTION_FAILED', message: 'Provider failed' }, {});
+
+ expect(notified()).toEqual(['NOT_FOUND', 'INTERNAL_ERROR', 'AI_PROVIDER_EXECUTION_FAILED']);
+ });
+
// ===========================================================================
// agents + instances namespaces
// ===========================================================================