feat(FN-4730): complete Step 2 — defer hook after summarization

Fusion-Task-Id: FN-4730
Fusion-Task-Lineage: 10fa1d65-f898-4576-bbca-a796df13bedb
This commit is contained in:
Fusion (runfusion.ai)
2026-05-16 08:28:50 -07:00
committed by gsxdsm
parent c3651da1b5
commit bed8dac04a

View File

@@ -2823,6 +2823,7 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
!title &&
input.description.length > 200 &&
(input.summarize === true || options?.settings?.autoSummarizeTitles === true);
const hasPendingSummarization = shouldSummarize && typeof options?.onSummarize === "function";
// Determine enabledWorkflowSteps: explicit input takes precedence, otherwise auto-apply default-on steps
let resolvedWorkflowSteps: string[] | undefined = input.enabledWorkflowSteps?.length
@@ -2855,11 +2856,19 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
if (input.dependencies?.includes(taskId)) {
throw new Error(`Task ${taskId} cannot depend on itself`);
}
return this._createTaskInternal(input, title, resolvedWorkflowSteps, taskId);
return this._createTaskInternal(
input,
title,
resolvedWorkflowSteps,
taskId,
undefined,
undefined,
{ invokeTaskCreatedHook: !hasPendingSummarization },
);
},
});
if (shouldSummarize && options?.onSummarize) {
if (hasPendingSummarization) {
const id = task.id;
Promise.resolve().then(async () => {
try {
@@ -2884,6 +2893,23 @@ export class TaskStore extends EventEmitter<TaskStoreEvents> {
},
);
}
let latestTask = task;
try {
const refreshed = this.readTaskFromDb(id);
if (refreshed) latestTask = refreshed;
} catch {
// Best-effort refresh; fall back to original task snapshot.
}
try {
await this.invokeTaskCreatedHook(latestTask);
} catch (err) {
storeLog.warn("Deferred task-created hook failed", {
taskId: id,
error: err instanceof Error ? err.message : String(err),
});
}
}).catch((err) => {
const autoEnabled = options?.settings?.autoSummarizeTitles === true;
storeLog.error("Unexpected title summarization promise-chain failure", {