Skip to content

feat: move input coercion & output encoding to Rust, delete dead SDK modules#2783

Merged
tempusfrangit merged 5 commits intomainfrom
feat/rust-coercion-sdk-trim
Feb 27, 2026
Merged

feat: move input coercion & output encoding to Rust, delete dead SDK modules#2783
tempusfrangit merged 5 commits intomainfrom
feat/rust-coercion-sdk-trim

Conversation

@tempusfrangit
Copy link
Member

Summary

  • Move input coercion and output encoding from Python to Rust in coglet-python, eliminating runtime calls to _adt.py and _inspector.py
  • Delete 20 dead Python SDK modules (-3,071 lines) whose functionality now lives in Rust coglet
  • Simplify remaining SDK to a thin surface: BasePredictor, Input, types, and BaseModel

Commit 1: Rust coercion (input.rs, output.rs, predictor.rs)

input.rs — Replaced Runtime/InputProcessor/CogInputProcessor architecture with prepare_input(py, input, func):

  • detect_file_fields() — introspects type annotations for cog.File/cog.Path params (handles Optional, list[File], Union[File, None])
  • coerce_url_strings() — converts URL strings to Path.validate() or File.validate() based on annotations
  • download_url_paths_into_dict() — parallel URLPath downloads via ThreadPoolExecutor
    output.rs — Pure Rust output processing replacing cog.json.make_encodeable() + cog.files.upload_file():
  • make_encodeable() — handles Pydantic v1/v2, dataclasses, enums, datetime, numpy, PathLike, collections
  • encode_files() — recursive Path/IOBase → base64 data URL conversion
  • file_to_base64() — MIME type guessing, seek-to-start, base64 encoding
    predictor.rs — Removed runtime/input_processor fields:
  • predict_func()/train_func() — getters for type annotation introspection
  • unwrap_field_info_defaults() — patches __defaults__/__kwdefaults__ to replace FieldInfo(default=42) wrappers with actual values

Commit 2: SDK cleanup

Deleted modules: _adt, _inspector, _schemas, coder, coders/*, command/*, config, errors, exceptions, files, json, logging, mode, schema, suppress_output
Simplified:

  • input.py — removed Representation, mutable default auto-conversion; default_factory now raises TypeError
  • predictor.py — removed get_predict/get_train/wait_for_env/get_healthcheck
  • server/http.py — reads predictor ref from COG_PREDICT_TYPE_STUB/COG_TRAIN_TYPE_STUB env vars, removed structlog/config
  • types.py — removed ExperimentalFeatureWarning
  • __init__.py — removed Coder imports, CancelationException now from coglet

Testing

  • All Rust tests pass (150 total, 6 #[ignore] — require cog in PYTHONPATH)
  • Python lint, typecheck (pyright), formatting all pass
  • Clippy clean

@tempusfrangit tempusfrangit requested a review from a team as a code owner February 27, 2026 21:55
@tempusfrangit tempusfrangit added this to the 0.17.0 Release milestone Feb 27, 2026
Base automatically changed from feat/go-schema-gen to main February 27, 2026 22:15
…adt/_inspector

Replace the Python-side input validation (_inspector.check_input) and output
encoding (cog.json/cog.files) with pure Rust implementations in coglet-python:

input.rs:
- Remove Runtime/InputProcessor/CogInputProcessor architecture
- Add prepare_input() with detect_file_fields() for File vs Path annotation
  introspection and coerce_url_strings() for URL->Path/File conversion
- Input validation now happens at HTTP edge (InputValidator); worker only
  does URL coercion and file downloads

output.rs:
- Pure Rust make_encodeable() handles Pydantic models, dataclasses, enums,
  datetime, numpy types, and collections
- Pure Rust encode_files() converts Path/IOBase to base64 data URLs
- No longer calls cog.json.make_encodeable or cog.files.upload_file

predictor.rs:
- Remove runtime/input_processor fields
- Add predict_func()/train_func() getters for type annotation introspection
- Add unwrap_field_info_defaults() to patch FieldInfo wrapper objects in
  __defaults__/__kwdefaults__ so Python resolves actual default values
- Use input::prepare_input(py, dict, &func) directly
Remove 20 Python files (-3,071 lines) whose functionality has moved to
Rust in coglet-python (input coercion, output encoding, schema generation,
file uploads, logging, config parsing).

Deleted modules:
  _adt, _inspector, _schemas, coder, coders/*, command/*,
  config, errors, exceptions, files, json, logging, mode,
  schema, suppress_output

Simplified:
  - input.py: remove Representation base, mutable default auto-conversion,
    default_factory support (now raises TypeError)
  - predictor.py: remove get_predict/get_train/wait_for_env/get_healthcheck
  - server/http.py: read predictor ref from env vars instead of cog.yaml,
    remove structlog/logging setup
  - types.py: remove ExperimentalFeatureWarning
  - __init__.py: remove Coder imports, import CancelationException from coglet
  - test_input.py, test_model.py: updated for new behavior
@tempusfrangit tempusfrangit force-pushed the feat/rust-coercion-sdk-trim branch from 1f89033 to 5560081 Compare February 27, 2026 22:17
tempusfrangit and others added 2 commits February 27, 2026 14:38
Co-authored-by: Mark Phelps <[email protected]>
Signed-off-by: Morgan Fainberg <[email protected]>
… file_to_base64)

Cover primitives, collections, enums, datetime, dataclasses, generators,
nested structures, PathLike->base64, IOBase->base64, MIME guessing,
seek-to-start, dict/list recursion, and end-to-end process_output.

All tests use stdlib Python only (no cog import needed).
Copy link
Contributor

@markphelps markphelps left a comment

Choose a reason for hiding this comment

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

i dig it. good stuff

@tempusfrangit tempusfrangit merged commit 61eedf3 into main Feb 27, 2026
36 checks passed
@tempusfrangit tempusfrangit deleted the feat/rust-coercion-sdk-trim branch February 27, 2026 23:00
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