{"record":{"id":"edc0bc5c918301b9","repo":"BoundaryML/baml","slug":"failed-to-unmarshal-invocationresponse-w","errorCode":null,"errorMessage":"failed to unmarshal InvocationResponse: %w","messagePattern":"failed to unmarshal InvocationResponse: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/callbacks.go","lineNumber":228,"sourceCode":"\t\t}\n\n\t\tsafeSend(callback.channel, res)\n\t\tif isDone == 1 {\n\t\t\tsafeClose(callback.channel)\n\t\t\tcallbackMutex.Lock()\n\t\t\tdefer callbackMutex.Unlock()\n\t\t\tdeleteCallback(id_uint)\n\t\t}\n\t}\n}\n\n// trigger_callback_object_handle handles callbacks that return an InvocationResponse\n// containing a BamlObjectHandle (e.g. from build_request_from_c).\nfunc trigger_callback_object_handle(id uint32, callback CallbackData, content_bytes []byte) {\n\tvar response cffi.InvocationResponse\n\terr := proto.Unmarshal(content_bytes, &response)\n\tif err != nil {\n\t\tsafeSend(callback.channel, ResultCallback{Error: fmt.Errorf(\"failed to unmarshal InvocationResponse: %w\", err)})\n\t\tsafeClose(callback.channel)\n\t\tcallbackMutex.Lock()\n\t\tdefer callbackMutex.Unlock()\n\t\tdeleteCallback(id)\n\t\treturn\n\t}\n\n\tswitch resp := response.GetResponse().(type) {\n\tcase *cffi.InvocationResponse_Error:\n\t\tsafeSend(callback.channel, ResultCallback{Error: BamlError{Message: resp.Error}})\n\tcase *cffi.InvocationResponse_Success:\n\t\tsuccess := resp.Success\n\t\tif success == nil {\n\t\t\tsafeSend(callback.channel, ResultCallback{Error: fmt.Errorf(\"nil success in InvocationResponse\")})\n\t\t} else {\n\t\t\tswitch result := success.GetResult().(type) {\n\t\t\tcase *cffi.InvocationResponseSuccess_Object:\n\t\t\t\tdecoded, decodeErr := decodeRawObjectImpl(callback.runtime, result.Object)","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/callbacks.go#L210-L246","documentation":"trigger_callback_object_handle processes the FFI callback that returns an InvocationResponse (e.g. from build_request_from_c). The payload bytes must be valid protobuf for cffi.InvocationResponse; if proto.Unmarshal fails, the error is wrapped and delivered to the waiting channel as the callback result, then the callback is cleaned up.","triggerScenarios":"The Rust/FFI side returns callback content_bytes that are not a valid protobuf-encoded InvocationResponse — corrupted or misrouted callback payload, version mismatch between the Go cffi definitions and the native runtime, or a buffer sliced incorrectly.","commonSituations":"Mixed BAML versions (Go bindings rebuilt against a different native library), custom builds where the callback protocol changed, or memory/transport corruption in the FFI channel.","solutions":["Rebuild/reinstall the BAML Go bindings and native runtime together so cffi definitions match (go mod tidy, regenerate, ensure matching baml CLI/runtime versions).","Check that the callback id/payload routing hasn't been corrupted — this is an internal protocol failure, so verify you're on a supported, consistent BAML version.","Inspect the wrapped error from proto.Unmarshal for details (wrong wire type usually indicates a schema mismatch).","Report to BAML if it reproduces on a consistent version set; include the inner unmarshal error."],"exampleFix":"// before\n// go.mod pins github.com/boundaryml/baml v0.1.2 but native runtime is v0.9.0\n\n// after\n// align versions:\n// go get github.com/boundaryml/baml@v0.9.0 && go mod tidy\n// ensure the baml CLI that generated the native lib is also v0.9.0","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"select {\ncase res := <-ch:\n\tif res.Error != nil {\n\t\tif strings.Contains(res.Error.Error(), \"failed to unmarshal InvocationResponse\") {\n\t\t\t// version mismatch suspected: reinit runtime/bindings\n\t\t}\n\t\treturn res.Error\n\t}\ncase <-timeoutCtx.Done():\n\treturn timeoutCtx.Err()\n}","preventionTips":["Keep BAML Go bindings and native runtime on identical versions","Avoid mixing baml CLI-generated artifacts across versions","Handle ResultCallback.Error on every callback channel receive"],"tags":["go","protobuf","ffi","callback"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}