Skip to content

fix(server): carry referrer pull responses as protojson bytes - #2463

Merged
muscariello merged 3 commits into
agntcy:mainfrom
jay23606:pr-go/2461-bug-autosync-cannot-transfer-any-referre
Nov 6, 2026
Merged

muscariello merged 3 commits into
agntcy:mainfrom
jay23606:pr-go/2461-bug-autosync-cannot-transfer-any-referre

Conversation

@jay23606

@jay23606 jay23606 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Bug

Autosync pulls a record from a trusted peer and then pulls its referrers (signatures, public keys, scan reports). Every referrer pull failed to decode on the receiving node. PullReferrerResponse carried a *corev1.RecordReferrer, whose Data is a structpb.Struct. The msgpack codec used by go-libp2p-gorpc cannot decode the structpb.Value oneof, so the response was rejected whatever the referrer contained. The record was ingested unsigned and the failure was only logged at Warn.

Change

PullReferrerResponse now carries the referrer as protojson bytes, the same way PullResponse carries the record. The serving side marshals with protojson.Marshal, and the client decodes with protojson.Unmarshal. structpb no longer crosses the msgpack wire.

Testing

  • go test -C server ./routing/rpc/ -run TestPullReferrer_ResponseSurvivesMsgpack -count=1 -v passes on the fix. On the base commit it fails with msgpack decode error ... structpb.isValue_Kind.
  • go test -C server ./routing/... -count=1: server/routing/rpc and server/routing/autosync pass. server/routing fails in TestPublishList_ValidMultiSkillQuery on Windows, where temp-directory cleanup cannot remove a Badger vlog file still in use. That test does not touch the referrer path.

Regression test: fails on base twice (/msgpack decode error.*structpb.isValue_Kind/), passes on fix twice (go test -C server ./routing/rpc/ -run TestPullReferrer_ResponseSurvivesMsgpack -count=1 -v)

Fixes #2461

@jay23606
jay23606 requested a review from a team as a code owner November 6, 2026 13:01
@github-actions github-actions Bot added the size/S Denotes a PR that changes 50-199 lines label Nov 6, 2026

@muscariello muscariello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The fix is correct and minimal, and the regression test fails on base with the error from #2461. I also ran a referrer through the whole path (serve, msgpack, referrerFromResponse) with nested, unicode and large-number data. It comes back proto.Equal to the original, with identical canonical Marshal() bytes. Two small things:

  1. The test doesn't cover the decode side (inline). It passes for any bytes in Data, so it would not notice a broken referrerFromResponse.
  2. server/go.mod: github.com/ugorji/go/codec is // indirect, but the test now imports it directly. go mod tidy in server/ moves it to the direct block. Please run it so the next person doesn't get the churn.

Optional: one line in the description on old and new peers. A new server talking to a v1.8.0 client gives a nil referrer, which verifyReferrer rejects. A v1.8.0 server talking to a new client fails in protojson.Unmarshal on empty Data. Both fail the way they do today, so nothing regresses.

The two-node test #2461 suggests isn't here. I'm fine with that as a follow-up, since the codec round trip is what regressed.


var got PullReferrerResponse
require.NoError(t, codec.NewDecoder(&wire, h).Decode(&got))
require.Equal(t, out, got)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only shows the Data bytes survive msgpack, so it passes for any bytes. Decode with referrerFromResponse(&got) and compare with proto.Equal against the original referrer. I ran that and it passes, so it costs one extra line and covers the client side too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test now decodes the received response with referrerFromResponse and checks it with proto.Equal against the served referrer, so the client-side decode is covered as well as the msgpack round trip.

@muscariello muscariello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same change as the inline comment on line 63, written as three suggestions to apply together. server/go.mod isn't in the diff, so it can't be suggested: go mod tidy in server/ does it.

"github.com/agntcy/dir/server/types"
"github.com/stretchr/testify/require"
"github.com/ugorji/go/codec"
"google.golang.org/protobuf/types/known/structpb"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import proto for the comparison in the last suggestion. The three suggestions go together.

Suggested change
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"

Comment on lines +39 to +47
api := &RPCAPI{service: &Service{
store: &peerStore{present: true},
refStore: referrerStore{referrer: &corev1.RecordReferrer{
Type: corev1.SignatureReferrerType,
ReferrerRef: &corev1.ReferrerRef{Cid: referrerCID},
Data: data,
}},
gate: peerGate{servable: true},
}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the served referrer in want, so the decoded one can be compared with it.

Suggested change
api := &RPCAPI{service: &Service{
store: &peerStore{present: true},
refStore: referrerStore{referrer: &corev1.RecordReferrer{
Type: corev1.SignatureReferrerType,
ReferrerRef: &corev1.ReferrerRef{Cid: referrerCID},
Data: data,
}},
gate: peerGate{servable: true},
}}
want := &corev1.RecordReferrer{
Type: corev1.SignatureReferrerType,
ReferrerRef: &corev1.ReferrerRef{Cid: referrerCID},
Data: data,
}
api := &RPCAPI{service: &Service{
store: &peerStore{present: true},
refStore: referrerStore{referrer: want},
gate: peerGate{servable: true},
}}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The served referrer is now held in a want variable that is passed to the referrer store, so the decoded result can be compared against it.


var got PullReferrerResponse
require.NoError(t, codec.NewDecoder(&wire, h).Decode(&got))
require.Equal(t, out, got)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decode what the receiving node would get and compare it with what the serving node held. With the three suggestions applied, gofmt and go vet are clean and the test passes.

Suggested change
require.Equal(t, out, got)
require.Equal(t, out, got)
// The receiving node decodes what the serving node held.
referrer, err := referrerFromResponse(&got)
require.NoError(t, err)
require.True(t, proto.Equal(want, referrer))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the msgpack round trip the test now decodes the response through referrerFromResponse and asserts proto.Equal with the served referrer.

@muscariello

Copy link
Copy Markdown
Member

Thanks, the test changes look good.

One thing is still open from my first review: server/go.mod has github.com/ugorji/go/codec v1.3.1 // indirect (line 196), but the new test imports it directly. Please run go mod tidy in server/, which moves it to the direct block.

Minor: the description says the test fails on base with msgpack decode error ... structpb.isValue_Kind. With the referrerFromResponse assertion it now fails to compile on base instead, since that function is new in this PR. Worth a one-line fix in the Testing section.

Otherwise this looks good to me.

@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/routing/rpc/rpc.go 71.4% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@muscariello muscariello left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@muscariello
muscariello added this pull request to the merge queue Nov 6, 2026
Merged via the queue into agntcy:main with commit e52fe45 Nov 6, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 50-199 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Autosync cannot transfer any referrer — signatures and scan reports never reach the receiving node

2 participants