Confirm manual task stops and protect cancellation state
Verify control plane / verify (push) Canceled after 0s
Verify control plane / verify (pull_request) Canceled after 0s

This commit is contained in:
WebUp Cloud committed 2026-11-07 23:06:52 +08:00
1 parent 4f2cf2fc87
commit fb82821dc7
4 files changed
+132 -14

No files matched your search

@@ -400,6 +400,12 @@ public class TaskService {
@Transactional
public void finish(UUID id, String lease, String status, String error, boolean release) {
var t = locked(id, lease);
if ("CANCEL".equals(t.get("requested_action"))
&& !Set.of("CANCELLED", "REVIEW_REQUIRED").contains(status)) {
status = "CANCELLED";
error = "用户已停止任务,已结算产生的费用";
release = true;
}
db.update(
"UPDATE ai_tasks SET"
+ " status=?,error=?,requested_action='',lease_token=NULL,lease_expires_at=NULL,updated_at=CURRENT_TIMESTAMP"
@@ -419,6 +425,9 @@ public class TaskService {
find(id, user);
var t = db.queryForMap("SELECT * FROM ai_tasks WHERE id=? FOR UPDATE", id);
String status = t.get("status").toString();
boolean stopping = status.equals("RUNNING") && "CANCEL".equals(t.get("requested_action"));
if (action.equals("cancel") && (stopping || status.equals("CANCELLED"))) return find(id, user);
if (stopping) throw new ApiError.Failure(409, "任务正在停止");
if (action.equals("resume") && status.equals("PAUSED")) {
db.update(
"UPDATE ai_tasks SET status='QUEUED',error='',requested_action='',max_steps=CASE WHEN"
@@ -430,7 +439,10 @@ public class TaskService {
else db.update("UPDATE ai_tasks SET requested_action='PAUSE' WHERE id=?", id);
event(id, "PAUSE_REQUESTED", "当前步骤结束后暂停");
} else if (action.equals("cancel") && (status.equals("QUEUED") || status.equals("PAUSED"))) {
db.update("UPDATE ai_tasks SET status='CANCELLED' WHERE id=?", id);
db.update(
"UPDATE ai_tasks SET status='CANCELLED',requested_action='',updated_at=CURRENT_TIMESTAMP"
+ " WHERE id=?",
id);
wallets.release(UUID.fromString(t.get("reservation_id").toString()));
queue.refundUnused(id);
event(id, "CANCELLED", "用户取消,未使用预留已释放");