Skip to content

pydantic app-server type generation#14124

Closed
sdcoffey wants to merge 10 commits intomainfrom
dev/steve/pydantic-generation
Closed

pydantic app-server type generation#14124
sdcoffey wants to merge 10 commits intomainfrom
dev/steve/pydantic-generation

Conversation

@sdcoffey
Copy link
Copy Markdown
Contributor

@sdcoffey sdcoffey commented Mar 9, 2026

Summary

Note to reviewer: 80% of the diff is generated pydantic types

This PR adds Python/Pydantic code generation for the app-server protocol in codex-rs/app-server-protocol, using the existing JSON Schema export layer rather than introducing new Rust derive macros. The goal is to make the Rust protocol types the single source of truth while generating Python bindings that stay aligned with the existing TypeScript and JSON schema artifacts.

The implementation is intentionally scoped to code generation only. It does not include PyPI packaging or release automation.

What Changed

The protocol exporter now generates Python bindings alongside the existing TypeScript and JSON outputs. A new codex app-server generate-python CLI subcommand was added, and schema fixture regeneration now vendors Python output under schema/python/.

The generated Python package preserves the existing protocol split:

  • root/shared models live in codex_app_server_protocol.models
  • v2-specific models live in codex_app_server_protocol.v2.models

To improve readability of the generated Python, the exporter now enables title-based naming in datamodel-code-generator. On top of that, Python-only schema title rewrites are applied for request/notification envelope wrappers so they generate stable names like ItemStartedServerNotification instead of collision-driven suffixes such as ItemStartedNotification1.

The generated base model is also patched to use populate_by_name=True, which keeps aliased fields such as _meta working correctly in Pydantic.

Design Notes

This PR deliberately keeps Python concerns in the export layer rather than pushing them into Rust protocol derives. That avoids coupling the Rust model definitions to Python packaging or Pydantic-specific behavior and keeps ts-rs focused on TypeScript.

A generic schema-to-Pydantic generator is still being used under the hood, so this approach is best viewed as a pragmatic codegen path rather than a formal compatibility proof. The exporter now does additional shaping of the Python input schema to preserve version boundaries and improve generated names, which gets us much closer to a usable generated API without introducing a separate custom emitter.

Validation

  • Regenerated vendored schema fixtures, including Python output
  • Ran cargo test -p codex-app-server-protocol
  • Ran just fix -p codex-app-server-protocol
  • Ran just fmt

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 9, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00bd65ae79

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/app-server-protocol/src/export.rs Outdated
@sdcoffey
Copy link
Copy Markdown
Contributor Author

sdcoffey commented Mar 9, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Mar 10, 2026
@sdcoffey sdcoffey force-pushed the dev/steve/pydantic-generation branch from 3f8c27f to 216013b Compare March 10, 2026 02:57
@sdcoffey sdcoffey requested a review from pakrym-oai March 10, 2026 04:07
@sdcoffey
Copy link
Copy Markdown
Contributor Author

closing for #14232

@sdcoffey sdcoffey closed this Mar 10, 2026
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.

1 participant