Skip to content

fix(miles-service): use force=False in _cancel_inflight — force=True is a no-op for actor tasks#39

Open
JunzheJoe wants to merge 1 commit into
zhenyu/miles-mvp-e2efrom
joe/cancel-inflight-actor-semantics
Open

fix(miles-service): use force=False in _cancel_inflight — force=True is a no-op for actor tasks#39
JunzheJoe wants to merge 1 commit into
zhenyu/miles-mvp-e2efrom
joe/cancel-inflight-actor-semantics

Conversation

@JunzheJoe

Copy link
Copy Markdown
Collaborator

What

Review finding F56-CANCEL-SYNC (F1-F12 review, confirmed against the Ray docs on 2026-07-06 — see docs/m11-joe-f1-f12-review.md §5 F5+F6).

Ray's ray.cancel contract for actor tasks: "Only force=False is allowed for an Actor Task. Otherwise, it raises ValueError."

Every ref in inflight_refs is an actor-method ObjectRef (run_sync_session / finalize_weight_update / set_weight_version / get_free_port / try_put), so the R06-F1 timeout fan-out ray.cancel(ref, force=True) raised ValueError on every single ref — swallowed by the per-ref try/except, logged as a warning. Net effect: the whole cancellation mechanism was a silent no-op; not even queued tasks were ever cancelled.

Fix (minimal)

  • force=Trueforce=False: queued follow-up RPCs behind a wedged transport are now genuinely cancelled and never start.
  • Rewrote the R06-F1 comment to state the real, narrower guarantee: a task already executing on the sync cache_owner / rollout_manager actors cannot be interrupted (Ray only sets a cooperative is_canceled() flag that miles does not poll) — it runs to completion and keeps _cache_lock until then. The old comment claimed interruption that Ray never provided.

Not in scope

Cooperative interruption of an executing run_sync_session (polling is_canceled() inside the bucket loop, or making the service chain async-actor-based) is a real design change — deferred for team discussion.

Adjacent, not conflicting: #23 adds pause/continue refs into inflight_refs; this PR makes the cancel they'd receive actually work. The two compose — #23's refs are exactly the queued-task kind this fix can cancel.

Test

tests/test_miles_service_cancel_inflight.py — the ray stub mirrors Ray's contract (raises on force=True), pinning that every ref reaches ray.cancel with force=False and the list drains. Suite: 60 passed, 3 skipped.

…is a no-op for actor tasks

Ray only allows force=False when cancelling actor tasks; force=True
raises ValueError before cancelling anything ('Only force=False is
allowed for an Actor Task', Ray 2.55 docs). Every ref in inflight_refs
is an actor-method ObjectRef, so the R06-F1 timeout fan-out never
cancelled a single task — each ValueError was swallowed by the per-ref
try/except and logged as a warning.

With force=False the fan-out does what it actually can: queued tasks
(finalize / set_weight_version / try_put behind a wedged transport) are
cancelled and never start. A task already executing on the sync
cache_owner / rollout_manager actors still runs to completion — Ray
only sets a cooperative is_canceled() flag that miles does not poll —
so the R06-F1 comment is rewritten to describe the real, narrower
guarantee instead of claiming interruption.

Cooperative interruption of the executing run_sync_session (polling
is_canceled() in the bucket loop, or moving the service chain to an
async actor) is a follow-up design decision.

Test: tests/test_miles_service_cancel_inflight.py pins that every ref
reaches ray.cancel with force=False (the stub mirrors Ray's contract by
raising on force=True, which is exactly the pre-fix silent-no-op).
@JunzheJoe
JunzheJoe requested a review from taoluo July 19, 2026 01:53
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