π€― 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(cli): apply --agent and other fields alongside --status in task edit (#19183)
Arvin Xu85ac782f8af2
diff --git a/apps/cli/src/commands/task.test.ts b/apps/cli/src/commands/task.test.tsindex bdd9a40d9d3..94e85b541c1 100644--- a/apps/cli/src/commands/task.test.ts+++ b/apps/cli/src/commands/task.test.ts@@ -85,3 +85,61 @@ describe('task create', () => {);});});++describe('task edit', () => {+ const mockUpdate = vi.fn();+ const mockUpdateStatus = vi.fn();++ beforeEach(() => {+ mockUpdate.mockReset().mockResolvedValue({+ data: { id: 'task_1', identifier: 'T-1' },+ success: true,+ });+ mockUpdateStatus.mockReset().mockResolvedValue({+ data: { id: 'task_1', identifier: 'T-1' },+ success: true,+ });+ mockGetTrpcClient.mockResolvedValue({+ task: {+ update: { mutate: mockUpdate },+ updateStatus: { mutate: mockUpdateStatus },+ },+ });+ mockLogInfo.mockReset();+ });++ const run = async (...args: string[]) => {+ const program = new Command();+ program.exitOverride();+ registerTaskCommand(program);+ await program.parseAsync(['node', 'test', 'task', 'edit', ...args]);+ };++ // --status used to early-return, silently dropping --agent and every other+ // field passed in the same invocation.+ it('applies --agent and --status together in one invocation', async () => {+ await run('task_1', '--agent', 'agt_new', '--status', 'backlog');++ expect(mockUpdate).toHaveBeenCalledWith(+ expect.objectContaining({ assigneeAgentId: 'agt_new', id: 'task_1', status: 'backlog' }),+ );+ expect(mockUpdateStatus).not.toHaveBeenCalled();+ expect(mockLogInfo).toHaveBeenCalledWith(expect.stringContaining('backlog'));+ });++ it('keeps the status-only path on the lifecycle API alone', async () => {+ await run('task_1', '--status', 'paused');++ expect(mockUpdateStatus).toHaveBeenCalledWith({ id: 'task_1', status: 'paused' });+ expect(mockUpdate).not.toHaveBeenCalled();+ });++ it('keeps field-only edits off the lifecycle API', async () => {+ await run('task_1', '--agent', 'agt_new');++ expect(mockUpdate).toHaveBeenCalledWith(+ expect.objectContaining({ assigneeAgentId: 'agt_new', id: 'task_1' }),+ );+ expect(mockUpdateStatus).not.toHaveBeenCalled();+ });+});diff --git a/apps/cli/src/commands/task/index.ts b/apps/cli/src/commands/task/index.tsindex 41ba589e370..ffe011fc671 100644--- a/apps/cli/src/commands/task/index.ts+++ b/apps/cli/src/commands/task/index.ts@@ -569,18 +569,6 @@ export function registerTaskCommand(program: Command) {) => {const client = await getTrpcClient();- // Handle --status separately (uses updateStatus API)- if (options.status) {- const valid = ['backlog', 'running', 'paused', 'completed', 'failed', 'canceled'];- if (!valid.includes(options.status)) {- log.error(`Invalid status "${options.status}". Must be one of: ${valid.join(', ')}`);- return;- }- const result = await client.task.updateStatus.mutate({ id, status: options.status });- log.info(`${pc.bold(result.data.identifier)} β ${options.status}`);- return;- }-const input: Record<string, any> = { id };if (options.name) input.name = options.name;if (options.instruction) input.instruction = options.instruction;@@ -593,6 +581,25 @@ export function registerTaskCommand(program: Command) {const val = Number.parseInt(options.heartbeatTimeout, 10);input.heartbeatTimeout = val === 0 ? null : val;}+ const hasFieldEdits = Object.keys(input).length > 1;++ // Status-only edits use the lifecycle API. Combined edits go through+ // task.update so the server can apply the fields and lifecycle change+ // atomically.+ if (options.status) {+ const valid = ['backlog', 'running', 'paused', 'completed', 'failed', 'canceled'];+ if (!valid.includes(options.status)) {+ log.error(`Invalid status "${options.status}". Must be one of: ${valid.join(', ')}`);+ return;+ }+ if (!hasFieldEdits) {+ const result = await client.task.updateStatus.mutate({ id, status: options.status });+ log.info(`${pc.bold(result.data.identifier)} β ${options.status}`);+ return;+ }++ input.status = options.status;+ }const result = await client.task.update.mutate(input as any);@@ -601,7 +608,8 @@ export function registerTaskCommand(program: Command) {return;}- log.info(`Task updated: ${pc.bold(result.data.identifier)}`);+ const statusSuffix = options.status ? ` β ${options.status}` : '';+ log.info(`Task updated: ${pc.bold(result.data.identifier)}${statusSuffix}`);},);diff --git a/apps/server/src/routers/lambda/__tests__/integration/task.integration.test.ts b/apps/server/src/routers/lambda/__tests__/integration/task.integration.test.tsindex 02a9b89feba..08c5780822f 100644--- a/apps/server/src/routers/lambda/__tests__/integration/task.integration.test.ts+++ b/apps/server/src/routers/lambda/__tests__/integration/task.integration.test.ts@@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { AcceptanceModel } from '@/database/models/acceptance';import { TaskModel } from '@/database/models/task';import { TaskTopicModel } from '@/database/models/taskTopic';+import { TaskService } from '@/server/services/task';import { taskRouter } from '../../task';import {@@ -208,6 +209,35 @@ describe('Task Router Integration', () => {expect(richTextUpdate.data.instruction).toBe('Rich instruction');expect(richTextUpdate.data.editorData).toEqual(nextEditorData);});++ it('should apply field and status edits in one mutation', async () => {+ const task = await caller.create({ instruction: 'Original', name: 'Original' });++ const result = await caller.update({+ id: task.data.id,+ name: 'Updated',+ status: 'completed',+ });++ expect(result.data.name).toBe('Updated');+ expect(result.data.status).toBe('completed');+ });++ it('should roll back field edits when the status transition fails', async () => {+ const task = await caller.create({ instruction: 'Original', name: 'Original' });+ const statusError = vi+ .spyOn(TaskService.prototype, 'updateStatus')+ .mockRejectedValueOnce(new Error('status transition failed'));++ await expect(+ caller.update({ id: task.data.id, name: 'Updated', status: 'completed' }),+ ).rejects.toThrow('Failed to update task');++ statusError.mockRestore();+ const persisted = await new TaskModel(serverDB, userId).findById(task.data.id);+ expect(persisted?.name).toBe('Original');+ expect(persisted?.status).toBe('backlog');+ });});describe('coexisting assignees (agent + member)', () => {diff --git a/apps/server/src/routers/lambda/task.ts b/apps/server/src/routers/lambda/task.tsindex 5e0e82bdbaa..7f18a96aa27 100644--- a/apps/server/src/routers/lambda/task.ts+++ b/apps/server/src/routers/lambda/task.ts@@ -131,6 +131,7 @@ const updateSchema = z.object({priority: z.number().min(0).max(4).optional(),schedulePattern: z.string().nullish(),scheduleTimezone: z.string().nullish(),+ status: z.enum(TASK_STATUSES).optional(),});const listSchema = z.object({@@ -1415,7 +1416,7 @@ export const taskRouter = router({}),update: taskProcedureWrite.input(idInput.merge(updateSchema)).mutation(async ({ input, ctx }) => {- const { id, parentTaskId, ...data } = input;+ const { id, parentTaskId, status, ...data } = input;try {const model = ctx.taskModel;await assertAssigneeAgentBelongsToUser(@@ -1481,10 +1482,19 @@ export const taskRouter = router({updateData.instruction !== undefined && updateData.editorData === undefined? { ...updateData, editorData: null }: updateData;- const task = await ctx.taskService.updateTaskWithAssigneeLock(- resolved.id,- normalizedUpdateData,- );+ const task = status+ ? await ctx.serverDB.transaction(async (tx) => {+ const taskService = new TaskService(tx, ctx.userId, ctx.workspaceId ?? undefined);+ const updated = await taskService.updateTaskWithAssigneeLock(+ resolved.id,+ normalizedUpdateData,+ );+ if (!updated) return null;++ const result = await taskService.updateStatus({ id: resolved.id, status });+ return result.task;+ })+ : await ctx.taskService.updateTaskWithAssigneeLock(resolved.id, normalizedUpdateData);if (!task) throw new TRPCError({ code: 'NOT_FOUND', message: 'Task not found' });// Only an actual assignee change notifies β re-saving the same assignee// stays silent (self-assignment is filtered inside the helper).