Skip to content

guard: expose ml_load_error and test corrupt checkpoints (#191) - #209

Open
AaliyaKhan25 wants to merge 2 commits into
UnplugAI:devfrom
AaliyaKhan25:fix/191-corrupt-checkpoint
Open

AaliyaKhan25 wants to merge 2 commits into
UnplugAI:devfrom
AaliyaKhan25:fix/191-corrupt-checkpoint

Conversation

@AaliyaKhan25

Copy link
Copy Markdown
Contributor

Summary

Closes #191.

I could not reproduce ml_model_loaded being true for a corrupt checkpoint on current dev. Both tests named in the issue pass for me (torch 2.12, transformers 4.44.2, Python 3.12, Windows, empty model cache), and they also pass at the commit before #174. The part of the issue that does hold is that the real load error only reached a log line: the warning logs the exception class name, so a caller running with require_ml=False had no way to see why ML was off.

  • Guard.ml_load_error returns the exception that stopped the model loading, or None if it loaded or was never attempted.
  • The warning text is unchanged, since test_ml_degraded_warning.py pins it.
  • New tests feed a truncated checkpoint. With require_ml=False, they assert ml_model_loaded is False and that the error is exposed. With require_ml=True, they assert the ModelError carries the underlying cause.

Checklist

  • The issue this closes was assigned to me
  • This is my only open PR
  • Target branch is dev
  • cd sdk && make check-ci passes locally
  • New code has tests
  • Public API changes are reflected in sdk/README.md / docs/
  • No secrets, internal URLs, or private paths in the diff
  • If a model wrote a meaningful part of this, I said so below

Notes for reviewers

ml_load_error is new public API and overlaps with the degraded reporting in #107, so tell me if you want a different shape. It also keeps the exception's traceback alive for the Guard's lifetime. If you'd rather not, I can store repr(exc) instead.

I ran pytest on the two touched test files, plus ruff check, ruff format --check and mypy directly, because make isn't available on my Windows setup. I did not run the full make check-ci.

On Windows, test_require_ml_error_names_the_offending_path fails on unmodified dev. The message uses {path!r}, which doubles the backslashes, so str(bad) in str(exc) can't match. It's unrelated to this change, and Linux CI doesn't see it. I'm happy to send a separate fix once this is merged.

Drafted with AI assistance. I traced the load path and ran the repro and tests myself.

@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous finding is fixed and no new issues were found.

Summary

Adds Guard.ml_load_error so callers can inspect the exception that prevented ML from loading.

  • A Guard exposes the exception behind a failed ML model load.

Reviews (2) · Last reviewed commit: "tests: skip checkpoint tests when transf..." · Reviewed by Greptile

Comment thread sdk/tests/unit/ml/test_model_store.py Resolved
If torch is installed but transformers is not, model loading raises an
install-hint error before config.json is read. Both new checkpoint tests
would then fail on the filename assertion even though Guard behaves
correctly. Guard both with pytest.importorskip('transformers').

Fixes P2 raised in Greptile review.

This branch has not been deployed

No deployments
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.

ml_model_loaded is true for a corrupt checkpoint

1 participant