chore: rename HOST_VALUE_ERROR to HOST_VALUE_OPAQUE#3756
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughThis 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. ChangesHost-value kind redefinition and protocol/bridge-level translation
Runtime handle drop and release management
Node.js SDK host-value registry migration
Python SDK host-value registry migration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
|
No description provided. |
There was a problem hiding this comment.
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
lookupHostValueconflates “missing” with a realundefinedpayload.
registerHostOpaqueaccepts any JS value, includingthrow undefined, butMap.get()returnsundefinedfor both “key missing” and “stored value is undefined”.proto.tsusesoriginal !== undefinedas the hit test, so same-process rehydration silently fails for legitimateundefinedthrows and degrades to the metadata wrapper instead of preserving the original value. Consider returning an explicit hit/miss shape here, or pairinggetwithhas.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
⛔ Files ignored due to path filters (13)
baml_language/sdks/go/bridge_go/cffi/proto/baml_core/cffi/v1/baml_inbound.pb.gois excluded by!**/*.pb.gobaml_language/sdks/nodejs/bridge_nodejs/dist/host_error_registry.d.ts.mapis excluded by!**/dist/**,!**/*.mapbaml_language/sdks/nodejs/bridge_nodejs/dist/host_error_registry.js.mapis excluded by!**/dist/**,!**/*.mapbaml_language/sdks/nodejs/bridge_nodejs/dist/host_value_registry.d.tsis excluded by!**/dist/**baml_language/sdks/nodejs/bridge_nodejs/dist/host_value_registry.d.ts.mapis excluded by!**/dist/**,!**/*.mapbaml_language/sdks/nodejs/bridge_nodejs/dist/host_value_registry.jsis excluded by!**/dist/**baml_language/sdks/nodejs/bridge_nodejs/dist/host_value_registry.js.mapis excluded by!**/dist/**,!**/*.mapbaml_language/sdks/nodejs/bridge_nodejs/dist/native.d.tsis excluded by!**/dist/**baml_language/sdks/nodejs/bridge_nodejs/dist/native.jsis excluded by!**/dist/**baml_language/sdks/nodejs/bridge_nodejs/dist/proto.jsis excluded by!**/dist/**baml_language/sdks/nodejs/bridge_nodejs/dist/proto.js.mapis excluded by!**/dist/**,!**/*.mapbaml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.d.tsis excluded by!**/dist/**baml_language/sdks/nodejs/bridge_nodejs/dist/proto/baml_cffi.jsis excluded by!**/dist/**
📒 Files selected for processing (22)
baml_language/crates/bex_engine/tests/host_value_callable.rsbaml_language/crates/bex_resource_types/src/host_value.rsbaml_language/crates/bridge_ctypes/src/value_decode.rsbaml_language/crates/bridge_ctypes/src/value_encode.rsbaml_language/crates/bridge_ctypes/types/baml_core/cffi/v1/baml_inbound.protobaml_language/crates/bridge_wasm/src/handle.rsbaml_language/crates/bridge_wasm/tests/host_callable.rsbaml_language/crates/sys_native/src/host_impls.rsbaml_language/crates/sys_types/src/lib.rsbaml_language/sdks/nodejs/bridge_nodejs/src/host_value.rsbaml_language/sdks/nodejs/bridge_nodejs/tests/host_callable.test.tsbaml_language/sdks/nodejs/bridge_nodejs/typescript_src/host_value_registry.tsbaml_language/sdks/nodejs/bridge_nodejs/typescript_src/native.d.tsbaml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto.tsbaml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.d.tsbaml_language/sdks/nodejs/bridge_nodejs/typescript_src/proto/baml_cffi.jsbaml_language/sdks/python/rust/bridge_python/src/host_value.rsbaml_language/sdks/python/rust/bridge_python/src/py_handle.rsbaml_language/sdks/python/src/baml_core/baml_py.pyibaml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.pybaml_language/sdks/python/src/baml_core/cffi/v1/baml_inbound_pb2.pyibaml_language/sdks/python/src/baml_core/proto.py
Rename
HOST_VALUE_ERROR→HOST_VALUE_OPAQUEBehavior-preserving rename of the host-value "error" kind and wire tag to "opaque", across all four language bridges. The
Errorhost-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_handleround-trip, identity equality). "Error-ness" is purely a host-side property: the bridge wraps the handle in abaml.errors.HostCallableinstance 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
HOST_VALUE_ERROR = 16→HOST_VALUE_OPAQUE = 16;HostValueKind::Error→Opaque; decode/encode arms, dispatch-gate comment, WASM handle, and all kind-naming tests.register_host_error→register_host_opaque;_try_rehydrate_host_callable→_try_rehydrate_host_value; tag checks/drop-skip; pb2 regenerated.host_error_registry.ts→host_value_registry.ts(registerHostOpaque/lookupHostValue/tryRehydrateHostValueByKey); napimintHostValueKey/registerHostValueReleaseCallback; proto regenerated.baml_inbound.pb.go(symbol-only diff, matching toolchain versions).The
baml.errors.HostCallableFQN 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 theraised is/=== caughtsame-object round-trip in both Python and Node.🤖 Generated with Claude Code
Summary by CodeRabbit