Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(activator): report a skill that could not be opened as failed, not selected (#23646)

AmAzing-f2c2e4c8804d
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/activator.test.ts b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/activator.test.ts
index efe0a4e2f5e..5c45d210b6c 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/activator.test.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/activator.test.ts
@@ -254,6 +254,48 @@ describe('activatorRuntime', () => {
relatedObjects: [{ objectId: 'user-skill', objectType: 'skill', relation: 'selected' }],
});
}, 20_000);
+
+ it('reports nothing when a requested identifier is neither a tool nor a skill', async () => {
+ // The skill lookup answers a miss with `success: false` instead of
+ // throwing. That used to be reported as a successful skill selection, so
+ // every mistyped tool identifier left a skill record behind.
+ const { emitToolOutcomeSafely } = await import('@/server/services/agentSignal/procedure');
+ const { activatorRuntime } = await import('../activator');
+ const runtime = await activatorRuntime.factory({
+ agentId: 'agent-1',
+ serverDB: {} as never,
+ toolManifestMap: {},
+ userId: 'user-1',
+ });
+
+ const result = await runtime.activateTools({ identifiers: ['lobe-web-browsing-typo'] });
+
+ expect(result.state.notFound).toEqual(['lobe-web-browsing-typo']);
+ expect(emitToolOutcomeSafely).not.toHaveBeenCalled();
+ }, 20_000);
+
+ it('reports a skill that could not be opened by name as a failed skill activation', async () => {
+ const { emitToolOutcomeSafely } = await import('@/server/services/agentSignal/procedure');
+ const { activatorRuntime } = await import('../activator');
+ const runtime = await activatorRuntime.factory({
+ agentId: 'agent-1',
+ serverDB: {} as never,
+ toolManifestMap: {},
+ userId: 'user-1',
+ });
+
+ const result = await runtime.activateSkill({ name: 'missing-skill' });
+
+ expect(result.success).toBe(false);
+ expect(emitToolOutcomeSafely).toHaveBeenCalledTimes(1);
+ expect(vi.mocked(emitToolOutcomeSafely).mock.calls[0][0]).toMatchObject({
+ apiName: 'activateSkill',
+ domainKey: 'skill:builtin-skill',
+ errorReason: expect.stringContaining('Skill not found: "missing-skill"'),
+ relatedObjects: [{ objectId: 'missing-skill', objectType: 'skill', relation: 'selected' }],
+ status: 'failed',
+ });
+ }, 20_000);
});
describe('activateTools — wire-name resolution', () => {
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/activator.ts b/apps/server/src/services/toolExecution/serverRuntimes/activator.ts
index e6a5f018955..9dd4a0a316c 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/activator.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/activator.ts
@@ -21,6 +21,12 @@ import { resolveAgentSkillGates } from './librarySkillGate';
import { REMOTE_DEVICE_TOOL_IDENTIFIER } from './noActiveDevice';
import { type ServerRuntimeRegistration } from './types';
+/**
+ * A skill miss lists every available skill in its content. The reported reason
+ * only needs the leading sentence that says what went wrong.
+ */
+const MAX_ERROR_REASON_LENGTH = 200;
+
/**
* Tools Activator Server Runtime
* Resolves tool manifests from context.toolManifestMap (populated by the agent state).
@@ -140,26 +146,40 @@ export const activatorRuntime: ServerRuntimeRegistration = {
const service: ActivatorRuntimeService = {
activateSkill: skillsRuntime
- ? async (args) => {
- try {
- const result = await skillsRuntime!.activateSkill(args);
- await emitActivationOutcome({
+ ? async (args, options) => {
+ const reportFailure = (errorReason: string) =>
+ emitActivationOutcome({
+ errorReason,
identifiers: [args.name],
kind: 'skill',
- status: 'succeeded',
- summary: 'Activator selected a skill.',
+ status: 'failed',
+ summary: 'Activator failed to select a skill.',
});
- return result;
+
+ let result: Awaited<ReturnType<SkillsExecutionRuntime['activateSkill']>>;
+ try {
+ result = await skillsRuntime!.activateSkill(args);
} catch (error) {
+ await reportFailure((error as Error).message);
+ throw error;
+ }
+
+ // The skills runtime answers a skill it cannot open with
+ // `success: false` instead of throwing, so the result decides what
+ // is reported. A miss while probing an `activateTools` identifier
+ // is not a skill event: the identifier simply names nothing.
+ if (result.success) {
await emitActivationOutcome({
- errorReason: (error as Error).message,
identifiers: [args.name],
kind: 'skill',
- status: 'failed',
- summary: 'Activator failed to select a skill.',
+ status: 'succeeded',
+ summary: 'Activator selected a skill.',
});
- throw error;
+ } else if (!options?.probe) {
+ await reportFailure(result.content.slice(0, MAX_ERROR_REASON_LENGTH));
}
+
+ return result;
}
: undefined,
// A device-locked run walls the picker off, so activating it can only fail;
diff --git a/packages/builtin-tool-activator/src/ExecutionRuntime/index.ts b/packages/builtin-tool-activator/src/ExecutionRuntime/index.ts
index 53fee473c06..5d3ca57f823 100644
--- a/packages/builtin-tool-activator/src/ExecutionRuntime/index.ts
+++ b/packages/builtin-tool-activator/src/ExecutionRuntime/index.ts
@@ -28,8 +28,20 @@ export interface ToolManifestInfo {
type?: string;
}
+export interface ActivateSkillOptions {
+ /**
+ * The name is an `activateTools` identifier that matched no tool, tried as a
+ * skill name. A miss then means the identifier names nothing, not that a
+ * skill failed to open.
+ */
+ probe?: boolean;
+}
+
export interface ActivatorRuntimeService {
- activateSkill?: (args: ActivateSkillParams) => Promise<BuiltinServerRuntimeOutput>;
+ activateSkill?: (
+ args: ActivateSkillParams,
+ options?: ActivateSkillOptions,
+ ) => Promise<BuiltinServerRuntimeOutput>;
/**
* Why an identifier that exists is withheld from this run, if the host knows.
* A bare "Not found" for a tool the model has seen before reads as a typo, so
@@ -309,7 +321,7 @@ export class ActivatorExecutionRuntime {
if (notFoundAsTools.length > 0 && this.service.activateSkill) {
for (const id of notFoundAsTools) {
try {
- const skillResult = await this.service.activateSkill({ name: id });
+ const skillResult = await this.service.activateSkill({ name: id }, { probe: true });
if (skillResult.success) {
activatedSkillResults.push(skillResult);
} else {