refactor(delegate-task): remove AI slop from executor metadata paths
Strip obvious comments, over-defensive guards, and dead branches across the five delegate-task executor files while preserving all metadata propagation behavior added in prior commits. Regression tests remain green (328 pass / 0 fail).
This commit is contained in:
@@ -14,9 +14,9 @@ export async function executeBackgroundContinuation(
|
|||||||
parentContext: ParentContext
|
parentContext: ParentContext
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const { manager } = executorCtx
|
const { manager } = executorCtx
|
||||||
|
const taskID = getTaskID(args)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const taskID = getTaskID(args)
|
|
||||||
if (!taskID) {
|
if (!taskID) {
|
||||||
throw new Error("task_id is required to continue a background task")
|
throw new Error("task_id is required to continue a background task")
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,9 @@ export async function executeBackgroundContinuation(
|
|||||||
parentAgent: parentContext.agent,
|
parentAgent: parentContext.agent,
|
||||||
parentTools: getSessionTools(parentContext.sessionID),
|
parentTools: getSessionTools(parentContext.sessionID),
|
||||||
})
|
})
|
||||||
|
const sessionId = task.sessionID
|
||||||
|
const backgroundTaskId = task.id
|
||||||
|
const resolvedModel = resolveMetadataModel(task.model, parentContext.model)
|
||||||
|
|
||||||
const bgContMeta = {
|
const bgContMeta = {
|
||||||
title: `Continue: ${task.description}`,
|
title: `Continue: ${task.description}`,
|
||||||
@@ -41,38 +44,38 @@ export async function executeBackgroundContinuation(
|
|||||||
load_skills: args.load_skills,
|
load_skills: args.load_skills,
|
||||||
description: args.description,
|
description: args.description,
|
||||||
run_in_background: args.run_in_background,
|
run_in_background: args.run_in_background,
|
||||||
taskId: task.sessionID,
|
taskId: sessionId,
|
||||||
backgroundTaskId: task.id,
|
backgroundTaskId,
|
||||||
sessionId: task.sessionID,
|
sessionId,
|
||||||
command: args.command,
|
command: args.command,
|
||||||
model: resolveMetadataModel(task.model, parentContext.model),
|
model: resolvedModel,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
await publishToolMetadata(ctx, bgContMeta)
|
await publishToolMetadata(ctx, bgContMeta)
|
||||||
|
|
||||||
return `Background task continued.
|
return `Background task continued.
|
||||||
|
|
||||||
Task ID: ${task.id}
|
Task ID: ${backgroundTaskId}
|
||||||
Description: ${task.description}
|
Description: ${task.description}
|
||||||
Agent: ${task.agent}
|
Agent: ${task.agent}
|
||||||
Status: ${task.status}
|
Status: ${task.status}
|
||||||
|
|
||||||
Agent continues with full previous context preserved.
|
Agent continues with full previous context preserved.
|
||||||
System notifies on completion. Use \`background_output\` with task_id="${task.id}" to check.
|
System notifies on completion. Use \`background_output\` with task_id="${backgroundTaskId}" to check.
|
||||||
|
|
||||||
Do NOT call background_output now. Wait for <system-reminder> notification first.
|
Do NOT call background_output now. Wait for <system-reminder> notification first.
|
||||||
|
|
||||||
${buildTaskMetadataBlock({
|
${buildTaskMetadataBlock({
|
||||||
sessionId: task.sessionID,
|
sessionId,
|
||||||
taskId: task.sessionID,
|
taskId: sessionId,
|
||||||
backgroundTaskId: task.id,
|
backgroundTaskId,
|
||||||
agent: task.agent,
|
agent: task.agent,
|
||||||
})}`
|
})}`
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return formatDetailedError(error, {
|
return formatDetailedError(error, {
|
||||||
operation: "Continue background task",
|
operation: "Continue background task",
|
||||||
args,
|
args,
|
||||||
sessionID: getTaskID(args),
|
sessionID: taskID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,9 +115,9 @@ export async function executeBackgroundTask(
|
|||||||
|
|
||||||
if (sessionId) {
|
if (sessionId) {
|
||||||
executorCtx.modelFallbackControllerAccessor?.setSessionFallbackChain(sessionId, fallbackChain)
|
executorCtx.modelFallbackControllerAccessor?.setSessionFallbackChain(sessionId, fallbackChain)
|
||||||
}
|
if (args.category) {
|
||||||
if (args.category && sessionId) {
|
SessionCategoryRegistry.register(sessionId, args.category)
|
||||||
SessionCategoryRegistry.register(sessionId, args.category)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolvedModel = resolveMetadataModel(categoryModel, parentContext.model)
|
const resolvedModel = resolveMetadataModel(categoryModel, parentContext.model)
|
||||||
@@ -130,17 +130,15 @@ export async function executeBackgroundTask(
|
|||||||
description: args.description,
|
description: args.description,
|
||||||
run_in_background: args.run_in_background,
|
run_in_background: args.run_in_background,
|
||||||
command: args.command,
|
command: args.command,
|
||||||
...(sessionId ? { taskId: sessionId } : {}),
|
...(sessionId ? { taskId: sessionId, sessionId } : {}),
|
||||||
backgroundTaskId: task.id,
|
backgroundTaskId: task.id,
|
||||||
...(sessionId ? { sessionId } : {}),
|
|
||||||
...(resolvedModel ? { model: resolvedModel } : {}),
|
...(resolvedModel ? { model: resolvedModel } : {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
const unstableMeta = {
|
await publishToolMetadata(ctx, {
|
||||||
title: args.description,
|
title: args.description,
|
||||||
metadata,
|
metadata,
|
||||||
}
|
})
|
||||||
await publishToolMetadata(ctx, unstableMeta)
|
|
||||||
|
|
||||||
const taskMetadataBlock = sessionId
|
const taskMetadataBlock = sessionId
|
||||||
? `\n\n${buildTaskMetadataBlock({
|
? `\n\n${buildTaskMetadataBlock({
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ import { isPlanFamily } from "./constants"
|
|||||||
import { publishToolMetadata } from "../../features/tool-metadata-store"
|
import { publishToolMetadata } from "../../features/tool-metadata-store"
|
||||||
import { getTaskToastManager } from "../../features/task-toast-manager"
|
import { getTaskToastManager } from "../../features/task-toast-manager"
|
||||||
import { getAgentToolRestrictions } from "../../shared/agent-tool-restrictions"
|
import { getAgentToolRestrictions } from "../../shared/agent-tool-restrictions"
|
||||||
import { getMessageDir } from "../../shared"
|
import { getMessageDir, normalizeSDKResponse } from "../../shared"
|
||||||
import { promptWithModelSuggestionRetry } from "../../shared/model-suggestion-retry"
|
import { promptWithModelSuggestionRetry } from "../../shared/model-suggestion-retry"
|
||||||
import { findNearestMessageWithFields } from "../../features/hook-message-injector"
|
import { findNearestMessageWithFields } from "../../features/hook-message-injector"
|
||||||
import { formatDuration } from "./time-formatter"
|
import { formatDuration } from "./time-formatter"
|
||||||
import { syncContinuationDeps, type SyncContinuationDeps } from "./sync-continuation-deps"
|
import { syncContinuationDeps, type SyncContinuationDeps } from "./sync-continuation-deps"
|
||||||
import { setSessionTools } from "../../shared/session-tools-store"
|
import { setSessionTools } from "../../shared/session-tools-store"
|
||||||
import { normalizeSDKResponse } from "../../shared"
|
|
||||||
import { buildTaskPrompt } from "./prompt-builder"
|
import { buildTaskPrompt } from "./prompt-builder"
|
||||||
import { buildTaskMetadataBlock } from "../../features/tool-metadata-store/task-metadata-contract"
|
import { buildTaskMetadataBlock } from "../../features/tool-metadata-store/task-metadata-contract"
|
||||||
import { getTaskID } from "./task-id"
|
import { getTaskID } from "./task-id"
|
||||||
@@ -41,8 +40,6 @@ export async function executeSyncContinuation(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let syncContMeta: { title: string; metadata: Record<string, unknown> } | undefined
|
|
||||||
|
|
||||||
let resumeAgent: string | undefined
|
let resumeAgent: string | undefined
|
||||||
let resumeModel: { providerID: string; modelID: string } | undefined
|
let resumeModel: { providerID: string; modelID: string } | undefined
|
||||||
let resumeVariant: string | undefined
|
let resumeVariant: string | undefined
|
||||||
@@ -56,8 +53,11 @@ export async function executeSyncContinuation(
|
|||||||
for (let i = messages.length - 1; i >= 0; i--) {
|
for (let i = messages.length - 1; i >= 0; i--) {
|
||||||
const info = messages[i].info
|
const info = messages[i].info
|
||||||
if (info?.agent || info?.model || (info?.modelID && info?.providerID)) {
|
if (info?.agent || info?.model || (info?.modelID && info?.providerID)) {
|
||||||
|
const fallbackResumeModel = info.providerID && info.modelID
|
||||||
|
? { providerID: info.providerID, modelID: info.modelID }
|
||||||
|
: undefined
|
||||||
resumeAgent = info.agent
|
resumeAgent = info.agent
|
||||||
resumeModel = info.model ?? (info.providerID && info.modelID ? { providerID: info.providerID, modelID: info.modelID } : undefined)
|
resumeModel = info.model ?? fallbackResumeModel
|
||||||
resumeVariant = info.variant
|
resumeVariant = info.variant
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -65,14 +65,15 @@ export async function executeSyncContinuation(
|
|||||||
} catch {
|
} catch {
|
||||||
const resumeMessageDir = getMessageDir(continuationID)
|
const resumeMessageDir = getMessageDir(continuationID)
|
||||||
const resumeMessage = resumeMessageDir ? findNearestMessageWithFields(resumeMessageDir) : null
|
const resumeMessage = resumeMessageDir ? findNearestMessageWithFields(resumeMessageDir) : null
|
||||||
|
const resumeMessageModel = resumeMessage?.model
|
||||||
resumeAgent = resumeMessage?.agent
|
resumeAgent = resumeMessage?.agent
|
||||||
resumeModel = resumeMessage?.model?.providerID && resumeMessage?.model?.modelID
|
resumeModel = resumeMessageModel?.providerID && resumeMessageModel.modelID
|
||||||
? { providerID: resumeMessage.model.providerID, modelID: resumeMessage.model.modelID }
|
? { providerID: resumeMessageModel.providerID, modelID: resumeMessageModel.modelID }
|
||||||
: undefined
|
: undefined
|
||||||
resumeVariant = resumeMessage?.model?.variant
|
resumeVariant = resumeMessageModel?.variant
|
||||||
}
|
}
|
||||||
|
|
||||||
syncContMeta = {
|
const syncContMeta = {
|
||||||
title: `Continue: ${args.description}`,
|
title: `Continue: ${args.description}`,
|
||||||
metadata: {
|
metadata: {
|
||||||
prompt: args.prompt,
|
prompt: args.prompt,
|
||||||
|
|||||||
@@ -88,13 +88,15 @@ export async function executeSyncTask(
|
|||||||
|
|
||||||
if (onSyncSessionCreated) {
|
if (onSyncSessionCreated) {
|
||||||
log("[task] Invoking onSyncSessionCreated callback", { sessionID, parentID: parentContext.sessionID })
|
log("[task] Invoking onSyncSessionCreated callback", { sessionID, parentID: parentContext.sessionID })
|
||||||
await onSyncSessionCreated({
|
try {
|
||||||
sessionID,
|
await onSyncSessionCreated({
|
||||||
parentID: parentContext.sessionID,
|
sessionID,
|
||||||
title: args.description,
|
parentID: parentContext.sessionID,
|
||||||
}).catch((err) => {
|
title: args.description,
|
||||||
log("[task] onSyncSessionCreated callback failed", { error: String(err) })
|
})
|
||||||
})
|
} catch (error) {
|
||||||
|
log("[task] onSyncSessionCreated callback failed", { error: String(error) })
|
||||||
|
}
|
||||||
await new Promise(r => setTimeout(r, 200))
|
await new Promise(r => setTimeout(r, 200))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,16 +136,20 @@ export async function executeSyncTask(
|
|||||||
}
|
}
|
||||||
await publishToolMetadata(ctx, syncTaskMeta)
|
await publishToolMetadata(ctx, syncTaskMeta)
|
||||||
|
|
||||||
let effectiveCategoryModel = categoryModel
|
const syncPromptInput = {
|
||||||
let promptError = await deps.sendSyncPrompt(client, {
|
|
||||||
sessionID,
|
sessionID,
|
||||||
agentToUse,
|
agentToUse,
|
||||||
args,
|
args,
|
||||||
systemContent,
|
systemContent,
|
||||||
categoryModel: effectiveCategoryModel,
|
|
||||||
toastManager,
|
toastManager,
|
||||||
taskId,
|
taskId,
|
||||||
sisyphusAgentConfig: executorCtx.sisyphusAgentConfig,
|
sisyphusAgentConfig: executorCtx.sisyphusAgentConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
let effectiveCategoryModel = categoryModel
|
||||||
|
let promptError = await deps.sendSyncPrompt(client, {
|
||||||
|
...syncPromptInput,
|
||||||
|
categoryModel: effectiveCategoryModel,
|
||||||
})
|
})
|
||||||
if (promptError) {
|
if (promptError) {
|
||||||
const promptResult = await retrySyncPromptWithFallbacks({
|
const promptResult = await retrySyncPromptWithFallbacks({
|
||||||
@@ -153,14 +159,8 @@ export async function executeSyncTask(
|
|||||||
fallbackChain,
|
fallbackChain,
|
||||||
sendPrompt: async (fallbackModel) => {
|
sendPrompt: async (fallbackModel) => {
|
||||||
return deps.sendSyncPrompt(client, {
|
return deps.sendSyncPrompt(client, {
|
||||||
sessionID,
|
...syncPromptInput,
|
||||||
agentToUse,
|
|
||||||
args,
|
|
||||||
systemContent,
|
|
||||||
categoryModel: fallbackModel,
|
categoryModel: fallbackModel,
|
||||||
toastManager,
|
|
||||||
taskId,
|
|
||||||
sisyphusAgentConfig: executorCtx.sisyphusAgentConfig,
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -198,12 +198,12 @@ export async function executeSyncTask(
|
|||||||
const parentModelStr = parentContext.model
|
const parentModelStr = parentContext.model
|
||||||
? `${parentContext.model.providerID}/${parentContext.model.modelID}`
|
? `${parentContext.model.providerID}/${parentContext.model.modelID}`
|
||||||
: undefined
|
: undefined
|
||||||
const modelRoutingNote =
|
let modelRoutingNote = ""
|
||||||
actualModelStr && parentModelStr && actualModelStr !== parentModelStr
|
if (actualModelStr && parentModelStr && actualModelStr !== parentModelStr) {
|
||||||
? `\n⚠️ Model routing: parent used ${parentModelStr}, this subagent used ${actualModelStr} (via category: ${args.category ?? "unknown"})`
|
modelRoutingNote = `\n⚠️ Model routing: parent used ${parentModelStr}, this subagent used ${actualModelStr} (via category: ${args.category ?? "unknown"})`
|
||||||
: actualModelStr
|
} else if (actualModelStr) {
|
||||||
? `\nModel: ${actualModelStr}${args.category ? ` (category: ${args.category})` : ""}`
|
modelRoutingNote = `\nModel: ${actualModelStr}${args.category ? ` (category: ${args.category})` : ""}`
|
||||||
: ""
|
}
|
||||||
|
|
||||||
return `Task completed in ${duration}.
|
return `Task completed in ${duration}.
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,14 @@ export async function executeUnstableAgentTask(
|
|||||||
}
|
}
|
||||||
await publishToolMetadata(ctx, bgTaskMeta)
|
await publishToolMetadata(ctx, bgTaskMeta)
|
||||||
|
|
||||||
|
const taskMetadataBlock = buildTaskMetadataBlock({
|
||||||
|
sessionId: sessionID,
|
||||||
|
taskId: sessionID,
|
||||||
|
backgroundTaskId: task.id,
|
||||||
|
agent: agentToUse,
|
||||||
|
category: args.category,
|
||||||
|
})
|
||||||
|
|
||||||
const startTime = new Date()
|
const startTime = new Date()
|
||||||
const timingCfg = getTimingConfig()
|
const timingCfg = getTimingConfig()
|
||||||
const pollStart = Date.now()
|
const pollStart = Date.now()
|
||||||
@@ -152,13 +160,7 @@ Model: ${actualModel}
|
|||||||
|
|
||||||
The task session may contain partial results.
|
The task session may contain partial results.
|
||||||
|
|
||||||
${buildTaskMetadataBlock({
|
${taskMetadataBlock}`
|
||||||
sessionId: sessionID,
|
|
||||||
taskId: sessionID,
|
|
||||||
backgroundTaskId: task.id,
|
|
||||||
agent: agentToUse,
|
|
||||||
category: args.category,
|
|
||||||
})}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!completedDuringMonitoring) {
|
if (!completedDuringMonitoring) {
|
||||||
@@ -176,13 +178,7 @@ Model: ${actualModel}
|
|||||||
|
|
||||||
The task session may still contain partial results.
|
The task session may still contain partial results.
|
||||||
|
|
||||||
${buildTaskMetadataBlock({
|
${taskMetadataBlock}`
|
||||||
sessionId: sessionID,
|
|
||||||
taskId: sessionID,
|
|
||||||
backgroundTaskId: task.id,
|
|
||||||
agent: agentToUse,
|
|
||||||
category: args.category,
|
|
||||||
})}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const messagesResult = await client.session.messages({ path: { id: sessionID } })
|
const messagesResult = await client.session.messages({ path: { id: sessionID } })
|
||||||
@@ -193,9 +189,8 @@ ${buildTaskMetadataBlock({
|
|||||||
const assistantMessages = messages
|
const assistantMessages = messages
|
||||||
.filter((m) => m.info?.role === "assistant")
|
.filter((m) => m.info?.role === "assistant")
|
||||||
.sort((a, b) => (b.info?.time?.created ?? 0) - (a.info?.time?.created ?? 0))
|
.sort((a, b) => (b.info?.time?.created ?? 0) - (a.info?.time?.created ?? 0))
|
||||||
const lastMessage = assistantMessages[0]
|
|
||||||
|
|
||||||
if (!lastMessage) {
|
if (assistantMessages.length === 0) {
|
||||||
return `No assistant response found (task ran in background mode).\n\nSession ID: ${sessionID}`
|
return `No assistant response found (task ran in background mode).\n\nSession ID: ${sessionID}`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,13 +225,7 @@ RESULT:
|
|||||||
|
|
||||||
${textContent || "(No text output)"}
|
${textContent || "(No text output)"}
|
||||||
|
|
||||||
${buildTaskMetadataBlock({
|
${taskMetadataBlock}`
|
||||||
sessionId: sessionID,
|
|
||||||
taskId: sessionID,
|
|
||||||
backgroundTaskId: task.id,
|
|
||||||
agent: agentToUse,
|
|
||||||
category: args.category,
|
|
||||||
})}`
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!cleanupReason) {
|
if (!cleanupReason) {
|
||||||
cleanupReason = "exception"
|
cleanupReason = "exception"
|
||||||
|
|||||||
Reference in New Issue
Block a user