fix(FN-2107): normalize task ID handling for task creation tools

- Return the created task ID directly from runTaskPlan and propagate it through fn_task_plan
- Remove hardcoded FN-### log parsing so CLI extension supports structured IDs like PROJ-042
- Add heartbeat fallback parsing from task_create text output when details.taskId is absent
- Expand engine and CLI tests to cover structured task IDs and updated task-plan return behavior
This commit is contained in:
Fusion
2026-04-19 03:21:26 -07:00
committed by gsxdsm
parent a901975ed8
commit 2f611ce489
7 changed files with 106 additions and 33 deletions

View File

@@ -9,6 +9,7 @@ import {
HEARTBEAT_SYSTEM_PROMPT_NO_TASK,
} from "./agent-heartbeat.js";
import { AgentLogger } from "./agent-logger.js";
import * as agentTools from "./agent-tools.js";
import type { AgentStore, AgentHeartbeatRun, TaskStore, TaskDetail, Agent, MessageStore, Message, AgentBudgetStatus } from "@fusion/core";
// Mock logger to suppress noise in test output
@@ -3290,6 +3291,35 @@ describe("HeartbeatMonitor", () => {
);
});
it("task_create tracking falls back to parsing text when details.taskId is missing", async () => {
const store = createMockStore();
const createTaskCreateToolSpy = vi.spyOn(agentTools, "createTaskCreateTool").mockReturnValue({
name: "task_create",
label: "Create Task",
description: "Create a task",
parameters: {} as any,
execute: vi.fn().mockResolvedValue({
content: [{ type: "text", text: "Created PROJ-777: Follow-up task" }],
details: {},
}),
} as any);
const monitor = new HeartbeatMonitor({ store, taskStore: mockTaskStore, rootDir: "/tmp" });
try {
const tools = monitor.createHeartbeatTools("agent-001", mockTaskStore, "FN-001");
await tools[0]!.execute("call-1", { description: "Follow-up task" }, undefined as any, undefined as any, undefined as any);
expect(mockTaskStore.logEntry).toHaveBeenCalledWith(
"PROJ-777",
"Created by agent agent-001 during heartbeat run",
undefined,
undefined,
);
} finally {
createTaskCreateToolSpy.mockRestore();
}
});
it("task_create tracking handles missing details gracefully", async () => {
const store = createMockStore();
const missingDetailsTaskStore = createMockTaskStoreForTools({

View File

@@ -1432,7 +1432,9 @@ export class HeartbeatMonitor {
execute: async (id: string, params: Static<typeof taskCreateParams>, signal, onUpdate, ctx) => {
const result = await baseCreateTool.execute(id, params, signal, onUpdate, ctx);
const createdTaskId = (result.details as { taskId?: string })?.taskId ?? "unknown";
const textResponse = result.content.find((item) => item.type === "text")?.text;
const taskIdMatch = textResponse?.match(/(?:Created|created) (\w+-\d+):/);
const createdTaskId = (result.details as { taskId?: string } | undefined)?.taskId ?? taskIdMatch?.[1] ?? "unknown";
// Log agent link on the created task with run context for correlation
try {

View File

@@ -6,6 +6,7 @@ import {
buildQmdAgentMemoryCollectionAddArgs,
buildQmdAgentMemorySearchArgs,
createMemoryTools,
createTaskCreateTool,
createSendMessageTool,
createReadMessagesTool,
qmdAgentMemoryCollectionName,
@@ -54,6 +55,41 @@ vi.mock("node:child_process", async () => {
};
});
describe("createTaskCreateTool", () => {
it("returns details.taskId and keeps Created <id> response text", async () => {
const store = {
createTask: vi.fn().mockResolvedValue({
id: "PROJ-042",
description: "Follow-up task",
dependencies: ["PROJ-001"],
column: "triage",
}),
};
const tool = createTaskCreateTool(store as any);
const result = await tool.execute(
"call-1",
{
description: "Follow-up task",
dependencies: ["PROJ-001"],
} as any,
undefined,
undefined,
{} as any,
);
expect(store.createTask).toHaveBeenCalledWith({
description: "Follow-up task",
dependencies: ["PROJ-001"],
column: "triage",
});
expect(result.details).toEqual({ taskId: "PROJ-042" });
const responseText = result.content[0]?.type === "text" ? result.content[0].text : "";
expect(responseText).toContain("Created PROJ-042: Follow-up task");
expect(responseText).toContain("(depends on: PROJ-001)");
});
});
describe("createMemoryTools", () => {
let tempDir: string;