fix: pass a non-empty participantId to enable SDS-R

The pre-nim-ffi binding had no participantId concept; mirroring that
with an empty id disables SDS-R, but the new libsds unwrap path
SIGSEGVs on real received messages in that configuration. Generate a
random per-manager participantId so SDS-R is enabled, matching the
nim-ffi 0.2.0 SDS-R/retrieval-hint design intent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Ivan FB 2026-06-11 23:31:43 +02:00
parent a5a47f8e6e
commit bf71cacb9a
No known key found for this signature in database
GPG Key ID: DF0C67A04C543270

View File

@ -110,6 +110,8 @@ package sds
*/
import "C"
import (
"crypto/rand"
"encoding/hex"
"errors"
"sync"
"unsafe"
@ -132,6 +134,15 @@ var eventNames = []string{
eventPeriodicSync,
}
// randomParticipantID returns a random hex-encoded SDS-R participant identity.
func randomParticipantID() (string, error) {
var b [16]byte
if _, err := rand.Read(b[:]); err != nil {
return "", err
}
return hex.EncodeToString(b[:]), nil
}
//export SdsGoCallback
func SdsGoCallback(ret C.int, msg *C.char, len C.size_t, resp unsafe.Pointer) {
if resp != nil {
@ -199,12 +210,17 @@ func NewReliabilityManager(logger *zap.Logger) (*ReliabilityManager, error) {
rm.logger.Info("creating new reliability manager")
// Empty participantId keeps plain SDS (causal history, acks, missing-deps)
// and disables SDS-R repair — matching the pre-nim-ffi binding's behavior.
createReq := sdsCreateReq{Config: sdsConfig{ParticipantID: ""}}
// participantId is the per-manager SDS-R identity. A non-empty id enables
// SDS-R (repair/retrieval); we generate a random one so each manager has a
// distinct identity.
participantID, err := randomParticipantID()
if err != nil {
return nil, errorspkg.Wrap(err, "failed to generate participant id")
}
createReq := sdsCreateReq{Config: sdsConfig{ParticipantID: participantID}}
var ret int
err := withReqCbor(createReq, func(ptr unsafe.Pointer, length C.size_t) {
err = withReqCbor(createReq, func(ptr unsafe.Pointer, length C.size_t) {
var data []byte
ret, data = sdsCall(func(resp unsafe.Pointer) {
rm.rmCtx = C.cGoSdsCreate(ptr, length, resp)