π€― 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
π style(task): stop automation tasks from marking themselves completed (#17911)
Arvin Xud383ce7543e0
diff --git a/apps/server/src/services/taskRunner/buildTaskPrompt.ts b/apps/server/src/services/taskRunner/buildTaskPrompt.tsindex 63a71da1c06..18e31abb37c 100644--- a/apps/server/src/services/taskRunner/buildTaskPrompt.ts+++ b/apps/server/src/services/taskRunner/buildTaskPrompt.ts@@ -240,12 +240,14 @@ export async function buildTaskPrompt(parentTask: parentTaskContext,task: {assigneeAgentId: task.assigneeAgentId,+ automationMode: task.automationMode,dependencies: dependencies.map((d: any) => ({dependsOn: depIdToIdentifier.get(d.dependsOnId) ?? d.dependsOnId,type: d.type,})),description: task.description,...(taskFiles.length > 0 ? { files: taskFiles } : {}),+ heartbeatInterval: task.heartbeatInterval,id: task.id,identifier: task.identifier,instruction: task.instruction,@@ -253,6 +255,8 @@ export async function buildTaskPrompt(parentIdentifier,priority: task.priority,review: taskModel.getReviewConfig(task) as any,+ schedulePattern: task.schedulePattern,+ scheduleTimezone: task.scheduleTimezone,status: task.status,verify: verifyEnabled? {diff --git a/apps/server/src/services/taskRunner/taskSkill.test.ts b/apps/server/src/services/taskRunner/taskSkill.test.tsnew file mode 100644index 00000000000..3831adce3ff--- /dev/null+++ b/apps/server/src/services/taskRunner/taskSkill.test.ts@@ -0,0 +1,42 @@+import { readFileSync } from 'node:fs';+import { createRequire } from 'node:module';+import { dirname, join } from 'node:path';++import { builtinSkills, TaskIdentifier } from '@lobechat/builtin-skills';+import { describe, expect, it } from 'vitest';++// The vitest config stubs `.md` imports to an empty string, so read the skill+// instructions straight from disk instead of through the package export.+const builtinSkillsEntry = createRequire(import.meta.url).resolve('@lobechat/builtin-skills');+const content = readFileSync(join(dirname(builtinSkillsEntry), 'task/SKILL.md'), 'utf8');++/**+ * TaskRunnerService auto-activates the task skill for every task run, so its+ * SKILL.md lands in the system context β a higher-priority surface than the+ * per-run task prompt. Guard that the "complete when done" guidance it ships+ * carries the automation exception; without it, a quiet automation tick can+ * follow the skill and `lh task complete` its own recurring task, which+ * cancels the in-flight run and permanently disarms the heartbeat/schedule+ * loop.+ */+describe('task skill instructions', () => {+ it('is mounted under the identifier the task runner auto-activates', () => {+ expect(builtinSkills.some((s) => s.identifier === TaskIdentifier)).toBe(true);+ });++ it('ships the complete-when-done guidance the exception guards against', () => {+ expect(content).toContain('lh task complete');+ expect(content).toContain('Complete when done');+ });++ it('forbids completing automation tasks via the CLI', () => {+ expect(content).toContain('Automation tasks are the exception β NEVER complete them');+ expect(content).toContain(+ 'NEVER run `lh task complete` (or set a terminal status via `lh task edit --status`)',+ );+ // The exception must follow the completion guidance it carves out of.+ expect(content.indexOf('NEVER run `lh task complete`')).toBeGreaterThan(+ content.indexOf('Complete when done'),+ );+ });+});diff --git a/packages/builtin-skills/src/task/SKILL.md b/packages/builtin-skills/src/task/SKILL.mdindex 26f4693c8e6..ad03c1e2faa 100644--- a/packages/builtin-skills/src/task/SKILL.md+++ b/packages/builtin-skills/src/task/SKILL.md@@ -1,4 +1,4 @@-\<task_skill_guides>+\<task\_skill\_guides>You are executing a task within the LobeHub task system. Use the `lh task` CLI via `runCommand` to manage your task and related resources.# Task Lifecycle@@ -50,4 +50,5 @@ You are executing a task within the LobeHub task system. Use the `lh task` CLI v- **Report progress**: Use `lh task comment` to log key milestones- **Respect dependencies**: Check `lh task tree` to understand task ordering- **Complete when done**: Use `lh task complete` when all deliverables are ready- \</task_skill_guides>+- **Automation tasks are the exception β NEVER complete them**: a task with automation (heartbeat or schedule β shown as an `Automation:` line in the task context) is a recurring loop, and this run is one tick of it. NEVER run `lh task complete` (or set a terminal status via `lh task edit --status`) on that task: a terminal status cancels the in-flight run and permanently disarms the loop β no future tick will fire and nothing recovers it. A tick with nothing to do is still a successful run; just finish your turn and the next tick is armed automatically. Only the user retires a recurring task.+ \</task\_skill\_guides>diff --git a/packages/builtin-tool-task/src/systemRole.ts b/packages/builtin-tool-task/src/systemRole.tsindex a1a2f84c870..8f621701c09 100644--- a/packages/builtin-tool-task/src/systemRole.ts+++ b/packages/builtin-tool-task/src/systemRole.ts@@ -21,6 +21,8 @@ Schedule fields (setTaskSchedule):After configuring a cron-based schedule (automationMode="schedule") on a task that is neither currently running nor already scheduled, start its schedule by default with updateTaskStatus(identifier, "scheduled") so it waits for the next scheduled run. When the user explicitly asks to keep it paused or as a draft, call updateTaskStatus(identifier, "paused") instead β a schedule-mode task left in any other non-terminal status is still picked up by the cron dispatcher. Never call updateTaskStatus on a currently running task just to arm the schedule β that interrupts the in-flight run, and the task returns to "scheduled" automatically once the run completes. A task already in "scheduled" stays armed after schedule edits β re-calling updateTaskStatus would reset its execution-count window. Do NOT call runTask just to start the schedule β runTask executes the task immediately.+An automation task (automationMode 'heartbeat' or 'schedule') is a recurring loop: each triggered run is one tick, and a tick with nothing to do is still a SUCCESSFUL tick β not a reason to close the task. When the task you are currently executing is an automation task, NEVER call updateTaskStatus with "completed" (or any other terminal status) on it: a terminal status cancels the in-flight run and permanently disarms the loop β no future tick will ever fire, and nothing recovers it automatically. Simply finish your turn; the scheduler parks the task back at 'scheduled' and arms the next tick on its own. Instructions like "end this run normally" or "treat as completed" refer to the current tick, not the task. Only the user retires a recurring task β either by doing it themselves or by explicitly asking you to stop the recurring task for good.+Verify fields (setTaskVerify):- **enabled**: true to require a verify gate when the task completes, false to disable, null to clear- **requirement**: a one-sentence description of what "done" means for the task; the server synthesizes acceptance criteria from it. This is usually all you need@@ -40,4 +42,4 @@ When planning work:1. Create tasks for each major piece of work (use parentIdentifier to organize as subtasks)2. Use editTask with addDependencies to control execution order3. For executable tasks dispatched to an agent, use setTaskVerify to attach acceptance criteria before running them-4. Use updateTaskStatus to mark the current task as completed when you finish all work`;+4. Use updateTaskStatus to mark the current task as completed when you finish all work β unless it is an automation (heartbeat/schedule) task, which must stay non-terminal so its loop keeps running`;diff --git a/packages/prompts/src/prompts/task/index.test.ts b/packages/prompts/src/prompts/task/index.test.tsindex 153882a624e..484c01efcd1 100644--- a/packages/prompts/src/prompts/task/index.test.ts+++ b/packages/prompts/src/prompts/task/index.test.ts@@ -112,6 +112,61 @@ describe('buildTaskRunPrompt', () => {expect(result).toMatchSnapshot();});+ it('should render a heartbeat automation line with the interval and a no-terminal warning', () => {+ const result = buildTaskRunPrompt(+ {+ task: {+ ...baseTask,+ automationMode: 'heartbeat',+ heartbeatInterval: 14_400,+ identifier: 'TASK-1',+ instruction: 'ζ― 4 ε°ζΆηε¬ Discord ι’ι',+ name: 'Discord ηε¬',+ },+ },+ NOW,+ );++ expect(result).toContain('Automation: heartbeat, every 4h');+ expect(result).toContain('NEVER set this task to completed');+ });++ it('should render a schedule automation line with the cron pattern and timezone', () => {+ const result = buildTaskRunPrompt(+ {+ task: {+ ...baseTask,+ automationMode: 'schedule',+ identifier: 'TASK-1',+ instruction: 'ζ―倩ζ©δΈζ±ζ»',+ name: 'ζ―ζ₯ζ±ζ»',+ schedulePattern: '0 9 * * *',+ scheduleTimezone: 'Asia/Shanghai',+ },+ },+ NOW,+ );++ expect(result).toContain('Automation: cron "0 9 * * *" (Asia/Shanghai)');+ expect(result).toContain('NEVER set this task to completed');+ });++ it('should not render an automation line for non-automation tasks', () => {+ const result = buildTaskRunPrompt(+ {+ task: {+ ...baseTask,+ identifier: 'TASK-1',+ instruction: 'δΈζ¬‘ζ§δ»»ε‘',+ name: 'δΈζ¬‘ζ§δ»»ε‘',+ },+ },+ NOW,+ );++ expect(result).not.toContain('Automation:');+ });+it('should prioritize user feedback at the top', () => {const result = buildTaskRunPrompt({diff --git a/packages/prompts/src/prompts/task/index.ts b/packages/prompts/src/prompts/task/index.tsindex 0bab01c85f7..01c9ba933f1 100644--- a/packages/prompts/src/prompts/task/index.ts+++ b/packages/prompts/src/prompts/task/index.ts@@ -417,11 +417,13 @@ export interface TaskRunPromptInput {/** Task data */task: {assigneeAgentId?: string | null;+ automationMode?: 'heartbeat' | 'schedule' | null;dependencies?: Array<{ dependsOn: string; type: string }>;description?: string | null;/** Lightweight metadata of files attached to the task instruction. Actual* content is forwarded to the agent runtime via `fileIds` on execAgent. */files?: TaskRunPromptAttachment[];+ heartbeatInterval?: number | null;id: string;identifier: string;instruction: string;@@ -433,6 +435,8 @@ export interface TaskRunPromptInput {maxIterations?: number;rubrics?: Array<{ name: string; threshold?: number; type: string }>;} | null;+ schedulePattern?: string | null;+ scheduleTimezone?: string | null;status: string;subtasks?: Array<TaskSummary & { blockedBy?: string }>;/** Delivery-acceptance criteria the builder must self-evidence while working. */@@ -466,6 +470,14 @@ const timeAgo = (dateStr: string, now?: Date): string => {return `${diffDay}d ago`;};+// ββ Heartbeat interval helper ββ++const formatInterval = (seconds: number): string => {+ if (seconds % 3600 === 0) return `${seconds / 3600}h`;+ if (seconds % 60 === 0) return `${seconds / 60}m`;+ return `${seconds}s`;+};+// ββ Brief icon ββconst briefIcon = (type: string): string => {@@ -528,8 +540,19 @@ export const buildTaskRunPrompt = (input: TaskRunPromptInput, now?: Date): strin`<hint>This tag contains the complete task context. Do NOT call viewTask to re-fetch it.</hint>`,`${task.identifier} ${task.name || task.identifier}`,`Status: ${statusIcon(task.status)} ${task.status} Priority: ${priorityLabel(task.priority)}`,- `Instruction: ${task.instruction}`,];+ if (task.automationMode) {+ const cadence =+ task.automationMode === 'heartbeat' && task.heartbeatInterval+ ? `heartbeat, every ${formatInterval(task.heartbeatInterval)}`+ : task.automationMode === 'schedule' && task.schedulePattern+ ? `cron "${task.schedulePattern}" (${task.scheduleTimezone || 'UTC'})`+ : task.automationMode;+ taskLines.push(+ `Automation: ${cadence} β this task is a recurring loop and this run is one tick of it. When the run ends, the next tick is armed automatically; a tick with nothing to do is still a successful run. NEVER set this task to completed (or any terminal status) β that permanently stops the loop.`,+ );+ }+ taskLines.push(`Instruction: ${task.instruction}`);if (task.description) taskLines.push(`Description: ${task.description}`);if (task.files && task.files.length > 0) {taskLines.push('Attachments (contents provided separately as multimodal inputs):');