Skip to content

RE: a cancel Prefect accepts is never reported as failed (TR-62c) - #1116

Merged
dwolfson merged 3 commits into
mainfrom
claude/tr62c-cancel-reject
Nov 19, 2026
Merged

dwolfson merged 3 commits into
mainfrom
claude/tr62c-cancel-reject

Conversation

@dwolfson

Copy link
Copy Markdown
Owner

TR-62c: a cancel Prefect accepts is never reported as failed

This fixes a regression from #1115 (TR-62a/b), found in that PR's live proof on laz on 2026-11-19.

The bug. When a run hasn't started yet (SCHEDULED or PENDING, so it has no infrastructure), Prefect rejects the CANCELLING proposal and sets the run to CANCELLED itself. request_cancel treated every ABORT or REJECT as a refusal. So for a run that Prefect had in fact cancelled:

  • the deadline line said "cancel attempt FAILED … the run may still be live" (flow run 90cf24d0, 17:17:49Z);
  • the Admin route answered 502 "Could not cancel".

The old forced Cancelled() had handled this case.

The fix. After an ABORT or REJECT, request_cancel re-reads the run.

  • CANCELLED, and the run never started (no start_time): success, worded "the run was cancelled before it started". The route returns 200 {"status": "cancelled"}.
  • CANCELLED after the run started: "cancelled".
  • CANCELLING: "cancelling". This covers a second Admin Cancel on a running run.
  • Any other state: the existing refusal words stay.

Commits

  • 60b0cb5: the re-read and the wording.
  • 516930c: a test-ratchet fix.
  • 7704c5d: R1 from the Architect's read-back. "Before it started" is said only when the run never started.

Tests

  • New test_tr62c_cancel_reject_is_cancelled.py, 18 tests. A REJECT followed by a CANCELLED read is success on both the deadline path and the route. An ABORT followed by a COMPLETED read stays a refusal.
  • Architect read-back: PASS, at 516930c and again after R1. In an RE-only venv the tr62a/b/c, status-routes and poll-timeout tests give 79 passed, 0 failed, both env ways.
  • Gate b458 against main 852b696: PASS. Main suite 15566 passed, 0 failed. The render harness and trellis-analytics (294/0) pass.

No separate live proof is needed (Architect). Nothing runs or writes differently; only the reported outcome changes.

🤖 Generated with Claude Code

… is a cancel

laz, flow run 90cf24d0: a SCHEDULED run hit RE's deadline. Prefect REJECTed
the CANCELLING proposal ("Scheduled flow run has no infrastructure to
terminate.") and set CANCELLED itself (BypassCancellingFlowRunsWithNoInfra),
but request_cancel read every ABORT/REJECT as a refusal: the deadline line
said "cancel attempt FAILED ... the run may still be live", and the Admin
route answered 502 on a run it had cancelled. The forced CANCELLED TR-62b
removed had covered this case.

request_cancel now re-reads the run after an ABORT or REJECT: CANCELLED or
CANCELLING is success, "before it started" (CancelOutcome.before_start). The
deadline line ends "; the run was cancelled before it started"; the route
returns {"status": "cancelled"}. Any other state, or an unreadable one, keeps
the existing refusal words.

Tests: tests/test_tr62c_cancel_reject_is_cancelled.py (13).

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
The full suite's no-silent-success ratchet caught a log-free `except: pass`
around the re-read. The refusal now ends "; its state could not be read
afterwards (<Type>)", so "refused" and "refused, and we could not check"
read differently.

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
Read-back R1: before_start was set for any CANCELLED or CANCELLING read
after a refused cancel. CancelOutcome now says `cancelled` (CANCELLED now)
and `before_start` (CANCELLED and no start_time) separately:
- refused, then CANCELLING (e.g. a second Admin Cancel on a running run):
  a cancel under way; the route says "cancelling", the deadline line
  "; the run was cancelled";
- refused, then CANCELLED with a start_time (an earlier cancel won): the
  route says "cancelled", the deadline line "; the run was cancelled";
- refused, then CANCELLED with no start_time (the laz SCHEDULED case):
  "; the run was cancelled before it started", route "cancelled".

Tests: the CANCELLING half of the earlier parametrized success test now
expects a cancel under way (R1), plus 7 new cases.

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
@dwolfson
dwolfson merged commit 6b80583 into main Nov 19, 2026
4 checks passed
dwolfson added a commit that referenced this pull request Nov 19, 2026
…nto the odpi sync

Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant