Skip to content

fix: add ExperimentalFeatureWarning compat shim#2789

Merged
tempusfrangit merged 4 commits intomainfrom
fix/experimental-feature-warning-compat
Mar 2, 2026
Merged

fix: add ExperimentalFeatureWarning compat shim#2789
tempusfrangit merged 4 commits intomainfrom
fix/experimental-feature-warning-compat

Conversation

@tempusfrangit
Copy link
Member

Summary

Existing models import ExperimentalFeatureWarning from cog to suppress experimental feature warnings. This was removed when the Python HTTP server was replaced by coglet (#2783), breaking those models at import time with ImportError.

What Changed

Added a backwards-compatible shim in python/cog/__init__.py that:

  • Provides ExperimentalFeatureWarning via module __getattr__ (lazy — only triggers when actually imported)
  • Prints a deprecation notice directly to stderr — cannot be swallowed by warnings.filterwarnings("ignore") or any other warnings suppression
  • The class is a real FutureWarning subclass, so existing warnings.filterwarnings("ignore", category=ExperimentalFeatureWarning) calls work syntactically
  • Will be removed in a future release

Models affected

Any model that does:

from cog import ExperimentalFeatureWarning
warnings.filterwarnings("ignore", category=ExperimentalFeatureWarning)

Including cog-examples/hello-concurrency, cog-examples/hello-context, cog-examples/hello-replicate.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a backwards-compatible ExperimentalFeatureWarning export to the Python cog SDK so older models that import it (to suppress warnings) don’t fail with ImportError after the coglet migration.

Changes:

  • Introduces a lazy ExperimentalFeatureWarning compat shim via module-level __getattr__.
  • Emits a deprecation notice directly to stderr when the deprecated symbol is accessed.
  • Exposes the deprecated symbol via __all__.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tempusfrangit tempusfrangit force-pushed the fix/experimental-feature-warning-compat branch from ff8b338 to f3156b0 Compare February 28, 2026 18:37
@tempusfrangit tempusfrangit enabled auto-merge (rebase) March 1, 2026 06:44
Existing models import ExperimentalFeatureWarning to suppress warnings:

    from cog import ExperimentalFeatureWarning
    warnings.filterwarnings('ignore', category=ExperimentalFeatureWarning)

This class was removed when the Python HTTP server was replaced by
coglet, causing ImportError on model load.

The shim provides _ExperimentalFeatureWarning (a FutureWarning subclass)
via module-level __getattr__, which:
- Prints a deprecation notice to stderr (cannot be swallowed by
  warnings.filterwarnings('ignore'))
- Caches in globals() so the message fires at most once
- Returns the class so existing filterwarnings() calls still work
Add Python unit tests verifying the __getattr__ compat shim works:
import succeeds, deprecation prints to stderr once, is FutureWarning
subclass, works with warnings.filterwarnings, unknown attrs raise.

Add txtar integration test proving a predictor importing
ExperimentalFeatureWarning builds and runs end-to-end.

Also fix coglet wheel build/test workflow:
- noxfile: fail loudly when dist/ has wheels but none match platform
  (was silently falling back to PyPI or installing wrong-platform wheel)
- noxfile: always use editable install for SDK so tests run against
  working tree
- mise.toml: remove sources/outputs caching from build:coglet:wheel
  (the broad glob falsely matched cross-compiled wheels, causing skips)
- mise.toml: test:python depends on build:coglet:wheel so dist/ always
  has a native wheel
@tempusfrangit tempusfrangit force-pushed the fix/experimental-feature-warning-compat branch from f3156b0 to 5fa03f4 Compare March 2, 2026 18:15
@tempusfrangit tempusfrangit requested a review from markphelps March 2, 2026 18:20
Editable install fails in CI because setuptools_scm needs a full git
checkout. Use the pre-built wheel from dist/ when available, fall back
to editable install only for local dev.
Copy link
Contributor

@meatballhat-cf meatballhat-cf left a comment

Choose a reason for hiding this comment

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

Looks like we got some wheel-related fixes along the way, which is 🎉 but also it would be nice for future selves if the PR description mentioned it.

return self.model.generate(prompt, image)
"""

import sys as _sys
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the _sys alias? To work around libraries that runtime patch stderr?

# Metrics
"current_scope",
# Deprecated compat shims
"ExperimentalFeatureWarning",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think ExperimentalFeatureWarning should not be in the __all__ since it's not supposed to be part of the public API. I found maybe one legit case of from cog import * in GitHub, so I think we can safely say the backward compatibility only applies to named access.

@tempusfrangit tempusfrangit merged commit 9616e8d into main Mar 2, 2026
37 checks passed
@tempusfrangit tempusfrangit deleted the fix/experimental-feature-warning-compat branch March 2, 2026 22:34
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.

4 participants