Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(channel-reader): render tool failures in plain language instead of raw error envelopes

Jose Ramirezd3d0f1f6161f
diff --git a/channel-reader/package-lock.json b/channel-reader/package-lock.json
index 0602cd6a9..c574d5571 100644
--- a/channel-reader/package-lock.json
+++ b/channel-reader/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-channel-reader",
- "version": "0.1.96",
+ "version": "0.1.97",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-channel-reader",
- "version": "0.1.96",
+ "version": "0.1.97",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@kubernetes/client-node": "^1.0.0",
diff --git a/channel-reader/package.json b/channel-reader/package.json
index 6a3698267..1f07627a3 100644
--- a/channel-reader/package.json
+++ b/channel-reader/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-channel-reader",
- "version": "0.1.96",
+ "version": "0.1.97",
"description": "Watches CommunicationChannel CRDs and fetches messages from Telegram, Email, and Slack",
"main": "dist/main.js",
"engines": {
diff --git a/channel-reader/src/__tests__/progressFormatter.test.ts b/channel-reader/src/__tests__/progressFormatter.test.ts
index d8cdf91ed..b79e35e6b 100644
--- a/channel-reader/src/__tests__/progressFormatter.test.ts
+++ b/channel-reader/src/__tests__/progressFormatter.test.ts
@@ -1,83 +1,89 @@
-import { describe, it, expect } from "vitest";
-import { formatProgressUpdate, formatFinalMessage } from "../progressFormatter";
-import type { ProgressStep } from "../types";
+import { describe, expect, it } from 'vitest'
+import { formatFinalMessage, formatProgressUpdate } from '../progressFormatter'
+import type { ProgressStep } from '../types'
const step = (overrides: Partial<ProgressStep> = {}): ProgressStep => ({
- toolCallId: "c1",
- toolName: "mongodb-server__find",
- displayName: "Mongodb-server",
- intentSummary: "Using Mongodb-server...",
+ toolCallId: 'c1',
+ toolName: 'mongodb-server__find',
+ displayName: 'Mongodb-server',
+ intentSummary: 'Using Mongodb-server...',
iteration: 0,
stepIndex: 0,
totalSteps: 1,
- state: "completed",
+ state: 'completed',
durationMs: 340,
...overrides,
-});
+})
-describe("formatProgressUpdate", () => {
- it("shows running step with spinner", () => {
- const result = formatProgressUpdate([step({ state: "running", durationMs: undefined })]);
- expect(result).toContain("Processing");
- expect(result).toContain("●");
- expect(result).toContain("running...");
- });
+describe('formatProgressUpdate', () => {
+ it('shows running step with spinner', () => {
+ const result = formatProgressUpdate([step({ state: 'running', durationMs: undefined })])
+ expect(result).toContain('Processing')
+ expect(result).toContain('●')
+ expect(result).toContain('running...')
+ })
- it("shows completed step with checkmark and duration", () => {
- const result = formatProgressUpdate([step()]);
- expect(result).toContain("✓");
- expect(result).toContain("Mongodb-server");
- expect(result).toContain("find");
- expect(result).toContain("340ms");
- });
+ it('shows completed step with checkmark and duration', () => {
+ const result = formatProgressUpdate([step()])
+ expect(result).toContain('✓')
+ expect(result).toContain('Mongodb-server')
+ expect(result).toContain('find')
+ expect(result).toContain('340ms')
+ })
- it("shows error step with cross", () => {
- const result = formatProgressUpdate([step({ state: "error", errorSummary: "HTTP 404" })]);
- expect(result).toContain("✗");
- expect(result).toContain("HTTP 404");
- });
+ it('shows error step with cross', () => {
+ const result = formatProgressUpdate([step({ state: 'error', errorSummary: 'HTTP 404' })])
+ expect(result).toContain('✗')
+ expect(result).toContain('unavailable (not found).')
+ expect(result).not.toContain('HTTP 404')
+ })
- it("shows iteration divider when iteration changes", () => {
- const steps = [
- step({ iteration: 0 }),
- step({ toolCallId: "c2", iteration: 1, stepIndex: 0 }),
- ];
- const result = formatProgressUpdate(steps);
- expect(result).toContain("Thinking further");
- });
+ it('shows iteration divider when iteration changes', () => {
+ const steps = [step({ iteration: 0 }), step({ toolCallId: 'c2', iteration: 1, stepIndex: 0 })]
+ const result = formatProgressUpdate(steps)
+ expect(result).toContain('Thinking further')
+ })
- it("shows tool function name for MCP tools", () => {
- const result = formatProgressUpdate([step()]);
- expect(result).toContain("find");
- });
+ it('shows tool function name for MCP tools', () => {
+ const result = formatProgressUpdate([step()])
+ expect(result).toContain('find')
+ })
- it("shows tool name for native tools with shared display name", () => {
- const result = formatProgressUpdate([step({ toolName: "memory_read", displayName: "Memory" })]);
- expect(result).toContain("memory_read");
- });
-});
+ it('shows tool name for native tools with shared display name', () => {
+ const result = formatProgressUpdate([step({ toolName: 'memory_read', displayName: 'Memory' })])
+ expect(result).toContain('memory_read')
+ })
+})
-describe("formatFinalMessage", () => {
- it("prefixes response with compact summary", () => {
- const steps = [step(), step({ toolCallId: "c2", toolName: "mongodb-server__aggregate", stepIndex: 1, totalSteps: 2 })];
- const result = formatFinalMessage(steps, "Here is your data.");
- expect(result).toContain("✓ 2 tools used");
- expect(result).toContain("Here is your data.");
- });
+describe('formatFinalMessage', () => {
+ it('prefixes response with compact summary', () => {
+ const steps = [
+ step(),
+ step({
+ toolCallId: 'c2',
+ toolName: 'mongodb-server__aggregate',
+ stepIndex: 1,
+ totalSteps: 2,
+ }),
+ ]
+ const result = formatFinalMessage(steps, 'Here is your data.')
+ expect(result).toContain('✓ 2 tools used')
+ expect(result).toContain('Here is your data.')
+ })
- it("returns just the response for zero-tool tasks", () => {
- const result = formatFinalMessage([], "Just a text response.");
- expect(result).toBe("Just a text response.");
- });
+ it('returns just the response for zero-tool tasks', () => {
+ const result = formatFinalMessage([], 'Just a text response.')
+ expect(result).toBe('Just a text response.')
+ })
- it("shows warning icon when errors occurred", () => {
- const result = formatFinalMessage([step({ state: "error" })], "Partial response.");
- expect(result).toContain("⚠");
- });
+ it('shows warning icon when errors occurred', () => {
+ const result = formatFinalMessage([step({ state: 'error' })], 'Partial response.')
+ expect(result).toContain('⚠')
+ })
- it("truncates summary if total exceeds 4096 chars", () => {
- const longResponse = "A".repeat(4090);
- const result = formatFinalMessage([step()], longResponse);
- expect(result.length).toBeLessThanOrEqual(4096);
- });
-});
+ it('truncates summary if total exceeds 4096 chars', () => {
+ const longResponse = 'A'.repeat(4090)
+ const result = formatFinalMessage([step()], longResponse)
+ expect(result.length).toBeLessThanOrEqual(4096)
+ })
+})
diff --git a/channel-reader/src/progressFormatter.ts b/channel-reader/src/progressFormatter.ts
index 83b3236a2..0204d6407 100644
--- a/channel-reader/src/progressFormatter.ts
+++ b/channel-reader/src/progressFormatter.ts
@@ -1,64 +1,83 @@
-import type { ProgressStep } from "./types";
+import type { ProgressStep } from './types'
-const MAX_MESSAGE_LENGTH = 4096;
+const MAX_MESSAGE_LENGTH = 4096
function toolFn(step: ProgressStep): string {
- const sep = step.toolName.indexOf("__");
- if (sep > 0) return step.toolName.substring(sep + 2);
- if (step.displayName !== step.toolName) return step.toolName;
- return "";
+ const sep = step.toolName.indexOf('__')
+ if (sep > 0) return step.toolName.substring(sep + 2)
+ if (step.displayName !== step.toolName) return step.toolName
+ return ''
}
function formatDuration(ms: number): string {
- if (ms < 1000) return `${ms}ms`;
- return `${(ms / 1000).toFixed(1)}s`;
+ if (ms < 1000) return `${ms}ms`
+ return `${(ms / 1000).toFixed(1)}s`
+}
+
+/**
+ * Render a tool failure in our own words. The raw summary can contain a
+ * JSON-RPC envelope, an internal error code, or arbitrary provider text, none
+ * of which belongs in a chat client. Classify into a closed vocabulary and
+ * render our sentence; anything unrecognised degrades to generic. The full
+ * text stays in logs and traces.
+ */
+export function describeToolError(errorSummary: string | undefined): string {
+ const raw = (errorSummary ?? '').toLowerCase()
+ if (!raw) return 'unavailable.'
+ if (/auth|credential|unauthorized|forbidden|401|403/.test(raw)) {
+ return 'unavailable (authentication problem). Ask your administrator.'
+ }
+ if (/timed out|timeout|etimedout|deadline/.test(raw)) return 'unavailable (timed out).'
+ if (/rate limit|429|too many requests/.test(raw)) return 'unavailable (rate limited).'
+ if (/not found|404|no such/.test(raw)) return 'unavailable (not found).'
+ return 'unavailable.'
}
function formatStepLine(step: ProgressStep): string {
- const icon = step.state === "completed" ? "✓" : step.state === "running" ? "●" : "✗";
- const name = step.displayName;
- const fn = toolFn(step);
- const label = fn ? `${name} · ${fn}` : name;
+ const icon = step.state === 'completed' ? '✓' : step.state === 'running' ? '●' : '✗'
+ const name = step.displayName
+ const fn = toolFn(step)
+ const label = fn ? `${name} · ${fn}` : name
- if (step.state === "completed" && step.durationMs != null) {
- return `${icon} ${label} ${formatDuration(step.durationMs)}`;
+ if (step.state === 'completed' && step.durationMs != null) {
+ return `${icon} ${label} ${formatDuration(step.durationMs)}`
}
- if (step.state === "running") {
- return `${icon} ${label} running...`;
+ if (step.state === 'running') {
+ return `${icon} ${label} running...`
}
- return `${icon} ${label} ${step.errorSummary || "error"}`;
+ return `${icon} ${label} ${describeToolError(step.errorSummary)}`
}
export function formatProgressUpdate(steps: ProgressStep[]): string {
- const lines: string[] = ["⏳ Processing your request...", ""];
- let prevIteration: number | undefined;
+ const lines: string[] = ['⏳ Processing your request...', '']
+ let prevIteration: number | undefined
for (const step of steps) {
if (prevIteration !== undefined && step.iteration !== prevIteration) {
- lines.push("── Thinking further... ──");
+ lines.push('── Thinking further... ──')
}
- prevIteration = step.iteration;
- lines.push(formatStepLine(step));
+ prevIteration = step.iteration
+ lines.push(formatStepLine(step))
}
- return lines.join("\n");
+ return lines.join('\n')
}
export function formatFinalMessage(steps: ProgressStep[], response: string): string {
- if (steps.length === 0) return response;
+ if (steps.length === 0) return response
- const errorCount = steps.filter((s) => s.state === "error").length;
- const totalDuration = steps.reduce((sum, s) => sum + (s.durationMs ?? 0), 0);
- const toolNames = [...new Set(steps.map((s) => s.displayName))].join(", ");
- const icon = errorCount > 0 ? "⚠" : "✓";
+ const errorCount = steps.filter(s => s.state === 'error').length
+ const totalDuration = steps.reduce((sum, s) => sum + (s.durationMs ?? 0), 0)
+ const toolNames = [...new Set(steps.map(s => s.displayName))].join(', ')
+ const icon = errorCount > 0 ? '⚠' : '✓'
- const summary = `${icon} ${steps.length} tool${steps.length > 1 ? "s" : ""} used · ${toolNames} · ${formatDuration(totalDuration)}`;
- const full = `${summary}\n\n${response}`;
+ const summary = `${icon} ${steps.length} tool${steps.length > 1 ? 's' : ''} used · ${toolNames} · ${formatDuration(totalDuration)}`
+ const full = `${summary}\n\n${response}`
- if (full.length <= MAX_MESSAGE_LENGTH) return full;
+ if (full.length <= MAX_MESSAGE_LENGTH) return full
if (response.length > MAX_MESSAGE_LENGTH - 4) {
- return response.substring(0, MAX_MESSAGE_LENGTH - 3) + "...";
+ return response.substring(0, MAX_MESSAGE_LENGTH - 3) + '...'
}
- return response;
+ return response
}
diff --git a/channel-reader/test/progressFormatter.test.ts b/channel-reader/test/progressFormatter.test.ts
new file mode 100644
index 000000000..86f5d8d82
--- /dev/null
+++ b/channel-reader/test/progressFormatter.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest'
+import { describeToolError } from '../src/progressFormatter'
+
+describe('describeToolError', () => {
+ it('classifies an authentication failure without leaking the envelope', () => {
+ const out = describeToolError('MCP error -32603: Authentication Failed: Bad credentials')
+ expect(out).toBe('unavailable (authentication problem). Ask your administrator.')
+ expect(out).not.toContain('-32603')
+ expect(out).not.toContain('Bad credentials')
+ })
+
+ it('classifies a timeout', () => {
+ expect(describeToolError('request timed out after 30000ms')).toBe('unavailable (timed out).')
+ })
+
+ it('falls back to generic for anything unrecognised', () => {
+ expect(describeToolError('kaboom {"secret":"hunter2"}')).toBe('unavailable.')
+ })
+
+ it('falls back to generic for undefined', () => {
+ expect(describeToolError(undefined)).toBe('unavailable.')
+ })
+})