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:
@@ -8,7 +8,8 @@ export function buildBackgroundTaskNotificationText(args: {
|
||||
completedTasks: BackgroundTask[]
|
||||
}): string {
|
||||
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}` : ""
|
||||
|
||||
if (allComplete) {
|
||||
|
||||
@@ -13,7 +13,7 @@ export async function notifyParentSession(
|
||||
): Promise<void> {
|
||||
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)
|
||||
|
||||
const toastManager = getTaskToastManager()
|
||||
|
||||
@@ -94,7 +94,10 @@ export async function pollRunningTasks(args: {
|
||||
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")
|
||||
|
||||
let toolCalls = 0
|
||||
|
||||
@@ -55,7 +55,8 @@ export async function validateSessionHasOutput(
|
||||
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 hasAssistantOrToolMessage = messages.some((message) => {
|
||||
|
||||
@@ -45,7 +45,7 @@ export function getRunningTasks(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 {
|
||||
|
||||
@@ -48,7 +48,11 @@ export async function resumeBackgroundTask(args: {
|
||||
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)
|
||||
existingTask.concurrencyKey = concurrencyKey
|
||||
existingTask.concurrencyGroup = concurrencyKey
|
||||
|
||||
Reference in New Issue
Block a user