Skip to content

feat(bridges): unify outbound BamlTy onto baml_type.proto Ty - #3830

Merged
sxlijin merged 1 commit into
canaryfrom
sam/generic2
Jun 23, 2026
Merged

sxlijin merged 1 commit into
canaryfrom
sam/generic2

Conversation

@sxlijin

@sxlijin sxlijin commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Consolidates the two on-the-wire "a BAML type" encodings in bridge_ctypes onto a single representation. BamlTy (baml_outbound.proto) was an older, lossy type-metadata encoding riding alongside outbound container values; Ty (baml_type.proto) is the faithful, complete mirror of baml_type::RuntimeTy already used inbound. This collapses the two parallel per-SDK mappings (native→Ty writing, BamlTy→native reading) into one per SDK.

Implements 02a-unify-bamlty-and-ty.md.

Main change

  • New ty_encode.rs: runtime_ty_to_proto_ty(&RuntimeTy) -> Ty — the total inverse of ty_decode.rs (all 24 variants), strictly more capable than the old ty_to_field_type (which collapsed many variants to unknown/unreachable!). Also wires the previously-dead outbound ty_value (field 21) for BexExternalAdt::Type.
  • Repoint the four embed sites (BamlValueList.item_type, BamlValueMap.key_type/value_type, BamlValueUnionVariant.self_type, BamlTyGenericArg.ty) from BamlTy → Ty; drop ty_to_field_type.
  • Unions encode structurally: nullable-single → Optional, else Ty::Union (mirrors the inbound writer). Type-position host readers map a structural union to a wildcard (§5).
  • Migrate SDK type-position readers: Python _ty_to_python_type and Node outboundTyToBamlType now consume Ty — the literal inverse of their inbound writers; the any_type branch is gone. Go has no type-position reader (only value-level BamlTyLiteral, retained) → regen only.
  • Delete the BamlTy message tree + BamlTyAny. Kept BamlTyLiteral/BamlLiteral* (they back the value-level BamlOutboundValue.literal_value) and BamlTyName/BamlTyGenericArg (now carrying Ty).

Side quest (§7)

Extract BamlHandleType + BamlHandle into baml_handle.proto so baml_outbound.proto imports it directly, dropping the outbound→inbound proto dependency edge. Python/TS2 import repoints; Rust/Node/Go regen-only.

All five proto clients regenerated.

Verification

  • Rust: bridge_ctypes builds + 30 unit tests pass; bridge_python/bridge_cffi/bridge_wasm/baml_lsp_server cargo-check clean.
  • Python: generics parity suite migrated to the Ty shape, all pass (4 unrelated failures confirmed pre-existing on canary).
  • Node: 110 integration tests pass (native build, full engine + generic $types round-trip); TS typechecks.
  • TS2: typecheck clean + 23 tests pass (fixtures migrated to the Ty $case shape).
  • Go: regen correct (pre-existing unrelated HostCallableError breakage untouched).

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added runtime-to-protobuf type metadata encoding for consistent outbound wire types.
    • Introduced shared CFFI handle protobuf definitions used by inbound/outbound messages.
  • Refactor

    • Updated SDK wire encoding/decoding to use the new BamlTy type representation for primitives, containers, optionals/unions, and generic arguments.
    • Reshaped class/enum/union and handle metadata; updated literal payloads to the new literal_value format.
  • Bug Fixes

    • Improved union/self-type and typed-handle handling, and aligned literal decoding (including bigint/float) with the new schema.
  • Chores

    • Regenerated Go/Python/TypeScript bindings and updated associated tests/fixtures.

@vercel

vercel Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jun 23, 2026 10:22pm
promptfiddle Ready Ready Preview, Comment Jun 23, 2026 10:22pm
promptfiddle2 Ready Ready Preview, Comment Jun 23, 2026 10:22pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 887b3562-7dea-4933-9d2a-874b9d96889d

📥 Commits

Reviewing files that changed from the base of the PR and between b3a0101 and 04c201f.

⛔ Files ignored due to path filters (14)
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_handle.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_inbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_outbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_type.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.js.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (38)
  • baml_language/crates/bridge_cffi/src/ffi/host_value.rs
  • baml_language/crates/bridge_ctypes/src/lib.rs
  • baml_language/crates/bridge_ctypes/src/ty_decode.rs
  • baml_language/crates/bridge_ctypes/src/ty_encode.rs
  • baml_language/crates/bridge_ctypes/src/value_decode.rs
  • baml_language/crates/bridge_ctypes/src/value_encode.rs
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_handle.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_inbound.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_outbound.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_type.proto
  • baml_language/crates/bridge_ctypes/types/buf.yaml
  • baml_language/crates/bridge_wasm/tests/host_callable.rs
  • baml_language/sdks/go/bridge_go/build.sh
  • baml_language/sdks/go/bridge_go/pkg/proto.go
  • baml_language/sdks/nodejs/bridge_nodejs/tests/test_decode_call_result.test.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/define_function.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.d.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/wire_ty.ts
  • baml_language/sdks/python/rust/bridge_python/src/host_value.rs
  • baml_language/sdks/python/src/baml_core/__init__.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.pyi
  • baml_language/sdks/python/src/baml_core/proto.py
  • baml_language/sdks/python/tests/test_decode_handle.py
  • baml_language/sdks/python/tests/test_host_callable.py
  • baml_language/sdks/python/tests/test_proto_decode_typemap.py
  • baml_language/sdks/python/tests/test_proto_generics.py
  • typescript2/pkg-proto/src/decode.ts
  • typescript2/pkg-proto/src/encode.ts
  • typescript2/pkg-proto/src/test/encode-decode.test.ts
✅ Files skipped from review due to trivial changes (10)
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.py
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/define_function.ts
  • baml_language/crates/bridge_ctypes/types/buf.yaml
  • baml_language/sdks/python/tests/test_host_callable.py
  • baml_language/sdks/python/src/baml_core/init.py
  • baml_language/sdks/nodejs/bridge_nodejs/tests/test_decode_call_result.test.ts
  • baml_language/sdks/python/tests/test_decode_handle.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.py
🚧 Files skipped from review as they are similar to previous changes (25)
  • baml_language/sdks/python/tests/test_proto_decode_typemap.py
  • baml_language/sdks/go/bridge_go/build.sh
  • baml_language/crates/bridge_cffi/src/ffi/host_value.rs
  • baml_language/crates/bridge_ctypes/src/lib.rs
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_handle.proto
  • baml_language/crates/bridge_wasm/tests/host_callable.rs
  • baml_language/sdks/go/bridge_go/pkg/proto.go
  • baml_language/sdks/python/rust/bridge_python/src/host_value.rs
  • baml_language/crates/bridge_ctypes/src/value_decode.rs
  • typescript2/pkg-proto/src/encode.ts
  • typescript2/pkg-proto/src/decode.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto.ts
  • baml_language/crates/bridge_ctypes/src/ty_encode.rs
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_inbound.proto
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.py
  • baml_language/crates/bridge_ctypes/src/ty_decode.rs
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.pyi
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/wire_ty.ts
  • baml_language/sdks/python/tests/test_proto_generics.py
  • baml_language/crates/bridge_ctypes/src/value_encode.rs
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_type.proto
  • typescript2/pkg-proto/src/test/encode-decode.test.ts
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/proto.py

📝 Walkthrough

Walkthrough

Unifies the CFFI wire type schema by renaming Ty/TyPrimitiveKind to BamlTy/BamlTyPrimitiveKind in baml_type.proto, removing the duplicate type-metadata BamlTy tree from baml_outbound.proto, extracting BamlHandleType/BamlHandle into a dedicated baml_handle.proto, adding a Rust ty_encode module to encode RuntimeTy to wire BamlTy, and propagating the unified wire representation through all SDK layers (Rust, Python, TypeScript, Node.js, Go).

Changes

BamlTy Schema Unification and Encoding

Layer / File(s) Summary
Proto schema: handle extraction, BamlTy migration, type field updates
baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_handle.proto, baml_inbound.proto, baml_outbound.proto, baml_type.proto, types/buf.yaml, sdks/go/bridge_go/build.sh
Introduces baml_handle.proto with BamlHandleType enum and BamlHandle message; baml_inbound.proto removes inline definitions and imports the new file. Updates all type references across inbound/outbound protos from Ty/TyArg/TyClass to BamlTy/BamlTyArg/BamlTyClass. Renames the entire wire type universe in baml_type.proto from Ty*/TY_PRIMITIVE_* to BamlTy*/BAML_TY_PRIMITIVE_*; adds new enums BamlTyPrimitiveKind, BamlTyMediaKind, BamlTyFunctionParamMode; removes generic_param_bounds from function type. Removes the local BamlTy type-metadata tree from baml_outbound.proto and uses the shared BamlTy from baml_type.proto for all type-metadata fields (list item_type, map key/value_type, class/union variant types). Adds buf.yaml lint config; updates Go protoc invocation.
Rust: ty_encode module, decode, and value encoding/decoding
baml_language/crates/bridge_ctypes/src/ty_encode.rs, ty_decode.rs, value_encode.rs, value_decode.rs, lib.rs, baml_language/crates/bridge_cffi/src/ffi/host_value.rs, baml_language/crates/bridge_wasm/tests/host_callable.rs
Adds ty_encode module implementing runtime_ty_to_proto_ty (public entrypoint) and recursive RuntimeTy → BamlTy mapping via runtime_ty_to_variant. Adds helpers literal_to_proto, media_kind_to_proto, and function_param_mode. Updates value_encode.rs to use runtime_ty_to_proto_ty for list item_type, map key/value_type, union self_type, and generic args; adds early match arm for BexExternalAdt::Type encoding as BamlValueVariant::TyValue; removes old ty_to_field_type implementation. Updates ty_decode.rs parameter types from Ty* to BamlTy*. Updates value_decode tests and host-callable error payloads to use BamlTyClass for class_ty field. Re-exports runtime_ty_to_proto_ty from crate root.
Python SDK: protobuf generation, type bindings, and logic
baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.py, baml_handle_pb2.pyi, baml_inbound_pb2.py, baml_inbound_pb2.pyi, baml_outbound_pb2.py, baml_outbound_pb2.pyi, baml_type_pb2.py, baml_type_pb2.pyi, proto.py, __init__.py, rust/bridge_python/src/host_value.rs
Adds generated baml_handle_pb2 modules. Inbound protobuf files drop inline handle definitions and import from baml_handle_pb2; type references updated from Ty to BamlTy, message TyArg renamed to BamlTyArg. Outbound protobuf regenerated: switches import to baml_handle_pb2, replaces local BamlTy-typed fields with _baml_type_pb2.BamlTy, removes BamlTy* message classes, adds BamlLiteralValue. Type protobuf regenerated with BamlTy* renaming and BAML_TY_PRIMITIVE_* constants. Updates proto.py to import baml_handle_pb2, refactors outbound decoding to _ty_to_python_type with primitive/media lookup maps and _parameterize_tys for generics, flattens class/enum/handle FQN extraction. Updates docstrings to BamlTyArg. Updates host-callable error payload to use class_ty field.
Python SDK: tests
baml_language/sdks/python/tests/test_decode_handle.py, test_proto_generics.py, test_host_callable.py, test_proto_decode_typemap.py
test_decode_handle.py constructs BamlHandle via baml_handle_pb2. test_proto_generics.py rewrites tests for _ty_to_python_type with BamlTy wire variants, adds unknown/union wildcard tests, updates generic-arg construction via _set_primitive(kind), refactors test helpers. Other tests flatten name field access.
TypeScript/Node.js SDK: wire decoding, encoding, and fixtures
baml_language/sdks/nodejs/bridge_nodejs/typescript_src/wire_ty.ts, define_function.ts, proto.ts, tests/test_decode_call_result.test.ts, baml_language/sdks/typescript2/pkg-proto/src/decode.ts, src/encode.ts, src/test/encode-decode.test.ts
wire_ty.ts adds TY_PRIMITIVE_TOKEN reverse lookup and reads type fields via ty.primitive.kind, ty.list.item, ty.map.key/value, ty.optional.inner, ty.classTy.name/typeArgs; returns undefined for unbound positions. Switches BamlHandleType import in decode.ts to baml_handle. Flattens class/enum/thrown FQN extraction in proto.ts and decodeValueHolder. Updates decodeClass to use classValue.typeArgs for generic parameterization. Updates encode.ts class-value encoding to populate classTy field with name and typeArgs. Fixture tests use BamlTyPrimitiveKind.BAML_TY_PRIMITIVE_* for primitives, flatten type metadata from objects to string names plus typeArgs arrays across multiple fixtures, remove empty type wrappers from handle values.
Go SDK: proto.go decoding
baml_language/sdks/go/bridge_go/pkg/proto.go
Adds math/big and strconv imports for numeric literal parsing. Flattens ClassValue/EnumValue name extraction to call GetName() directly. Updates literal decoding from pb.BamlTyLiteral_* to pb.BamlLiteralValue_* with BigintValue (base-16) and FloatValue (string) parsing support.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • BoundaryML/baml#3431: Both PRs update bridge_ctypes/src/value_encode.rs to use new wire type metadata paths for generic type arguments, with this PR introducing the unified BamlTy schema and ty_encode encoding module.
  • BoundaryML/baml#3825: Both PRs modify value_encode.rs to derive wire type metadata via runtime_ty_to_proto_ty for generic instances and class type arguments.
  • BoundaryML/baml#3508: Both PRs tie into the new streaming BexExternalAdt::TaggedHeapHandle: this PR updates handle encoding to carry wire-encoded ty via runtime_ty_to_proto_ty, matching the proto tagging of ADT_TAGGED_HEAP_HANDLE.

Poem

🐇 A rabbit hops through schemas old and new,
Renaming Ty to BamlTy—what a zoo!
With baml_handle.proto shiny and fresh,
And ty_encode weaving through the mesh.
From Python to TypeScript, all SDKs cheer—
The unified wire type is finally here! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main objective: consolidating the outbound BamlTy type encoding onto the baml_type.proto Ty representation, which is the core refactoring work shown across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sam/generic2

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
baml_language/crates/bridge_ctypes/src/ty_encode.rs

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.15][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

baml_language/crates/bridge_cffi/src/ffi/host_value.rs

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.21][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

baml_language/crates/bridge_ctypes/src/value_encode.rs

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.20][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

  • 23 others
🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 01:04 Inactive
@github-actions

Copy link
Copy Markdown

No description provided.

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

Copy link
Copy Markdown

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: 75b14cb273

ℹ️ 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 on lines +171 to +173
BexExternalValue::Adt(BexExternalAdt::Type(rt)) => Some(BamlValueVariant::TyValue(
crate::ty_encode::runtime_ty_to_proto_ty(rt),
)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add host decoders before emitting ty_value

For any reflect.type_of<T>() result, this new arm now emits the ty_value oneof instead of the previous handle_value/ADT_TYPE path, but the outbound decoders still do not handle that variant: Python decode_value falls through to return None, Node decodeValueHolder falls through to return null, and typescript2/pkg-proto's deserializeValue default also returns null. In those environments, returning a reflected type silently becomes null rather than a usable type/handle, so either the host decoders need a ty_value case or this should remain on the handle path until they do.

Useful? React with 👍 / 👎.

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 01:10 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@typescript2/pkg-proto/src/decode.ts`:
- Line 9: The import statement in the decode.ts file references a generated
TypeScript module for BamlHandleType that does not exist. Regenerate the
TypeScript protobuf bindings from the baml_handle.proto source file to create
the missing generated module. This will generate the necessary TypeScript
definitions for the BamlHandleType enum and its constants (HANDLE_UNSPECIFIED,
UNTAGGED_RUST_DATA, UNTAGGED_BEX_HEAP) that are being used in the decode.ts
file. Ensure the protobuf code generation tool is properly configured to output
TypeScript files to the expected location matching the import path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2802928f-e32b-441e-8af8-03ae5a6100ed

📥 Commits

Reviewing files that changed from the base of the PR and between 3826d61 and 75b14cb.

⛔ Files ignored due to path filters (9)
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_handle.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_inbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_outbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (22)
  • baml_language/crates/bridge_ctypes/src/lib.rs
  • baml_language/crates/bridge_ctypes/src/ty_encode.rs
  • baml_language/crates/bridge_ctypes/src/value_encode.rs
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_handle.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_inbound.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_outbound.proto
  • baml_language/crates/bridge_ctypes/types/buf.yaml
  • baml_language/sdks/go/bridge_go/build.sh
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.d.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/wire_ty.ts
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/proto.py
  • baml_language/sdks/python/tests/test_decode_handle.py
  • baml_language/sdks/python/tests/test_proto_generics.py
  • typescript2/pkg-proto/src/decode.ts
  • typescript2/pkg-proto/src/test/encode-decode.test.ts

Comment thread typescript2/pkg-proto/src/decode.ts Resolved
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle June 23, 2026 01:22 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 01:52 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 01:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 02:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 02:06 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 02:07 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 02:13 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle June 23, 2026 02:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 18:40 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 18:47 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/crates/bridge_ctypes/src/value_encode.rs`:
- Around line 177-180: The code in the match statement for BexExternalValue::Adt
with BexExternalAdt::TaggedHeapHandle and in the other location around lines
234-252 should not use a fallback format string like format!("{ty}") for
class_ty names when handling non-nominal types. Instead, ensure that class_ty is
only set to Some when the type is actually a valid class or interface type by
validating the result of ty_to_class_ty. For non-class/interface types, return
None or propagate an error rather than fabricating a class name, to prevent
structural type strings like unknown or map<...> from being inserted into
typemap-key fields.

In `@baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_type.proto`:
- Around line 10-11: The header comment describing the generic function call
contract claims hosts send an ordered BamlTy list, but the actual wire format
defined in CallFunctionArgs.type_args is repeated BamlTyArg (which includes both
a TypeVar name and a type_value field). Update the header comment to accurately
describe that the host sends an ordered list of BamlTyArg entries, not bare
BamlTy entries, so SDK authors understand the correct wire shape they need to
implement.

In `@baml_language/sdks/go/bridge_go/pkg/proto.go`:
- Around line 308-313: In the switch statement handling BamlLiteralValue cases
within the literal value decoding logic, add a missing case handler for
BamlLiteralValue_BigintLiteral. After the existing cases for StringLiteral,
IntLiteral, and BoolLiteral, add a new case that matches
*pb.BamlLiteralValue_BigintLiteral and returns the result of parsing the
BigintLiteral value using a parseHexBigint function (similar to how other SDKs
handle bigint literals with hex parsing logic). This will ensure the switch
statement handles all literal value types and maintains parity with the Python
and Node SDK implementations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e5d1dbde-49f8-4e4c-b5c1-f64c2759930d

📥 Commits

Reviewing files that changed from the base of the PR and between c627f26 and 5814e3e.

⛔ Files ignored due to path filters (14)
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_handle.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_inbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_outbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_type.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.js.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (34)
  • baml_language/crates/bridge_ctypes/src/lib.rs
  • baml_language/crates/bridge_ctypes/src/ty_decode.rs
  • baml_language/crates/bridge_ctypes/src/ty_encode.rs
  • baml_language/crates/bridge_ctypes/src/value_decode.rs
  • baml_language/crates/bridge_ctypes/src/value_encode.rs
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_handle.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_inbound.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_outbound.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_type.proto
  • baml_language/crates/bridge_ctypes/types/buf.yaml
  • baml_language/sdks/go/bridge_go/build.sh
  • baml_language/sdks/go/bridge_go/pkg/proto.go
  • baml_language/sdks/nodejs/bridge_nodejs/tests/test_decode_call_result.test.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/define_function.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.d.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/wire_ty.ts
  • baml_language/sdks/python/src/baml_core/__init__.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.pyi
  • baml_language/sdks/python/src/baml_core/proto.py
  • baml_language/sdks/python/tests/test_decode_handle.py
  • baml_language/sdks/python/tests/test_host_callable.py
  • baml_language/sdks/python/tests/test_proto_decode_typemap.py
  • baml_language/sdks/python/tests/test_proto_generics.py
  • typescript2/pkg-proto/src/decode.ts
  • typescript2/pkg-proto/src/test/encode-decode.test.ts
✅ Files skipped from review due to trivial changes (7)
  • baml_language/crates/bridge_ctypes/types/buf.yaml
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.py
  • baml_language/sdks/python/src/baml_core/init.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.pyi
  • baml_language/sdks/python/tests/test_decode_handle.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.py
🚧 Files skipped from review as they are similar to previous changes (5)
  • baml_language/crates/bridge_ctypes/src/lib.rs
  • baml_language/sdks/go/bridge_go/build.sh
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_handle.proto
  • baml_language/crates/bridge_ctypes/src/ty_encode.rs
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.py

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle June 23, 2026 18:59 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 21:07 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 21:13 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle June 23, 2026 21:25 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 21:28 Inactive
@blacksmith-sh

This comment has been minimized.

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 21:34 Inactive
@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 21:43 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
baml_language/sdks/python/src/baml_core/proto.py (1)

432-439: 🎯 Functional Correctness | 🟠 Major

Handle PEP 604 unions before falling back to unknown.

Line 432 only recognizes typing.Union[...]. On Python 3.10+, typing.get_origin(int | str) returns types.UnionType, so Box[int | str] type args encode as unknown instead of a structural union.

Proposed fix
+import types as _types
 import typing
+_PEP604_UNION_TYPE = getattr(_types, "UnionType", None)
+
 def _fill_wire_ty(ty: "baml_type_pb2.BamlTy", py_type: Any) -> None:
-        if origin is typing.Union:
+        if origin is typing.Union or (
+            _PEP604_UNION_TYPE is not None and origin is _PEP604_UNION_TYPE
+        ):
             non_none = [a for a in targs if a is not type(None)]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/sdks/python/src/baml_core/proto.py` around lines 432 - 439, The
condition at line 432 only checks for typing.Union but doesn't handle PEP 604
union syntax (e.g., int | str) which uses types.UnionType on Python 3.10+.
Update the condition that checks if origin is typing.Union to also include a
check for types.UnionType (import the types module if needed) so that both union
syntaxes are properly handled by the _fill_inner function and encode as
structural unions instead of falling back to unknown.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/sdks/python/src/baml_core/proto.py`:
- Around line 286-301: The Pydantic model branch (around line 286-301) has been
updated to assign the FQN to cv.class_ty.name, but the media class branch
handling BamlImage, BamlAudio, and BamlPdf (around line 253) still uses the old
cv.name assignment pattern. Update the media class encoder branch to use
cv.class_ty.name instead of cv.name to maintain consistency with the Pydantic
model approach and ensure media wrapper FQNs are properly preserved during
serialization.

---

Outside diff comments:
In `@baml_language/sdks/python/src/baml_core/proto.py`:
- Around line 432-439: The condition at line 432 only checks for typing.Union
but doesn't handle PEP 604 union syntax (e.g., int | str) which uses
types.UnionType on Python 3.10+. Update the condition that checks if origin is
typing.Union to also include a check for types.UnionType (import the types
module if needed) so that both union syntaxes are properly handled by the
_fill_inner function and encode as structural unions instead of falling back to
unknown.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6e5cdcbe-d4c6-48ce-84f6-20d8409266d9

📥 Commits

Reviewing files that changed from the base of the PR and between c627f26 and 040bb40.

⛔ Files ignored due to path filters (14)
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_handle.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_inbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_outbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_type.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto.js.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/wire_ty.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (38)
  • baml_language/crates/bridge_cffi/src/ffi/host_value.rs
  • baml_language/crates/bridge_ctypes/src/lib.rs
  • baml_language/crates/bridge_ctypes/src/ty_decode.rs
  • baml_language/crates/bridge_ctypes/src/ty_encode.rs
  • baml_language/crates/bridge_ctypes/src/value_decode.rs
  • baml_language/crates/bridge_ctypes/src/value_encode.rs
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_handle.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_inbound.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_outbound.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_type.proto
  • baml_language/crates/bridge_ctypes/types/buf.yaml
  • baml_language/crates/bridge_wasm/tests/host_callable.rs
  • baml_language/sdks/go/bridge_go/build.sh
  • baml_language/sdks/go/bridge_go/pkg/proto.go
  • baml_language/sdks/nodejs/bridge_nodejs/tests/test_decode_call_result.test.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/define_function.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.d.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.js
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/wire_ty.ts
  • baml_language/sdks/python/rust/bridge_python/src/host_value.rs
  • baml_language/sdks/python/src/baml_core/__init__.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.pyi
  • baml_language/sdks/python/src/baml_core/proto.py
  • baml_language/sdks/python/tests/test_decode_handle.py
  • baml_language/sdks/python/tests/test_host_callable.py
  • baml_language/sdks/python/tests/test_proto_decode_typemap.py
  • baml_language/sdks/python/tests/test_proto_generics.py
  • typescript2/pkg-proto/src/decode.ts
  • typescript2/pkg-proto/src/encode.ts
  • typescript2/pkg-proto/src/test/encode-decode.test.ts
✅ Files skipped from review due to trivial changes (10)
  • baml_language/sdks/go/bridge_go/build.sh
  • baml_language/crates/bridge_ctypes/types/buf.yaml
  • baml_language/sdks/nodejs/bridge_nodejs/tests/test_decode_call_result.test.ts
  • baml_language/sdks/python/src/baml_core/init.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.pyi
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_outbound_pb2.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.py
  • baml_language/sdks/python/tests/test_proto_decode_typemap.py
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_handle_pb2.py
🚧 Files skipped from review as they are similar to previous changes (15)
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_handle.proto
  • baml_language/sdks/python/tests/test_host_callable.py
  • baml_language/sdks/go/bridge_go/pkg/proto.go
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/define_function.ts
  • baml_language/crates/bridge_ctypes/src/lib.rs
  • baml_language/sdks/python/tests/test_decode_handle.py
  • typescript2/pkg-proto/src/decode.ts
  • baml_language/crates/bridge_ctypes/src/ty_decode.rs
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_inbound.proto
  • baml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_type.proto
  • baml_language/crates/bridge_ctypes/src/ty_encode.rs
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_type_pb2.pyi
  • typescript2/pkg-proto/src/test/encode-decode.test.ts
  • baml_language/crates/bridge_ctypes/src/value_encode.rs
  • baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.pyi

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 21:49 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle June 23, 2026 22:00 Inactive
Consolidate the two on-the-wire "a BAML type" encodings in bridge_ctypes
onto a single representation. `BamlTy` (baml_outbound.proto) was an older,
lossy type-metadata encoding riding alongside outbound container values;
`Ty` (baml_type.proto) is the faithful, complete mirror of
`baml_type::RuntimeTy` already used inbound. This collapses the two
parallel per-SDK mappings (native->Ty writing, BamlTy->native reading)
into one.

Main change (02a):
- New ty_encode.rs: runtime_ty_to_proto_ty(&RuntimeTy) -> Ty, the total
  inverse of ty_decode.rs (all 24 variants) and strictly more capable
  than the old ty_to_field_type, which collapsed many variants to
  unknown/unreachable!. Also wires the previously-dead outbound
  ty_value (field 21) for BexExternalAdt::Type.
- Repoint the four embed sites (BamlValueList.item_type,
  BamlValueMap.key_type/value_type, BamlValueUnionVariant.self_type,
  BamlTyGenericArg.ty) from BamlTy to Ty; drop ty_to_field_type.
- Unions encode structurally: nullable-single -> Optional, else
  Ty::Union (mirrors the inbound writer). Type-position host readers map
  a structural union to a wildcard.
- Migrate the SDK type-position readers: Python _ty_to_python_type and
  Node outboundTyToBamlType now consume Ty (the literal inverse of their
  inbound writers); the any_type branch is gone. Go has no type-position
  reader (only value-level BamlTyLiteral, retained) -> regen only.
- Delete the BamlTy message tree + BamlTyAny. Keep BamlTyLiteral /
  BamlLiteral* (they back the value-level BamlOutboundValue.literal_value)
  and BamlTyName / BamlTyGenericArg (now carrying Ty).

Side quest (02a §7):
- Extract BamlHandleType + BamlHandle into baml_handle.proto so
  baml_outbound.proto imports it directly, dropping the outbound->inbound
  proto dependency edge. Python/TS2 import repoints; Rust/Node/Go regen.

Regenerated all five proto clients.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vercel
vercel Bot temporarily deployed to Preview – beps June 23, 2026 22:04 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 23, 2026 22:10 Inactive
@sxlijin
sxlijin enabled auto-merge June 23, 2026 22:10
@sxlijin
sxlijin added this pull request to the merge queue Jun 23, 2026
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle June 23, 2026 22:22 Inactive
Merged via the queue into canary with commit c50a0a7 Jun 23, 2026
54 checks passed
@sxlijin
sxlijin deleted the sam/generic2 branch June 23, 2026 22:34

This branch was previously deployed

3 inactive deployments
Preview – promptfiddle — 04c201f5 Deployed Jun 23, 2026 by vercel[bot]
Preview – promptfiddle2 — 04c201f5 Deployed Jun 23, 2026 by vercel[bot]
Preview – beps — 04c201f5 Deployed Jun 23, 2026 by vercel[bot]
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