Skip to content

Preserve SageMaker job lifecycle states in trigger events - #71653

Merged
o-nikolas merged 2 commits into
apache:mainfrom
SameerMesiah97:SageMakerTrigger-Add-Run-Method
Sep 18, 2026
Merged

o-nikolas merged 2 commits into
apache:mainfrom
SameerMesiah97:SageMakerTrigger-Add-Run-Method

Conversation

@SameerMesiah97

@SameerMesiah97 SameerMesiah97 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

This change updates SageMakerTrigger to preserve SageMaker job lifecycle outcomes as explicit trigger event statuses.

The trigger now translates structured AWS waiter outcomes into failed, stopped, and timeout events, while successful jobs continue to emit success. Polling, retries, timeout detection, and AWS error handling remain managed by the shared AwsBaseWaiterTrigger implementation.

This is a follow-up to PR #69042 and the shared AWS waiter changes that allow individual triggers to translate waiter outcomes without reimplementing the polling lifecycle.

Rationale

SageMakerTrigger previously represented unsuccessful waiter outcomes using the generic error status, preventing consumers from distinguishing between a failed SageMaker job, an explicitly stopped job, and waiter exhaustion.

Using the exception-to-event translation provided by AwsBaseWaiterTrigger allows SageMakerTrigger to preserve these lifecycle states while continuing to rely on the shared AWS waiter implementation.

Tests

Added unit tests verifying that:

  • Failed and stopped SageMaker jobs are translated into failed and stopped events.
  • Failed jobs use the SageMaker failure reason when available.
  • Waiter exhaustion is translated into a timeout event.
  • Unrecognized terminal states and generic errors fall back to the default error event.

The stopped-job path was also manually validated against a real SageMaker training job by stopping the underlying job while the Airflow task was deferred.

Backwards Compatibility

This change does not modify the public API or constructor of SageMakerTrigger.

Successful jobs continue to emit success. Non-successful outcomes use more specific statuses instead of the generic error status. Existing SageMaker operators already treat any status other than success as a task failure, so their task-level behavior remains unchanged.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [GPT 5.6] following the guidelines

@boring-cyborg boring-cyborg Bot added area:providers provider:amazon AWS/Amazon - related issues labels Aug 15, 2026
@SameerMesiah97
SameerMesiah97 force-pushed the SageMakerTrigger-Add-Run-Method branch from bcde123 to da87d3f Compare August 16, 2026 16:38
@SameerMesiah97
SameerMesiah97 marked this pull request as ready for review August 16, 2026 18:52
@eladkal
eladkal requested a review from vincbeck August 17, 2026 20:08
@vincbeck

Copy link
Copy Markdown
Contributor

@seanghaeli @ramitkataria

@SameerMesiah97
SameerMesiah97 force-pushed the SageMakerTrigger-Add-Run-Method branch from da87d3f to 9e0ba2d Compare August 19, 2026 20:57
@SameerMesiah97

Copy link
Copy Markdown
Contributor Author

Requesting review for this.

@o-nikolas o-nikolas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we really need to be careful when moving away from very well tested and delicate code that all Triggers share (async_wait) in this case and trying to re-implement it. I know you have good intentions and are trying to provide more information after the Trigger returns, but you're opening yourself up to a lot of new code to maintain (and almost duplicate) as well as all the bugs and edge cases that come along with that.

@SameerMesiah97

Copy link
Copy Markdown
Contributor Author

I think we really need to be careful when moving away from very well tested and delicate code that all Triggers share (async_wait) in this case and trying to re-implement it. I know you have good intentions and are trying to provide more information after the Trigger returns, but you're opening yourself up to a lot of new code to maintain (and almost duplicate) as well as all the bugs and edge cases that come along with that.

After reading your comment, I have realized the core issue is not with the SageMakerTrigger but AwsBaseWaiterTrigger flattening the waiter outcome into success / error, so SageMakerTrigger can't preserve states like Failed and Stopped without taking over the polling loop.

What are your thoughts on adding a overridable translation method i.e. _event_from_exception to AwsBaseWaiterTrigger, which the SageMakerTrigger uses to surface more granular TriggerEvent payloads? I believe this should preserve centralizied handling of ThrottlingError, the polling loop, timeouts etc whilst keeping the state machine for this trigger (and any other AWS trigger) explicit.

@SameerMesiah97
SameerMesiah97 marked this pull request as draft September 2, 2026 16:14
@o-nikolas

Copy link
Copy Markdown
Contributor

I think we really need to be careful when moving away from very well tested and delicate code that all Triggers share (async_wait) in this case and trying to re-implement it. I know you have good intentions and are trying to provide more information after the Trigger returns, but you're opening yourself up to a lot of new code to maintain (and almost duplicate) as well as all the bugs and edge cases that come along with that.

After reading your comment, I have realized the core issue is not with the SageMakerTrigger but AwsBaseWaiterTrigger flattening the waiter outcome into success / error, so SageMakerTrigger can't preserve states like Failed and Stopped without taking over the polling loop.

What are your thoughts on adding a overridable translation method i.e. _event_from_exception to AwsBaseWaiterTrigger, which the SageMakerTrigger uses to surface more granular TriggerEvent payloads? I believe this should preserve centralizied handling of ThrottlingError, the polling loop, timeouts etc whilst keeping the state machine for this trigger (and any other AWS trigger) explicit.

Yupp, I think this is the right approach, a generalized one. CC @ramitkataria @vincbeck

@SameerMesiah97
SameerMesiah97 deleted the SageMakerTrigger-Add-Run-Method branch September 10, 2026 17:37
@SameerMesiah97
SameerMesiah97 restored the SageMakerTrigger-Add-Run-Method branch September 10, 2026 17:37
@SameerMesiah97
SameerMesiah97 force-pushed the SageMakerTrigger-Add-Run-Method branch from 9e0ba2d to 071c4ec Compare September 10, 2026 18:38
@SameerMesiah97 SameerMesiah97 changed the title Expand SageMakerTrigger to preserve job lifecycle states Preserve SageMaker job lifecycle states in trigger events Sep 10, 2026
@SameerMesiah97
SameerMesiah97 marked this pull request as ready for review September 10, 2026 20:08
@SameerMesiah97

Copy link
Copy Markdown
Contributor Author

I think we really need to be careful when moving away from very well tested and delicate code that all Triggers share (async_wait) in this case and trying to re-implement it. I know you have good intentions and are trying to provide more information after the Trigger returns, but you're opening yourself up to a lot of new code to maintain (and almost duplicate) as well as all the bugs and edge cases that come along with that.

After reading your comment, I have realized the core issue is not with the SageMakerTrigger but AwsBaseWaiterTrigger flattening the waiter outcome into success / error, so SageMakerTrigger can't preserve states like Failed and Stopped without taking over the polling loop.
What are your thoughts on adding a overridable translation method i.e. _event_from_exception to AwsBaseWaiterTrigger, which the SageMakerTrigger uses to surface more granular TriggerEvent payloads? I believe this should preserve centralizied handling of ThrottlingError, the polling loop, timeouts etc whilst keeping the state machine for this trigger (and any other AWS trigger) explicit.

Yupp, I think this is the right approach, a generalized one. CC @ramitkataria @vincbeck

I opened PR #72455 to add the overridable translation method i.e. _event_from_exception to AwsBaseWaiterTrigger which just got merged very recently. This PR now only overrides that method via its own implementation for SageMakerTrigger. Everything else is being handled by the shared AWS abstraction.

@ramitkataria ramitkataria left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a minor nit inline but otherwise looks good

Sameer Mesiah added 2 commits September 16, 2026 15:36
…structured AWS waiter outcomes into failed, stopped, and timed-out SageMaker trigger events while retaining the shared waiter lifecycle handling. Add unit tests for the SageMaker-specific event translation.
@SameerMesiah97
SameerMesiah97 force-pushed the SageMakerTrigger-Add-Run-Method branch from 071c4ec to 2a47ed5 Compare September 16, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants