LibreChat/packages/data-provider/src/errors.spec.ts
Danny Avila 3a2241c048
🌲 feat: Expose Navigable Subagent Progress Trees (#16748)
* feat: Return a Navigable Progress Tree When Checking a Running Subagent

check_background_task on a running or finished-but-undelivered subagent now
returns an activity digest: the child's turns, tool calls, and replies folded
to one line each and addressed by stable positional paths. Callers expand one
node or range with expand, and page with since against a settled-node cursor.

The owning process folds the child's update stream into a bounded tree that
keeps only tool names, the model-authored intent label, the tool-authored
outcome label, statuses, timings, and sizes. Routed claims carry the tree to a
poll on any replica, lists carry counts and the node in flight, and a finished
child whose owner is gone is rebuilt from its durable public projection.

The background-task card renders the digest as a foldable tree and links the
existing subagent activity panel.

* fix: Tighten Progress Digest Verdicts, Overflow Bounds, and Rebuilt Trees

Failed reply steps and schema-rejected calls now record as errors, and an
overflowed call is counted once without retaining it in the lookup maps.
A tree rebuilt from the durable projection re-checks completed calls with the
shared failure verdict, carries the projection's truncation, and tells the
caller its paths are a reconstruction. The card localizes folded summaries
instead of rendering the server's English tally.

* fix: Measure Single-Part Message Deltas in the Progress Digest

* fix: Scope Nested Progress Ownership by Run and Count Overflow Once

Nested runs now attach to the call recorded by their own spawning run, since
provider call ids repeat across runs. Only the step that announces a call can
count it as overflow, so later sightings of an unretained or evicted call never
re-count it or reopen history. A zero-valued since cursor is rejected, and the
card labels MCP tools with the configured server names.
2026-10-04 15:49:57 -04:00

48 lines
1.6 KiB
TypeScript

import { isFailedToolOutput, hasToolCallErrorPrefix, stripToolCallErrorPrefix } from './errors';
describe('tool call errors', () => {
test.each([
'Error: tool call failed: unavailable',
'Error: [search] tool call failed: unavailable',
'Error: [agent] [search] tool call failed: unavailable',
])('recognizes %s', (message) => {
expect(hasToolCallErrorPrefix(message)).toBe(true);
});
test('does not scan across bracket boundaries', () => {
const ambiguous = 'Error: [agent] unexpected [search] tool call failed: unavailable';
expect(hasToolCallErrorPrefix(ambiguous)).toBe(false);
expect(stripToolCallErrorPrefix(ambiguous)).toBe(ambiguous);
});
test('rejects repeated bracket segments without the required suffix', () => {
const incomplete = `Error: ${'[tool] '.repeat(20)}unavailable`;
expect(hasToolCallErrorPrefix(incomplete)).toBe(false);
});
test('strips the complete prefix', () => {
expect(stripToolCallErrorPrefix('Error: [agent] [search] tool call failed: unavailable')).toBe(
'unavailable',
);
});
});
describe('isFailedToolOutput', () => {
test.each([
'Error: tool call failed: unavailable',
'Error processing tool',
'Error processing tool: boom',
'Error: Received tool input did not match expected schema\n Please fix your mistakes.',
])('treats %j as a failed call', (output) => {
expect(isFailedToolOutput(output)).toBe(true);
});
test.each(['PASS 12 tests', 'Error processing tools completed', 'Error: something\nPlease fix'])(
'treats %j as a completed call',
(output) => {
expect(isFailedToolOutput(output)).toBe(false);
},
);
});