Skip to content

[Protobuf][3/n] Wire an actor UUID validator into generated protobuf server code - #2520

Merged
mark200 merged 4 commits into
yarpc:mainfrom
mark200:add-support-for-uuid-annotation-protobuf-wire-validator-in-server
Aug 27, 2026
Merged

[Protobuf][3/n] Wire an actor UUID validator into generated protobuf server code#2520
mark200 merged 4 commits into
yarpc:mainfrom
mark200:add-support-for-uuid-annotation-protobuf-wire-validator-in-server

Conversation

@mark200

@mark200 mark200 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Description

The previous PR#2519 in this stack makes protoc-gen-yarpc-go emit an ActorUUID() accessor on every message with a reachable actor_uuid-annotated field. This PR closes the loop on the server side: it lets services install a validator that runs against those UUIDs after the request is decoded but before the user's handler executes, mirroring what thriftrw-plugin-yarpc already provides for thrift services (encoding/thrift.ActorUUIDValidator).

New public API in encoding/protobuf (actor_uuid.go):
- ActorUUIDValidatorfunc(ctx, actorUUIDs []string) error, receiving exactly what the generated ActorUUID() accessor returns.
- RegisterOption / WithActorUUIDValidator(v) — server-side registration option that installs the validator.
- ValidateActorUUID(...) and ActorUUIDValidatorFromOptions(...) — helpers called by generated code, not by users. A rejection is wrapped in an PermissionDenied YARPC error

Generated code (template in lib.go, fixture in withuuid.pb.yarpc.go):
- Build<Service>YARPCProcedures gains a variadic ...protobuf.RegisterOption
parameter, the handler struct carries the validator, and every handler whose request type has annotated paths (unary, oneway, and streaming handlers that carry a request message) calls ValidateActorUUID(ctx, validator, request.ActorUUID(), service, method) before invoking the user's handler.
- The Fx constructors accept the validator as an optional:"true" dependency.

Changed files
- encoding/protobuf/actor_uuid.go — Public server-side API
- encoding/protobuf/protoc-gen-yarpc-go/internal/lib/lib.go — Template changes; conditionally add validator fields, RegisterOption params, and per-handler ValidateActorUUID calls only for annotated services/methods
- encoding/protobuf/protoc-gen-yarpc-go/internal/lib/uuid.go — Per file UUID analysis cache; serviceHasActorUUID/methodHasActorUUID gating helpers; memoized walk results
- encoding/protobuf/protoc-gen-yarpc-go/internal/tests/withuuid/withuuid.pb.yarpc.go — Regenerated fixture showing validator plumbing

Backwards compatibility

Installing no validator is always safe: a nil validator makes the generated check a no-op, so services that regenerate but never call WithActorUUIDValidator keep their existing behaviour. Whether an empty UUID slice is acceptable is the validator's decision, so handlers on partially annotated services can still be supported by treating empty as "not provided".

Stacked PRs

  1. internal/protogen — shared descriptor-agnostic core PR#2535
  2. gogo converter + ActorUUID() emission in protoc-gen-yarpc-go PR#2519
  3. this PR — server-side validator wiring PR#2520

Test Plan

  • Unit tests for the gating helpers (annotated vs. unannotated services and methods, cross-file request types, error propagation) and for the cache-backed variants.
  • An end-to-end validator_test.go against the real generated withuuid fixture: validator receives the exact UUIDs the accessor collects, rejections surface as PermissionDenied errors naming the service and procedure and never reach the handler, nil validator and unannotated methods skip validation entirely.
  • Golden-file runner tests asserting the generated output.

RELEASE NOTES:

Wire ActorUUID validator into protobuf generated code

@mark200 mark200 changed the title Add support for UUID annotation protobuf wire validator in server [Protobuf][2/n] Wire validator in server Jul 23, 2026
@mark200
mark200 force-pushed the add-support-for-uuid-annotation-protobuf-wire-validator-in-server branch 4 times, most recently from b2d55db to f5b68cc Compare August 3, 2026 20:54
@mark200
mark200 force-pushed the add-support-for-uuid-annotation-protobuf-wire-validator-in-server branch 4 times, most recently from 58d1b8f to e76a7db Compare August 11, 2026 13:11
@mark200 mark200 changed the title [Protobuf][2/n] Wire validator in server [Protobuf][3/n] Wire validator in server Aug 11, 2026
@mark200 mark200 changed the title [Protobuf][3/n] Wire validator in server [Protobuf][3/n] Wire an actor UUID validator into generated protobuf server code Aug 11, 2026
@mark200
mark200 force-pushed the add-support-for-uuid-annotation-protobuf-wire-validator-in-server branch 2 times, most recently from ebfd0b1 to 7908d25 Compare August 11, 2026 15:08
CoolTomatos
CoolTomatos previously approved these changes Aug 13, 2026
@mark200
mark200 force-pushed the add-support-for-uuid-annotation-protobuf-wire-validator-in-server branch from 7908d25 to 96852e6 Compare August 17, 2026 13:50
@mark200
mark200 dismissed CoolTomatos’s stale review August 17, 2026 19:50

The merge-base changed after approval.

@mark200
mark200 force-pushed the add-support-for-uuid-annotation-protobuf-wire-validator-in-server branch from 96852e6 to 303fe72 Compare August 17, 2026 19:50
Comment thread encoding/protobuf/protoc-gen-yarpc-go/internal/lib/lib.go
Comment on lines +237 to +239
// server template uses it to gate the service-wide handler struct's
// validator field and the validator extraction in the Build/Fx entry
// points.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I couldn't understand this explanation

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated the comment

Comment thread encoding/protobuf/protoc-gen-yarpc-go/internal/lib/lib.go
Comment thread encoding/protobuf/actor_uuid.go
Comment thread encoding/protobuf/actor_uuid.go Outdated
Comment on lines +46 to +48
// registerConfig holds the settings a slice of RegisterOptions resolves
// to. It is threaded to generated server code via the option helpers
// below.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry, I couldn't understand any of this :(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated the comment here as well

Comment thread encoding/protobuf/actor_uuid.go
Comment thread encoding/protobuf/actor_uuid.go
Comment thread encoding/protobuf/actor_uuid.go
@mark200
mark200 force-pushed the add-support-for-uuid-annotation-protobuf-wire-validator-in-server branch from afc23d8 to 18502a6 Compare August 20, 2026 22:59
@mark200
mark200 merged commit 2f37b72 into yarpc:main Aug 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants