feat(cloud): add durable cancellation support to task repository

- Add nullable cancel_requested_at column (migration 0012)
- Widen ScheduledTaskStatus/TerminalTaskStatus to include cancelled
- Add CancellationRequestStatus + request_task_cancellation() to
  CloudRepository protocol and SQLAlchemy implementation
- renew_lease() now returns LeaseRenewalResult, surfacing whether
  cancellation is pending, instead of a bare status string
- reap_expired_leases() resolves pending-cancellation tasks to
  cancelled instead of requeuing/failing them
- record_task_result() accepts cancelled and clears
  cancel_requested_at on any terminal write

Note: internal_api/api.py's renew_assignment route still compares
renew_lease()'s return value against a bare string; it will be
updated in the next task (Internal Host<->Cloud protocol) to consume
LeaseRenewalResult and populate the new cancel_requested wire field.
This commit is contained in:
2026-07-15 18:08:48 +08:00
parent 88189770ff
commit 19c6669800
9 changed files with 385 additions and 35 deletions
@@ -110,6 +110,7 @@ class ScheduledTaskRow(Base):
progress_step_status: Mapped[str | None] = mapped_column(String, nullable=True)
progress_summary: Mapped[str | None] = mapped_column(String, nullable=True)
progress_updated_at: Mapped[str | None] = mapped_column(String, nullable=True)
cancel_requested_at: Mapped[str | None] = mapped_column(String, nullable=True)
failure_reason: Mapped[str | None] = mapped_column(Text, nullable=True)
result_json: Mapped[str | None] = mapped_column(Text, nullable=True)
updated_at: Mapped[str | None] = mapped_column(String, nullable=True)