Skip to content

feat: opt-in static schema gen with legacy runtime fallback#2800

Merged
markphelps merged 7 commits intofix/dict-list-output-schemafrom
fix/dict-list-output-schema-legacy-fallback
Mar 4, 2026
Merged

feat: opt-in static schema gen with legacy runtime fallback#2800
markphelps merged 7 commits intofix/dict-list-output-schemafrom
fix/dict-list-output-schema-legacy-fallback

Conversation

@markphelps
Copy link
Contributor

Summary

  • Gate static schema generation behind COG_STATIC_SCHEMA=1 env var for cog build (legacy runtime path remains default)
  • Static gen always enabled for cog train/cog serve/cog predict (skipLabels paths) since CLI needs schema for -i flag parsing
  • Automatic fallback to legacy runtime path when static gen fails with ErrUnresolvableType
  • Restore Python SDK modules (_adt.py, _inspector.py, _schemas.py, command/openapi_schema.py) required by legacy fallback
  • Add pydantic v2 BaseModel support in legacy _inspector.py
  • Update architecture docs for dual-path model

The static Go tree-sitter schema generator was the default for SDK >= 0.17.0,
which risks breaking builds when the parser encounters types it cannot resolve.

- Gate static schema gen behind COG_STATIC_SCHEMA=1 (or "true") env var
- Legacy runtime schema generation (boot container + python introspection)
  remains the default
- When opted in, gracefully fall back to legacy on ErrUnresolvableType
  instead of hard-failing the build
- Add unit tests for canUseStaticSchemaGen (12 table-driven cases)
- Add integration test for the static->legacy fallback path
- Update existing static/multi-file integration tests to set the env var
Reflect that static schema generation is opt-in via COG_STATIC_SCHEMA=1,
with legacy runtime path as the default and automatic fallback.
Restore the Python modules needed by the legacy runtime schema generation
path (python -m cog.command.openapi_schema). These were deleted in 61eedf3
but are needed as the fallback when the static Go parser encounters types
it cannot resolve.

Restored modules: _adt, _inspector, _schemas, coder, config, errors, mode,
suppress_output, command/__init__, command/openapi_schema.

config.py is trimmed to only what openapi_schema.py needs (removed
get_predictor_types which depended on deleted get_predict/get_train).
…r train/serve

Remove the skipLabels override that forced static schema gen for
cog train/serve paths. Now useStatic is purely opt-in via
COG_STATIC_SCHEMA=1 for all commands.

For train/serve without the env var, no schema is generated at
build time. Coglet gracefully handles this (warns and accepts all
input). These are local-only images that don't need strict schema
validation.

Also improves the static_schema_fallback integration test to use
a realistic mypackage/__init__.py scenario instead of a plain class.
…legacy inspector

Two IT failures:

1. training_setup: cog train needs schema for -i flag parsing. The CLI
   fetches it from coglet's /openapi.json, which returns 503 when no
   schema file exists. Re-enable static gen for skipLabels paths (same
   as main) since there's no post-build legacy fallback for these.

2. pydantic2_output: the legacy runtime inspector (_inspector.py) didn't
   handle pydantic v2 BaseModel as output types — only cog.BaseModel.
   Add conditional pydantic.BaseModel check with model_fields iteration.
@markphelps markphelps requested a review from a team as a code owner March 3, 2026 21:54
@markphelps markphelps force-pushed the fix/dict-list-output-schema-legacy-fallback branch from c52fc0c to 3d869b7 Compare March 3, 2026 22:04
@markphelps markphelps requested a review from michaeldwan March 4, 2026 16:08
Copy link
Member

@michaeldwan michaeldwan left a comment

Choose a reason for hiding this comment

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

lgtm

@markphelps markphelps merged commit 103fa07 into fix/dict-list-output-schema Mar 4, 2026
32 checks passed
@markphelps markphelps deleted the fix/dict-list-output-schema-legacy-fallback branch March 4, 2026 18:03
michaeldwan pushed a commit that referenced this pull request Mar 5, 2026
* fix: make static schema generation opt-in via COG_STATIC_SCHEMA env var

The static Go tree-sitter schema generator was the default for SDK >= 0.17.0,
which risks breaking builds when the parser encounters types it cannot resolve.

- Gate static schema gen behind COG_STATIC_SCHEMA=1 (or "true") env var
- Legacy runtime schema generation (boot container + python introspection)
  remains the default
- When opted in, gracefully fall back to legacy on ErrUnresolvableType
  instead of hard-failing the build
- Add unit tests for canUseStaticSchemaGen (12 table-driven cases)
- Add integration test for the static->legacy fallback path
- Update existing static/multi-file integration tests to set the env var

* docs: update schema architecture doc for opt-in static generation model

Reflect that static schema generation is opt-in via COG_STATIC_SCHEMA=1,
with legacy runtime path as the default and automatic fallback.

* fix: restore legacy runtime schema generation modules for fallback path

Restore the Python modules needed by the legacy runtime schema generation
path (python -m cog.command.openapi_schema). These were deleted in 61eedf3
but are needed as the fallback when the static Go parser encounters types
it cannot resolve.

Restored modules: _adt, _inspector, _schemas, coder, config, errors, mode,
suppress_output, command/__init__, command/openapi_schema.

config.py is trimmed to only what openapi_schema.py needs (removed
get_predictor_types which depended on deleted get_predict/get_train).

* fix: simplify schema gen gating — let coglet handle missing schema for train/serve

Remove the skipLabels override that forced static schema gen for
cog train/serve paths. Now useStatic is purely opt-in via
COG_STATIC_SCHEMA=1 for all commands.

For train/serve without the env var, no schema is generated at
build time. Coglet gracefully handles this (warns and accepts all
input). These are local-only images that don't need strict schema
validation.

Also improves the static_schema_fallback integration test to use
a realistic mypackage/__init__.py scenario instead of a plain class.

* fix: restore static gen for train/serve paths, handle pydantic v2 in legacy inspector

Two IT failures:

1. training_setup: cog train needs schema for -i flag parsing. The CLI
   fetches it from coglet's /openapi.json, which returns 503 when no
   schema file exists. Re-enable static gen for skipLabels paths (same
   as main) since there's no post-build legacy fallback for these.

2. pydantic2_output: the legacy runtime inspector (_inspector.py) didn't
   handle pydantic v2 BaseModel as output types — only cog.BaseModel.
   Add conditional pydantic.BaseModel check with model_fields iteration.

* fix: suppress pyright reportMissingImports for optional pydantic import

* fix: flatten nested error handling to early returns, case-insensitive env var check
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