Cancel the Code Engine job when a Fleets job times out - #2478
Merged
Conversation
Elena Peña Tapia (ElePT)
approved these changes
Sep 10, 2026
Elena Peña Tapia (ElePT)
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for looking into this, also LGTM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a Fleets job goes past
PROGRAM_TIMEOUT,stop_job_if_timeoutwritesSTOPPEDon the row but never asks Code Engine to cancel anything. The fleet keeps running, and since nothing else looks at a job that is already in a terminal status, nothing ever cleans it up. This adds the missingrunner.stop()call before the status is written.Details and comments
The timeout is the one path that decides to stop a job on its own, without Code Engine having reported a terminal state first. The other branches of
update_job_statusreachto_terminalbecause the task store already says the job succeeded, failed or was cancelled, so there is genuinely nothing left to cancel there. The timeout branch fires while the fleet is very likely still running, or while its state is unknown because the status poll returned nothing or raised.If the cancel fails, the error is logged and the row still moves to
STOPPED. Leaving it in a running status instead would keep it holding the user's concurrency slot for as long as Code Engine stays unreachable, which is the problem the timeout exists to bound.Ray is not affected. Its timeout path has the same shape, but
FreeResourcesdeletes theRayClusterfor any job in a terminal status, so the teardown happens regardless of whetherstop()was called. Fleets has no equivalent task.Worth knowing for reviewers: a follow-up will replace this single write with a two-phase transition, where a stop request moves the job to a new
STOPPINGstatus and a later poll confirms the realSTOPPED. That work changes what this branch writes, not whether the cancel happens, so landing this first is still a strict improvement over today.Closes https://github.ibm.com/IBM-Q-Software/qiskit-serverless/issues/1831