Skip to content

test(python): cover bridge version mismatch diagnostic - #4380

Merged
sxlijin merged 2 commits into
canaryfrom
agent/b-1473-version-mismatch
Aug 12, 2026
Merged

sxlijin merged 2 commits into
canaryfrom
agent/b-1473-version-mismatch

Conversation

@sxlijin

@sxlijin sxlijin commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add Python integration coverage for generated-bytecode toolchain mismatches
  • verify the complete bridge identity diagnostic survives the PyO3 boundary
  • verify compatibility validation runs before bytecode deserialization

Root cause and relation to #4315

The B-1473 report used generator 0.15.1-nightly.20260731.a with baml_bridge==0.15.0. That generator predates #4315 and emitted only raw bytecode, so the bridge had no independently readable generator identity and surfaced Unexpected variant tag: 7.

#4315 already fixed the supported regenerated-SDK path by embedding generation metadata and validating it before deserialization. Current coverage tests metadata emission and core bridge_cffi diagnostics separately; this PR closes the remaining Python host-boundary gap.

Legacy SDKs generated before #4315 must be regenerated to gain the compatibility preflight because their raw-bytecode-only payload has no toolchain identity to inspect.

Controlled reproduction

State Generator Installed Python bridge Result
Before #4315 0.15.1-nightly.20260731.a 0.15.0 Reproduces BamlPanic: Failed to deserialize BAML bytecode: Unexpected variant tag: 7
With #4315 0.16.0 0.15.1.dev2026080700 Raises an actionable version-skew RuntimeError before deserialization with generated, installed, and required versions plus repair guidance

Validation

  • uv run pytest -n 0 tests/test_engine.py::TestBasics -q — 4 passed, 1 expected xfail
  • cargo test -p bridge_cffi generated_metadata_tests — 5 passed
  • uv run ruff check tests/test_engine.py
  • git diff --check

Linear: B-1473

Summary by CodeRabbit

  • Bug Fixes
    • Improved runtime handling of bytecode generated with an incompatible toolchain.
    • Displays a clear version-mismatch error with installed and expected versions instead of an initialization failure.

@linear

linear Bot commented Aug 12, 2026

Copy link
Copy Markdown

B-1473

@vercel

vercel Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
beps Error Error Aug 12, 2026 8:25pm
promptfiddle2 Ready Ready Preview Aug 12, 2026 8:25pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – beps August 12, 2026 19:10 Inactive
@coderabbitai

coderabbitai Bot commented Aug 12, 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 Plus

Run ID: 8c32556a-cec8-4239-8340-3d7f71b2d84a

📥 Commits

Reviewing files that changed from the base of the PR and between f6c01b1 and da2bba3.

📒 Files selected for processing (1)
  • baml_language/sdks/python/tests/test_engine.py

📝 Walkthrough

Walkthrough

The Python engine tests now import bridge and toolchain version accessors. They verify that incompatible bytecode raises a detailed RuntimeError with version information and regeneration guidance instead of exposing a deserialization panic.

Changes

Runtime version validation

Layer / File(s) Summary
Version-skew initialization test
baml_language/sdks/python/tests/test_engine.py
The test imports runtime version accessors and validates the error raised when generated bytecode uses incompatible toolchain metadata. It checks installed and expected versions, regeneration guidance, and exclusion of the lower-level deserialization error.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: hellovai

Poem

A rabbit checked the bytecode with care,
Found mismatched versions hiding there.
“Regenerate,” said the test,
“Clear errors are best!”
No panic bounced through the software air.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the Python test coverage for bridge version mismatch diagnostics, which is the main change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/b-1473-version-mismatch

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

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 – promptfiddle2 August 12, 2026 19:18 Inactive
@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 26.2 MB 11.1 MB file 27.4 MB -1.2 MB (-4.4%) OK
✅ packed-program Linux 🔒 16.9 MB 6.8 MB file 18.6 MB -1.7 MB (-9.1%) OK
✅ baml-cli macOS 🔒 20.4 MB 9.7 MB file 21.3 MB -913.9 KB (-4.3%) OK
✅ packed-program macOS 🔒 13.3 MB 6.0 MB file 14.5 MB -1.2 MB (-8.2%) OK
✅ baml-cli Windows 🔒 21.9 MB 9.9 MB file 23.0 MB -1.1 MB (-4.7%) OK
✅ packed-program Windows 🔒 14.1 MB 6.1 MB file 15.5 MB -1.4 MB (-9.3%) OK
✅ bridge_wasm WASM 15.5 MB 🔒 4.2 MB gzip 4.6 MB -440.8 KB (-9.6%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@vercel
vercel Bot temporarily deployed to Preview – beps August 12, 2026 20:16 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 August 12, 2026 20:25 Inactive
@sxlijin
sxlijin added this pull request to the merge queue Aug 12, 2026
Merged via the queue into canary with commit 0a7cc11 Aug 12, 2026
185 of 193 checks passed
@sxlijin
sxlijin deleted the agent/b-1473-version-mismatch branch August 12, 2026 20:53
pull Bot pushed a commit to justinlietz93/baml that referenced this pull request Aug 13, 2026
## Summary

- add `baml toolchain pin <canary|nightly|version|path>` to select a
project-local toolchain in the nearest `baml.toml`
- share installation, channel activation, and local-path validation
behavior with `baml toolchain use`
- preserve manifest formatting and comments while replacing conflicting
`toolchain.version`, `toolchain.channel`, or `toolchain.path` selectors
- update generated-bytecode version-skew diagnostics to recommend the
executable pin command
- identify each bridge's package ecosystem in upgrade guidance,
including “the Python package,” npm, Go, Rust, NuGet, Maven, Swift, and
C++

## Why

The existing version-skew error told users to pin `toolchain.version`
manually or change their machine-wide default with `baml toolchain use`.
BAML did not provide a command that performed the project-local edit.

This makes the primary recovery path directly executable, supports the
same selector forms as `baml toolchain use`, and keeps the alternative
bridge-upgrade guidance specific to the active SDK ecosystem.

## Behavior

```text
baml toolchain pin canary
baml toolchain pin nightly
baml toolchain pin 0.15.1-nightly.20260807.a
baml toolchain pin ./target/debug/baml-cli
```

The command:

- finds the nearest `baml.toml` from the current directory
- validates the manifest before downloading or writing
- installs exact versions when missing
- installs and activates channel selections
- validates local binaries and stores a normalized path
- atomically writes the matching `[toolchain]` key: `version`,
`channel`, or `path`
- removes conflicting selectors while preserving TOML comments and
formatting

## Validation

- `cargo test -p baml -p bridge_cffi` — 43 wrapper unit tests, 5 wrapper
integration tests, 37 bridge unit tests, and bridge
ABI/header/unhandled-spawn tests passed
- `cargo clippy -p baml -p bridge_cffi --all-targets -- -D warnings`
- `cargo fmt --all -- --check`
- rebuilt the Python bridge with `uv run maturin develop --uv`
- `uv run pytest -n 0
tests/test_engine.py::TestBasics::test_generated_bytecode_version_skew_fails_before_deserialization
-q` — 1 passed
- `uv run ruff check tests/test_engine.py`
- `git diff --check`

Linear:
[B-1123](https://linear.app/boundaryml2/issue/B-1123/bytecode-version-skew-errors)

Follow-up to [BoundaryML#4315](BoundaryML#4315) and
[BoundaryML#4380](BoundaryML#4380).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added `baml toolchain pin` to select a project-specific toolchain by
version, release channel, or local executable path.
- Toolchain settings are saved in the nearest project manifest, with
paths normalized automatically.
  - Added offline status support for verifying pinned toolchains.

- **Bug Fixes**
- Improved version-mismatch guidance with clear steps to pin or upgrade
the toolchain and regenerate code.
- Preserved existing manifest formatting and comments when updating
toolchain settings.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

This branch was previously deployed

2 inactive deployments
Preview – promptfiddle2 — da2bba37 Deployed Aug 12, 2026 by vercel[bot]
Preview – beps — da2bba37 Deployed Aug 12, 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