Skip to content

fix(train): raise on expired credentials in show_metrics log fetch - #6114

Open
skamal23 wants to merge 2 commits into
aws:master-nova-follow-upsfrom
skamal23:fix/show-metrics-expired-credentials
Open

fix(train): raise on expired credentials in show_metrics log fetch#6114
skamal23 wants to merge 2 commits into
aws:master-nova-follow-upsfrom
skamal23:fix/show-metrics-expired-credentials

Conversation

@skamal23

@skamal23 skamal23 commented Jul 28, 2026

Copy link
Copy Markdown

When AWS credentials expire, show_metrics() reported "No CloudWatch logs found for job ''. The job may still be starting, or logs may not be available yet", sending users to debug their training job instead of refreshing credentials.

_fetch_smtj_logs() and _fetch_smhp_logs() each wrapped their CloudWatch Logs call in a bare except Exception, logged a warning, and returned an empty list, so an ExpiredTokenException was indistinguishable from a job that genuinely has no logs yet. The empty list then became the misleading ValueError above.

Changes:

  • cloudwatch_metrics.py: add _AUTH_ERROR_CODES and _raise_if_auth_error(); apply at describe_log_streams, get_log_events, and filter_log_events; narrow except Exception to except ClientError
  • base_trainer.py: document PermissionError on show_metrics()
  • test_cloudwatch_metrics.py: 20 unit tests covering all 7 auth codes on both platforms, ResourceNotFoundException degradation, mid-pagination failure, and a regression guard for the existing "no logs found" path

{"message": "global_step: 2 train_rm_score: 0.72"},
]

AUTH_ERROR_CODES = [

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.

Can we have a common constants in sagemaker-train/src/sagemaker/train/common_utils/constants.py so that they're reusable in both test and src files ? Otherwise, we need to maintain two lists for test coverage

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good call, moved it. Also rebased onto latest master-nova-follow-ups

sayemkam added 2 commits July 28, 2026 18:26
When AWS credentials expire, show_metrics() reported "No CloudWatch logs
found for job '<name>'. The job may still be starting, or logs may not be
available yet", sending users to debug their training job instead of
refreshing credentials.

_fetch_smtj_logs() and _fetch_smhp_logs() each wrapped their CloudWatch
Logs call in a bare `except Exception`, logged a warning, and returned an
empty list, so an ExpiredTokenException was indistinguishable from a job
that genuinely has no logs yet. The empty list then became the misleading
ValueError above.

Design follows the existing notifications.py pattern: read the structured
error code, re-raise the auth subset as PermissionError with remediation
guidance, and let every other code keep its current degrade-to-empty
behavior. A genuinely absent log group (ResourceNotFoundException) still
returns an empty list, so a just-started job continues to raise the
existing "No CloudWatch logs found" ValueError.

Changes:
- cloudwatch_metrics.py: add _AUTH_ERROR_CODES and _raise_if_auth_error();
  apply at describe_log_streams, get_log_events, and filter_log_events;
  narrow `except Exception` to `except ClientError`
- base_trainer.py: document PermissionError on show_metrics()
- test_cloudwatch_metrics.py: 20 unit tests covering all 7 auth codes on
  both platforms, ResourceNotFoundException degradation, mid-pagination
  failure, and a regression guard for the existing "no logs found" path
Addresses review feedback: the auth error-code list was duplicated in
cloudwatch_metrics.py and its unit test, so the two lists had to be kept in
sync manually.

Move it to the existing common_utils/constants.py as a module-level
frozenset and import it in both places. Test parametrization sorts the
frozenset so test IDs stay deterministic.
@skamal23
skamal23 force-pushed the fix/show-metrics-expired-credentials branch from ba5c09c to 6e2b58e Compare July 28, 2026 18:35
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.

2 participants