fix: address Cubic background-agent issues — task status filter, array response handling, error mapping, concurrency key, duration fallback, output validation
This commit is contained in:
parent
d6fbe7bd8d
commit
247940bf02
@ -8,7 +8,8 @@ export function buildBackgroundTaskNotificationText(args: {
|
|||||||
completedTasks: BackgroundTask[]
|
completedTasks: BackgroundTask[]
|
||||||
}): string {
|
}): string {
|
||||||
const { task, duration, allComplete, remainingCount, completedTasks } = args
|
const { task, duration, allComplete, remainingCount, completedTasks } = args
|
||||||
const statusText = task.status === "completed" ? "COMPLETED" : "CANCELLED"
|
const statusText =
|
||||||
|
task.status === "completed" ? "COMPLETED" : task.status === "error" ? "ERROR" : "CANCELLED"
|
||||||
const errorInfo = task.error ? `\n**Error:** ${task.error}` : ""
|
const errorInfo = task.error ? `\n**Error:** ${task.error}` : ""
|
||||||
|
|
||||||
if (allComplete) {
|
if (allComplete) {
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export async function notifyParentSession(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { client, state } = ctx
|
const { client, state } = ctx
|
||||||
|
|
||||||
const duration = formatDuration(task.startedAt ?? new Date(), task.completedAt)
|
const duration = formatDuration(task.startedAt ?? task.completedAt ?? new Date(), task.completedAt)
|
||||||
log("[background-agent] notifyParentSession called for task:", task.id)
|
log("[background-agent] notifyParentSession called for task:", task.id)
|
||||||
|
|
||||||
const toastManager = getTaskToastManager()
|
const toastManager = getTaskToastManager()
|
||||||
|
|||||||
@ -94,7 +94,10 @@ export async function pollRunningTasks(args: {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const messages = asSessionMessages((messagesResult as { data?: unknown }).data)
|
const messagesPayload = Array.isArray(messagesResult)
|
||||||
|
? messagesResult
|
||||||
|
: (messagesResult as { data?: unknown }).data
|
||||||
|
const messages = asSessionMessages(messagesPayload)
|
||||||
const assistantMsgs = messages.filter((m) => m.info?.role === "assistant")
|
const assistantMsgs = messages.filter((m) => m.info?.role === "assistant")
|
||||||
|
|
||||||
let toolCalls = 0
|
let toolCalls = 0
|
||||||
|
|||||||
@ -55,7 +55,8 @@ export async function validateSessionHasOutput(
|
|||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
})
|
})
|
||||||
|
|
||||||
const messagesRaw = "data" in response ? response.data : []
|
const messagesRaw =
|
||||||
|
isObject(response) && "data" in response ? (response as { data?: unknown }).data : response
|
||||||
const messages = Array.isArray(messagesRaw) ? messagesRaw : []
|
const messages = Array.isArray(messagesRaw) ? messagesRaw : []
|
||||||
|
|
||||||
const hasAssistantOrToolMessage = messages.some((message) => {
|
const hasAssistantOrToolMessage = messages.some((message) => {
|
||||||
|
|||||||
@ -45,7 +45,7 @@ export function getRunningTasks(tasks: Iterable<BackgroundTask>): BackgroundTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getCompletedTasks(tasks: Iterable<BackgroundTask>): BackgroundTask[] {
|
export function getCompletedTasks(tasks: Iterable<BackgroundTask>): BackgroundTask[] {
|
||||||
return Array.from(tasks).filter((t) => t.status !== "running")
|
return Array.from(tasks).filter((t) => t.status === "completed")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasRunningTasks(tasks: Iterable<BackgroundTask>): boolean {
|
export function hasRunningTasks(tasks: Iterable<BackgroundTask>): boolean {
|
||||||
|
|||||||
@ -48,7 +48,11 @@ export async function resumeBackgroundTask(args: {
|
|||||||
return existingTask
|
return existingTask
|
||||||
}
|
}
|
||||||
|
|
||||||
const concurrencyKey = existingTask.concurrencyGroup ?? existingTask.agent
|
const concurrencyKey =
|
||||||
|
existingTask.concurrencyGroup ??
|
||||||
|
(existingTask.model
|
||||||
|
? `${existingTask.model.providerID}/${existingTask.model.modelID}`
|
||||||
|
: existingTask.agent)
|
||||||
await concurrencyManager.acquire(concurrencyKey)
|
await concurrencyManager.acquire(concurrencyKey)
|
||||||
existingTask.concurrencyKey = concurrencyKey
|
existingTask.concurrencyKey = concurrencyKey
|
||||||
existingTask.concurrencyGroup = concurrencyKey
|
existingTask.concurrencyGroup = concurrencyKey
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user