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(task): refuse createTask without a name (#20057)

Arvin Xu4f6910c7bbb2
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/task.test.ts b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/task.test.ts
index c489db29546..31ce04a8e13 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/task.test.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/task.test.ts
@@ -1,4 +1,8 @@
-import { normalizeListTasksParams, UNFINISHED_TASK_STATUSES } from '@lobechat/builtin-tool-task';
+import {
+ MISSING_TASK_NAME_ERROR,
+ normalizeListTasksParams,
+ UNFINISHED_TASK_STATUSES,
+} from '@lobechat/builtin-tool-task';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createTaskRuntime, taskRuntime } from '../task';
@@ -298,6 +302,24 @@ describe('createTaskRuntime', () => {
);
});
+ it.each([undefined, '', ' '])(
+ 'refuses to create a task without a name (%j) instead of storing an unnamed row',
+ async (name) => {
+ const deps = makeDeps();
+ const runtime = createTaskRuntime({
+ agentModel: deps.agentModel as any,
+ taskCaller: deps.taskCaller,
+ taskModel: deps.taskModel as any,
+ taskService: deps.taskService as any,
+ });
+
+ const result = await runtime.createTask({ instruction: 'Do something', name } as any);
+
+ expect(result).toMatchObject({ content: MISSING_TASK_NAME_ERROR, success: false });
+ expect(deps.taskService.createTask).not.toHaveBeenCalled();
+ },
+ );
+
it('embeds a workspace-scoped link when the task is in a workspace', async () => {
const deps = makeDeps();
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/task.ts b/apps/server/src/services/toolExecution/serverRuntimes/task.ts
index 7dbe1fb8dae..918d79dc7a7 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/task.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/task.ts
@@ -1,5 +1,6 @@
import type { ListWorkspaceMembersParams } from '@lobechat/builtin-tool-task';
import {
+ MISSING_TASK_NAME_ERROR,
normalizeListTasksParams,
normalizeListWorkspaceMembersParams,
selectAssignableMembers,
@@ -201,6 +202,9 @@ export const createTaskRuntime = (deps: TaskRuntimeDeps) => {
assigneeUserId: rawArgs.assigneeUserId?.trim() || undefined,
parentIdentifier: rawArgs.parentIdentifier?.trim() || undefined,
};
+ // `name` is required by the manifest but nothing enforced it: nameless
+ // tasks listed as "(unnamed)" and the receipt printed `"null"`.
+ if (!args.name?.trim()) return { content: MISSING_TASK_NAME_ERROR, success: false };
let parentLabel: string | undefined;
// Pre-resolve parent identifier so we can surface a tool-friendly error
diff --git a/packages/builtin-tool-task/src/client/executor/index.ts b/packages/builtin-tool-task/src/client/executor/index.ts
index 404c1ae4c06..796923fe239 100644
--- a/packages/builtin-tool-task/src/client/executor/index.ts
+++ b/packages/builtin-tool-task/src/client/executor/index.ts
@@ -32,6 +32,7 @@ import { findSubtaskParentId } from '@/store/task/slices/detail/reducer';
import { useUserStore } from '@/store/user';
import { userProfileSelectors } from '@/store/user/selectors';
+import { MISSING_TASK_NAME_ERROR } from '../../constants';
import { normalizeListTasksParams } from '../../listTasks';
import { selectAssignableMembers } from '../../listWorkspaceMembers';
import { TaskIdentifier } from '../../manifest';
@@ -217,6 +218,13 @@ class TaskExecutor extends BaseExecutor<typeof TaskApiName> {
const parentIdentifier = params.parentIdentifier?.trim() || undefined;
const assigneeAgentId = params.assigneeAgentId?.trim() || undefined;
const assigneeUserId = params.assigneeUserId?.trim() || undefined;
+ if (!params.name?.trim()) {
+ return {
+ content: MISSING_TASK_NAME_ERROR,
+ error: { message: MISSING_TASK_NAME_ERROR, type: 'InvalidParams' },
+ success: false,
+ };
+ }
// Executing agent and human owner are independent, coexisting sides (the
// member owns the outcome, the agent executes) — a member owner does not
diff --git a/packages/builtin-tool-task/src/constants.ts b/packages/builtin-tool-task/src/constants.ts
index a2754e7d5cc..3e2768c73df 100644
--- a/packages/builtin-tool-task/src/constants.ts
+++ b/packages/builtin-tool-task/src/constants.ts
@@ -9,3 +9,7 @@ export const TASK_STATUSES = [
] as const;
export const UNFINISHED_TASK_STATUSES = ['backlog', 'running', 'scheduled', 'paused'] as const;
+
+/** Tool result for a create call without a usable `name` (required by the manifest). */
+export const MISSING_TASK_NAME_ERROR =
+ 'Task not created: `name` is required. Pass a short, descriptive name for the task and call again.';
diff --git a/packages/builtin-tool-task/src/index.ts b/packages/builtin-tool-task/src/index.ts
index 4a64e35d8a7..183778186cb 100644
--- a/packages/builtin-tool-task/src/index.ts
+++ b/packages/builtin-tool-task/src/index.ts
@@ -1,4 +1,4 @@
-export { TASK_STATUSES, UNFINISHED_TASK_STATUSES } from './constants';
+export { MISSING_TASK_NAME_ERROR, TASK_STATUSES, UNFINISHED_TASK_STATUSES } from './constants';
export {
DEFAULT_LIST_TASK_LIMIT,
normalizeListTasksParams,