Skip to content

chore: rename HOST_VALUE_ERROR to HOST_VALUE_OPAQUE#3756

Merged
sxlijin merged 4 commits into
canaryfrom
sam/host-value
Jun 12, 2026
Merged

chore: rename HOST_VALUE_ERROR to HOST_VALUE_OPAQUE#3756
sxlijin merged 4 commits into
canaryfrom
sam/host-value

Conversation

@sxlijin

@sxlijin sxlijin commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Rename HOST_VALUE_ERRORHOST_VALUE_OPAQUE

Behavior-preserving rename of the host-value "error" kind and wire tag to "opaque", across all four language bridges. The Error host-value kind was never error-specific at the engine level — it's a generic opaque passthrough value everywhere (interning, deferred release, wire encode/decode, $rust_type _handle round-trip, identity equality). "Error-ness" is purely a host-side property: the bridge wraps the handle in a baml.errors.HostCallable instance for throw semantics. This rename names the kind for what it is; a native host exception is just one consumer.

The wire enum number is unchanged (16), so this is wire-compatible — only the symbol name changes.

Phases

  • Phase 1 — Proto + Rust core (+ WASM): HOST_VALUE_ERROR = 16HOST_VALUE_OPAQUE = 16; HostValueKind::ErrorOpaque; decode/encode arms, dispatch-gate comment, WASM handle, and all kind-naming tests.
  • Phase 2 — Python bridge: register_host_errorregister_host_opaque; _try_rehydrate_host_callable_try_rehydrate_host_value; tag checks/drop-skip; pb2 regenerated.
  • Phase 3 — Node bridge: host_error_registry.tshost_value_registry.ts (registerHostOpaque/lookupHostValue/tryRehydrateHostValueByKey); napi mintHostValueKey/registerHostValueReleaseCallback; proto regenerated.
  • Phase 4 — Go gencode: regenerated baml_inbound.pb.go (symbol-only diff, matching toolchain versions).

The baml.errors.HostCallable FQN and all error-throw behavior are unchanged. The existing host-callable / host-error test suites pass (modulo renamed symbols), proving the rename is behavior-preserving — including the raised is/=== caught same-object round-trip in both Python and Node.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Replaced error-specific host registry with a unified opaque host-value registry for registering, rehydrating, and releasing host-owned values across runtimes and SDKs.
    • SDK APIs and callbacks updated to mint/release host-value keys and to rehydrate thrown host-callable values via the opaque-value path.
    • Same-process round-trip behavior for thrown host-callable values now uses the host-value registry.

@vercel

vercel Bot commented Jun 12, 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 12, 2026 6:26pm
promptfiddle Ready Ready Preview, Comment Jun 12, 2026 6:26pm
promptfiddle2 Ready Ready Preview, Comment Jun 12, 2026 6:26pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f7805ed-078f-4d65-b714-d5cec7edb505

📥 Commits

Reviewing files that changed from the base of the PR and between 82223f8 and 4485185.

📒 Files selected for processing (9)
  • baml_language/crates/bex_engine/tests/host_value_callable.rs
  • baml_language/crates/bex_resource_types/src/host_value.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_inbound.proto
  • baml_language/crates/bridge_wasm/src/handle.rs
  • baml_language/crates/bridge_wasm/tests/host_callable.rs
  • baml_language/crates/sys_native/src/host_impls.rs
  • baml_language/crates/sys_types/src/lib.rs

📝 Walkthrough

Walkthrough

This PR renames HostValueKind::Error → HostValueKind::Opaque and updates the protocol discriminator HOST_VALUE_ERROR (16) → HOST_VALUE_OPAQUE, adjusting bridge encode/decode, handle-drop/release logic, Node.js/Python SDK registries, and tests to use opaque host-value semantics.

Changes

Host-value kind redefinition and protocol/bridge-level translation

Layer / File(s) Summary
Core host-value kind and proto
baml_language/crates/bex_resource_types/src/host_value.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.pyi, baml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.py, 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
Removed HostValueKind::Error; updated docs to describe Opaque. Renamed proto enum member 16 from HOST_VALUE_ERRORHOST_VALUE_OPAQUE; regenerated descriptors and language stubs.
Bridge encode/decode host-value translation
baml_language/crates/bridge_ctypes/src/value_decode.rs, baml_language/crates/bridge_ctypes/src/value_encode.rs
Mapping updated so HostValueKind::OpaqueBamlHandleType::HostValueOpaque; tests assert opaque handles bypass HANDLE_TABLE and decode/encode as Opaque.

Runtime handle drop and release management

Layer / File(s) Summary
WASM and native handle drop logic & tests
baml_language/crates/bridge_wasm/src/handle.rs, baml_language/crates/bridge_wasm/tests/host_callable.rs, baml_language/crates/sys_native/src/host_impls.rs, baml_language/crates/sys_types/src/lib.rs, baml_language/crates/bex_engine/tests/host_value_callable.rs
Drop/type_name updated to treat HostValueOpaque (with HostValueCallable) as host-owned and excluded from HANDLE_TABLE release. Tests and synthetic payloads now use HostValueKind::Opaque.
Python bridge handle/drop updates
baml_language/sdks/python/rust/bridge_python/src/py_handle.rs, baml_language/sdks/python/src/baml_core/baml_py.pyi
BamlPyHandle Drop logic and docstrings updated to exclude HostValueOpaque from baml_handle_release and to document HOST_VALUE_OPAQUE usage.

Node.js SDK host-value registry migration

Layer / File(s) Summary
Node.js Rust bridge host-value API
baml_language/sdks/nodejs/bridge_nodejs/src/host_value.rs
Replaced error-specific TSFN/OnceLock and key mint/register APIs with host-value equivalents (mint_host_value_key, HOST_VALUE_RELEASE_CALLBACK, register_host_value_release_callback). host_release_callback wired to new TSFN.
Node.js TypeScript registry & proto flow
baml_language/sdks/nodejs/bridge_nodejs/typescript_src/host_value_registry.ts, baml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto.ts, baml_language/sdks/nodejs/bridge_nodejs/typescript_src/native.d.ts
Registry repurposed for opaque host values: registerHostOpaque/lookupHostValue/tryRehydrateHostValueByKey; proto.ts uses these helpers and emits BamlHandleType.HOST_VALUE_OPAQUE; native.d.ts updated declarations.
Node.js tests
baml_language/sdks/nodejs/bridge_nodejs/tests/host_callable.test.ts
Tests updated to import hostValueRegistry and assert rehydration via tryRehydrateHostValueByKey.

Python SDK host-value registry migration

Layer / File(s) Summary
Python Rust bridge host-value registry & send/lookup
baml_language/sdks/python/rust/bridge_python/src/host_value.rs
Replaced register_host_error with register_host_opaque; lookup_host_value and build_host_callable_inbound expect/emits HostValueOpaque; send_dispatch_error_from_pyerr uses register_host_opaque.
Python decode/rehydration helper
baml_language/sdks/python/src/baml_core/proto.py
Replaced _try_rehydrate_host_callable with _try_rehydrate_host_value; decode_call_result calls the new helper to attempt identity-preserving re-raise of same-runtime exceptions.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • BoundaryML/baml#3680: Related host-callable/host-value round-trip plumbing; this PR renames/moves the handle kind to OPAQUE.
  • BoundaryML/baml#3571: Related changes to host-value representation and bridge mappings that this migration builds upon.

🐰 From Error to Opaque, the handles now glide,
Across proto and bridges they quietly slide,
Rust, Node, and Python keep identity near,
Registries whisper the value is here,
A small rename, one protocol-wide stride.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Title check ✅ Passed The title clearly and concisely summarizes the main change: renaming HOST_VALUE_ERROR to HOST_VALUE_OPAQUE across the codebase.

✏️ 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/host-value

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 and usage tips.

@github-actions

github-actions Bot commented Jun 12, 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.

@sxlijin sxlijin enabled auto-merge June 12, 2026 17:47
@github-actions

Copy link
Copy Markdown

No description provided.

@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/nodejs/bridge_nodejs/typescript_src/host_value_registry.ts (1)

87-109: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

lookupHostValue conflates “missing” with a real undefined payload.

registerHostOpaque accepts any JS value, including throw undefined, but Map.get() returns undefined for both “key missing” and “stored value is undefined”. proto.ts uses original !== undefined as the hit test, so same-process rehydration silently fails for legitimate undefined throws and degrades to the metadata wrapper instead of preserving the original value. Consider returning an explicit hit/miss shape here, or pairing get with has.

Suggested direction
-export function lookupHostValue(key: bigint): unknown {
-    return hostValueMap.get(key);
+export function lookupHostValue(key: bigint): { found: boolean; value: unknown } {
+    return hostValueMap.has(key)
+        ? { found: true, value: hostValueMap.get(key) }
+        : { found: false, value: undefined };
 }
🤖 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/nodejs/bridge_nodejs/typescript_src/host_value_registry.ts`
around lines 87 - 109, lookupHostValue currently returns Map.get(key) which
conflates a missing entry with a legitimately stored undefined
(registerHostOpaque can store undefined), causing proto.ts's original !==
undefined check to mis-detect hits; change lookupHostValue to return an explicit
hit/miss shape (e.g. { found: boolean, value?: unknown } or a tuple [boolean,
unknown]) or at minimum use hostValueMap.has(key) together with
hostValueMap.get(key) so callers can distinguish "missing" from "stored
undefined"; update the function signature and all callers (notably proto.ts's
decoder path that checks original !== undefined) to use the new shape or check
the returned boolean before treating value as absent.
🤖 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/nodejs/bridge_nodejs/typescript_src/host_value_registry.ts`:
- Around line 43-44: hostValueMap is module-scoped so reloads create a new Map
but the native registerHostValueReleaseCallback (first-call-wins) still points
at the old callback and leaks entries; fix by hoisting shared state onto
globalThis (e.g. use a globalThis.__bamlHostValueMap and
globalThis.__bamlHostValueReleaseRegistered flag) and use those in hostValueMap
creation and when calling registerHostValueReleaseCallback so the callback
always references the shared Map across reloads; update any other occurrences
(the same pattern around the code referenced at lines 137-140) to read/write the
shared global Map and to only register the native release callback once.

---

Outside diff comments:
In
`@baml_language/sdks/nodejs/bridge_nodejs/typescript_src/host_value_registry.ts`:
- Around line 87-109: lookupHostValue currently returns Map.get(key) which
conflates a missing entry with a legitimately stored undefined
(registerHostOpaque can store undefined), causing proto.ts's original !==
undefined check to mis-detect hits; change lookupHostValue to return an explicit
hit/miss shape (e.g. { found: boolean, value?: unknown } or a tuple [boolean,
unknown]) or at minimum use hostValueMap.has(key) together with
hostValueMap.get(key) so callers can distinguish "missing" from "stored
undefined"; update the function signature and all callers (notably proto.ts's
decoder path that checks original !== undefined) to use the new shape or check
the returned boolean before treating value as absent.
🪄 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: e56b9844-b04e-4320-ac5c-4761a47a69e8

📥 Commits

Reviewing files that changed from the base of the PR and between bdab837 and 82223f8.

⛔ Files ignored due to path filters (13)
  • baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_inbound.pb.go is excluded by !**/*.pb.go
  • baml_language/sdks/nodejs/bridge_nodejs/dist/host_error_registry.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/host_error_registry.js.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/host_value_registry.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/host_value_registry.d.ts.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/host_value_registry.js is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/host_value_registry.js.map is excluded by !**/dist/**, !**/*.map
  • baml_language/sdks/nodejs/bridge_nodejs/dist/native.d.ts is excluded by !**/dist/**
  • baml_language/sdks/nodejs/bridge_nodejs/dist/native.js is excluded by !**/dist/**
  • 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/**
📒 Files selected for processing (22)
  • baml_language/crates/bex_engine/tests/host_value_callable.rs
  • baml_language/crates/bex_resource_types/src/host_value.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_inbound.proto
  • baml_language/crates/bridge_wasm/src/handle.rs
  • baml_language/crates/bridge_wasm/tests/host_callable.rs
  • baml_language/crates/sys_native/src/host_impls.rs
  • baml_language/crates/sys_types/src/lib.rs
  • baml_language/sdks/nodejs/bridge_nodejs/src/host_value.rs
  • baml_language/sdks/nodejs/bridge_nodejs/tests/host_callable.test.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/host_value_registry.ts
  • baml_language/sdks/nodejs/bridge_nodejs/typescript_src/native.d.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/python/rust/bridge_python/src/host_value.rs
  • baml_language/sdks/python/rust/bridge_python/src/py_handle.rs
  • baml_language/sdks/python/src/baml_core/baml_py.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/proto.py

@sxlijin sxlijin changed the title Rename HOST_VALUE_ERROR → HOST_VALUE_OPAQUE (behavior-preserving) chore: rename HOST_VALUE_ERROR to HOST_VALUE_OPAQUE Jun 12, 2026
@sxlijin sxlijin added this pull request to the merge queue Jun 12, 2026
Merged via the queue into canary with commit 82605ba Jun 12, 2026
54 checks passed
@sxlijin sxlijin deleted the sam/host-value branch June 12, 2026 18:26
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