fix: propagate queue cancel to run state

This commit is contained in:
Codex
2026-06-09 02:12:12 +08:00
parent 0227babce6
commit 70f2a6e22a
3 changed files with 9 additions and 5 deletions
+2 -2
View File
@@ -985,8 +985,8 @@ CREATE TABLE IF NOT EXISTS agentrun_schema_migrations (
async cancelQueueTask(taskId: string, reason = "cancel requested"): Promise<QueueTaskRecord> {
const task = await this.getQueueTask(taskId);
if (isTerminalQueueTaskState(task.state)) return task;
if (task.latestAttempt?.commandId) await this.cancelCommand(task.latestAttempt.commandId, reason);
else if (task.latestAttempt?.runId) await this.cancelRun(task.latestAttempt.runId, reason);
if (task.latestAttempt?.runId) await this.cancelRun(task.latestAttempt.runId, reason);
else if (task.latestAttempt?.commandId) await this.cancelCommand(task.latestAttempt.commandId, reason);
return this.withTransaction(async (client) => {
const existing = await client.query("SELECT * FROM agentrun_queue_tasks WHERE id = $1 FOR UPDATE", [taskId]);
const row = existing.rows[0];
+2 -2
View File
@@ -495,8 +495,8 @@ export class MemoryAgentRunStore implements AgentRunStore {
cancelQueueTask(taskId: string, reason = "cancel requested"): QueueTaskRecord {
const task = this.getQueueTask(taskId);
if (isTerminalQueueTaskState(task.state)) return task;
if (task.latestAttempt?.commandId) this.cancelCommand(task.latestAttempt.commandId, reason);
else if (task.latestAttempt?.runId) this.cancelRun(task.latestAttempt.runId, reason);
if (task.latestAttempt?.runId) this.cancelRun(task.latestAttempt.runId, reason);
else if (task.latestAttempt?.commandId) this.cancelCommand(task.latestAttempt.commandId, reason);
const at = nowIso();
const latestAttempt = task.latestAttempt ? { ...task.latestAttempt, state: "cancelled" as const } : null;
const next: QueueTaskRecord = { ...task, state: "cancelled", latestAttempt, version: this.nextQueueVersion(), updatedAt: at, cancelledAt: at, cancelReason: reason };