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): accept setTaskVerify booleans and numbers sent as strings (#20056)

Arvin Xu362a29fc0fb4
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 31ce04a8e13..0701e15be99 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/task.test.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/task.test.ts
@@ -1025,6 +1025,30 @@ describe('createTaskRuntime', () => {
});
});
+ it('accepts verify booleans and numbers a model sent as strings', async () => {
+ const taskCaller = { updateVerifyConfig: vi.fn().mockResolvedValue({}) };
+ const runtime = createTaskRuntime({
+ agentModel: { existsById: vi.fn() } as any,
+ taskCaller: taskCaller as any,
+ taskModel: {
+ resolve: vi.fn().mockResolvedValue({ id: 'task-1', identifier: 'T-1' }),
+ } as any,
+ taskService: {} as any,
+ });
+
+ const result = await runtime.setTaskVerify({
+ enabled: 'true' as any,
+ identifier: 'T-1',
+ maxIterations: '3' as any,
+ });
+
+ expect(result.success).toBe(true);
+ expect(taskCaller.updateVerifyConfig).toHaveBeenCalledWith({
+ id: 'task-1',
+ verify: { enabled: true, maxIterations: 3 },
+ });
+ });
+
it('handles status-only updates', async () => {
const taskCaller = {
updateStatus: vi.fn().mockResolvedValue({ data: { identifier: 'T-1' } }),
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/task.ts b/apps/server/src/services/toolExecution/serverRuntimes/task.ts
index 918d79dc7a7..dea81081167 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/task.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/task.ts
@@ -3,6 +3,7 @@ import {
MISSING_TASK_NAME_ERROR,
normalizeListTasksParams,
normalizeListWorkspaceMembersParams,
+ normalizeSetTaskVerifyParams,
selectAssignableMembers,
TaskIdentifier,
} from '@lobechat/builtin-tool-task';
@@ -737,6 +738,7 @@ export const createTaskRuntime = (deps: TaskRuntimeDeps) => {
verifyCriteriaIds?: string[] | null;
verifyRubricId?: string | null;
}) => {
+ args = normalizeSetTaskVerifyParams(args);
const task = await taskModel().resolve(args.identifier);
if (!task) return { content: `Task not found: ${args.identifier}`, success: false };
diff --git a/packages/builtin-tool-task/src/client/executor/index.ts b/packages/builtin-tool-task/src/client/executor/index.ts
index 796923fe239..f28b56158ef 100644
--- a/packages/builtin-tool-task/src/client/executor/index.ts
+++ b/packages/builtin-tool-task/src/client/executor/index.ts
@@ -36,6 +36,7 @@ import { MISSING_TASK_NAME_ERROR } from '../../constants';
import { normalizeListTasksParams } from '../../listTasks';
import { selectAssignableMembers } from '../../listWorkspaceMembers';
import { TaskIdentifier } from '../../manifest';
+import { normalizeSetTaskVerifyParams } from '../../setTaskVerify';
import type {
AddTaskCommentParams,
CreateTaskParams,
@@ -677,6 +678,7 @@ class TaskExecutor extends BaseExecutor<typeof TaskApiName> {
): Promise<BuiltinToolResult> => {
try {
log('[TaskExecutor] setTaskVerify - params:', params);
+ params = normalizeSetTaskVerifyParams(params);
const { identifier } = params;
diff --git a/packages/builtin-tool-task/src/index.ts b/packages/builtin-tool-task/src/index.ts
index 183778186cb..9f8b8e13e16 100644
--- a/packages/builtin-tool-task/src/index.ts
+++ b/packages/builtin-tool-task/src/index.ts
@@ -12,6 +12,7 @@ export {
selectAssignableMembers,
} from './listWorkspaceMembers';
export { TaskIdentifier, TaskManifest } from './manifest';
+export { normalizeSetTaskVerifyParams } from './setTaskVerify';
export { systemPrompt } from './systemRole';
export type {
CreateGoalParams,
diff --git a/packages/builtin-tool-task/src/setTaskVerify.test.ts b/packages/builtin-tool-task/src/setTaskVerify.test.ts
new file mode 100644
index 00000000000..f7bc73c28d0
--- /dev/null
+++ b/packages/builtin-tool-task/src/setTaskVerify.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from 'vitest';
+
+import { normalizeSetTaskVerifyParams } from './setTaskVerify';
+
+describe('normalizeSetTaskVerifyParams', () => {
+ it('coerces stringified booleans and integers', () => {
+ expect(
+ normalizeSetTaskVerifyParams({ enabled: 'true', identifier: 'T-1', maxIterations: '3' }),
+ ).toEqual({ enabled: true, identifier: 'T-1', maxIterations: 3 });
+ expect(normalizeSetTaskVerifyParams({ enabled: 'False' })).toEqual({ enabled: false });
+ expect(normalizeSetTaskVerifyParams({ enabled: '"true"', maxIterations: '"2"' })).toEqual({
+ enabled: true,
+ maxIterations: 2,
+ });
+ expect(normalizeSetTaskVerifyParams({ enabled: 'null', maxIterations: 'null' })).toEqual({
+ enabled: null,
+ maxIterations: null,
+ });
+ });
+
+ it('leaves real values and unknown strings untouched', () => {
+ expect(normalizeSetTaskVerifyParams({ enabled: true, maxIterations: 2 })).toEqual({
+ enabled: true,
+ maxIterations: 2,
+ });
+ expect(normalizeSetTaskVerifyParams({ enabled: 'yes', maxIterations: 'two' })).toEqual({
+ enabled: 'yes',
+ maxIterations: 'two',
+ });
+ expect(normalizeSetTaskVerifyParams({ identifier: 'T-1' })).toEqual({ identifier: 'T-1' });
+ // Clearing is reserved for an explicit null; an empty string must still be
+ // rejected by the schema instead of silently wiping the setting.
+ expect(normalizeSetTaskVerifyParams({ enabled: '', maxIterations: ' ' })).toEqual({
+ enabled: '',
+ maxIterations: ' ',
+ });
+ });
+});
diff --git a/packages/builtin-tool-task/src/setTaskVerify.ts b/packages/builtin-tool-task/src/setTaskVerify.ts
new file mode 100644
index 00000000000..679560ba773
--- /dev/null
+++ b/packages/builtin-tool-task/src/setTaskVerify.ts
@@ -0,0 +1,32 @@
+/**
+ * Weak models sometimes send `setTaskVerify` booleans and numbers as JSON
+ * strings (`"true"`, `"3"`) — the manifest types them as `boolean | null` /
+ * `integer | null` unions, which some models flatten to strings. Passed
+ * through, the TRPC schema rejects the whole call with "expected boolean,
+ * received string". Coerce the unambiguous literals; leave anything else for
+ * the schema to report.
+ */
+export const normalizeSetTaskVerifyParams = <T extends object>(params: T): T => {
+ const normalized = { ...params } as Record<string, unknown>;
+ // Some models double-encode: `"\"true\""`.
+ const literal = (value: string) =>
+ value
+ .trim()
+ .replace(/^"(.*)"$/, '$1')
+ .trim();
+
+ if (typeof normalized.enabled === 'string') {
+ const value = literal(normalized.enabled).toLowerCase();
+ if (value === 'true') normalized.enabled = true;
+ else if (value === 'false') normalized.enabled = false;
+ else if (value === 'null') normalized.enabled = null;
+ }
+
+ if (typeof normalized.maxIterations === 'string') {
+ const value = literal(normalized.maxIterations);
+ if (value === 'null') normalized.maxIterations = null;
+ else if (/^\d+$/.test(value)) normalized.maxIterations = Number(value);
+ }
+
+ return normalized as T;
+};