MCPcopy Create free account
hub / github.com/HKUDS/AgentSpace / completeQueuedTaskSync

Function completeQueuedTaskSync

packages/db/src/task-queue.ts:385–473  ·  view source on GitHub ↗
(input: {
  taskId: string;
  resultJson?: Record<string, unknown>;
  sessionId?: string;
  workDir?: string;
})

Source from the content-addressed store, hash-verified

383}
384
385export function completeQueuedTaskSync(input: {
386 taskId: string;
387 resultJson?: Record<string, unknown>;
388 sessionId?: string;
389 workDir?: string;
390}): QueuedTaskRecord {
391 const db = getDatabase();
392 const now = new Date().toISOString();
393 const previous = readQueuedTaskSync(input.taskId);
394 db.prepare(
395 `UPDATE agent_task_queue
396 SET status = 'completed',
397 result_json = ?,
398 session_id = ?,
399 work_dir = ?,
400 finished_at = ?,
401 updated_at = ?
402 WHERE id = ?`,
403 ).run(
404 input.resultJson ? JSON.stringify(input.resultJson) : null,
405 input.sessionId ?? null,
406 input.workDir ?? null,
407 now,
408 now,
409 input.taskId,
410 );
411
412 const task = readQueuedTaskSync(input.taskId);
413 if (!task) {
414 throw new Error(`Queued task "${input.taskId}" does not exist.`);
415 }
416 if (previous?.status !== "completed") {
417 const attempt = readLatestAgentTaskAttemptForTaskSync(task.id);
418 const runtime = readAgentRuntimeSync(task.runtimeId);
419 if (attempt) {
420 updateAgentTaskAttemptSync({
421 attemptId: attempt.id,
422 status: "completed",
423 providerSessionId: input.sessionId ?? null,
424 metadata: mergeJsonObject(attempt.metadataJson, {
425 workDir: input.workDir,
426 completedAt: task.finishedAt,
427 resumeMode: attempt.providerSessionId ? "same_provider_resume" : "cold_rebuild",
428 }),
429 });
430 }
431 if (runtime && task.routerSessionId && input.sessionId) {
432 upsertAgentRouterProviderSessionSync({
433 workspaceId: task.workspaceId,
434 routerSessionId: task.routerSessionId,
435 runtimeId: task.runtimeId,
436 provider: runtime.provider,
437 providerSessionId: input.sessionId,
438 metadata: {
439 taskQueueId: task.id,
440 attemptId: attempt?.id,
441 workDir: input.workDir,
442 },

Callers 5

executeQueuedTaskFunction · 0.90
data.test.tsFile · 0.90
POSTFunction · 0.90

Calls 13

getDatabaseFunction · 0.90
readAgentRuntimeSyncFunction · 0.90
readQueuedTaskSyncFunction · 0.85
mergeJsonObjectFunction · 0.85
readResultSummaryFunction · 0.85
recordArtifactEventsFunction · 0.85
prepareMethod · 0.80

Tested by

no test coverage detected