{"record":{"id":"e7867ae02e179921","repo":"BoundaryML/baml","slug":"failed-to-decode-object-handle-w","errorCode":null,"errorMessage":"failed to decode object handle: %w","messagePattern":"failed to decode object handle: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/callbacks.go","lineNumber":248,"sourceCode":"\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)\n\t\t\t\tif decodeErr != nil {\n\t\t\t\t\tsafeSend(callback.channel, ResultCallback{Error: fmt.Errorf(\"failed to decode object handle: %w\", decodeErr)})\n\t\t\t\t} else {\n\t\t\t\t\tsafeSend(callback.channel, ResultCallback{HasData: true, Data: decoded})\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\tsafeSend(callback.channel, ResultCallback{Error: fmt.Errorf(\"unexpected result type in InvocationResponse: %T\", success.GetResult())})\n\t\t\t}\n\t\t}\n\tdefault:\n\t\tsafeSend(callback.channel, ResultCallback{Error: fmt.Errorf(\"unexpected response type in InvocationResponse\")})\n\t}\n\n\tsafeClose(callback.channel)\n\tcallbackMutex.Lock()\n\tdefer callbackMutex.Unlock()\n\tdeleteCallback(id)\n}\n\nfunc create_unique_id(ctx context.Context, onTick OnTickCallbackData) (uint32, chan ResultCallback) {","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/callbacks.go#L230-L266","documentation":"Within a valid InvocationResponseSuccess, the result oneof must contain an Object carrying a raw object handle. If decodeRawObjectImpl fails to decode that object (bad handle bytes, unknown type id, runtime mismatch), the error is wrapped as 'failed to decode object handle' and delivered as the callback result.","triggerScenarios":"build_request_from_c (or similar) returns an InvocationResponseSuccess_Object whose Object payload cannot be decoded by decodeRawObjectImpl in the current runtime — e.g. handle created by a different runtime instance, corrupted bytes, or unsupported object type id.","commonSituations":"Sharing object handles across multiple BamlRuntime instances, mixing runtime versions, or the native side returning an object type the Go decoder doesn't know.","solutions":["Read the wrapped decodeErr to see whether it's an unknown type or malformed handle bytes.","Ensure the callback runtime (callback.runtime) is the same BamlRuntime instance that produced the object.","Align BAML Go binding and native runtime versions.","If using multiple runtimes, keep object handles scoped to the runtime that created them."],"exampleFix":"// before\nhandle, err := baml.BuildRequestFromC(otherRuntime, req) // object bound to otherRuntime\n\n// after\nhandle, err := baml.BuildRequestFromC(currentRuntime, req) // use the same runtime instance","handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":"res := <-ch\nif res.Error != nil {\n\tif strings.Contains(res.Error.Error(), \"failed to decode object handle\") {\n\t\treturn fmt.Errorf(\"object handle unusable, recreate request with same runtime: %w\", res.Error)\n\t}\n\treturn res.Error\n}","preventionTips":["Use one BamlRuntime instance per set of object handles","Never share handles across runtime instances","Keep runtime and Go bindings versions aligned"],"tags":["go","ffi","decoding","object-handle"],"backgroundTag":"unexpected-response-shape","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}