Skip to content

add apply changes and list transforms RPCs to world state store service - #948

Open
Devin T. Currie (DTCurrie) wants to merge 5 commits into
viamrobotics:mainfrom
DTCurrie:add-change-and-bulk-get-apis-to-wss
Open

Devin T. Currie (DTCurrie) wants to merge 5 commits into
viamrobotics:mainfrom
DTCurrie:add-change-and-bulk-get-apis-to-wss

Conversation

@DTCurrie

@DTCurrie Devin T. Currie (DTCurrie) commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Add ApplyTransformChanges and ListTransforms to the world state store service

Summary

Adds two RPCs to WorldStateStoreService:

  • ApplyTransformChanges: a standard way to write to a store. One call carries any mix of additions, updates and removals and applies them all or not at all.
  • ListTransforms: a bulk read that returns a snapshot of the whole world state as a stream of batches.

Only proto/viam/service/worldstatestore/v1/world_state_store.proto is changed by hand. The generated Go and JS code comes from the ready-for-protos workflow.

Why

The service has no write call today. The builtin store in RDK takes writes through DoCommand (add, update, remove), so every other implementation has to invent its own, and clients cannot write to a store without knowing which model it is.

It also has no way to read the world state in one consistent view. A client has to call ListUUIDs and then GetTransform once per transform, and the store can change between those calls. The motion service reads the store this way, so a Move planned while obstacles are being swapped can see part of the old set and part of the new one.

ApplyTransformChanges

rpc ApplyTransformChanges(ApplyTransformChangesRequest) returns (ApplyTransformChangesResponse) {
  option (google.api.http) = {post: "/viam/api/v1/service/worldstatestore/{name}/apply_transform_changes"};
}

enum TransformChangeOperation {
  TRANSFORM_CHANGE_OPERATION_UNSPECIFIED = 0;
  TRANSFORM_CHANGE_OPERATION_ADD = 1;
  TRANSFORM_CHANGE_OPERATION_REMOVE = 2;
  TRANSFORM_CHANGE_OPERATION_UPDATE = 3;
  TRANSFORM_CHANGE_OPERATION_UPSERT = 4;
}

message TransformChange {
  TransformChangeOperation operation = 1;
  common.v1.Transform transform = 2;
  google.protobuf.FieldMask updated_fields = 3;
}

message ApplyTransformChangesRequest {
  string name = 1;
  repeated TransformChange changes = 2;
  google.protobuf.Struct extra = 99;
}

message ApplyTransformChangesResponse {
  repeated bytes uuids = 1;
}
  • One RPC for every kind of change. A single add, update, remove or upsert is a batch of one, so SDKs can offer per-kind helpers without more RPCs.
  • Built on the change stream's shape. TransformChange has the same layout as StreamTransformChangesResponse: the kind of change in field 1, the transform in field 2 and the field mask in field 3. StreamTransformChangesResponse itself is unchanged.
  • Its own enum. TransformChangeOperation says what a request asks for; TransformChangeType says what the stream reports happened. They are separate because a request can ask for an upsert, which the stream never reports. ADD, REMOVE and UPDATE keep the same numbers as ADDED, REMOVED and UPDATED, and the two enums are to be kept in sync.
  • Applied in request order. Each change sees the effect of the ones before it. A transform is replaced atomically by sending a removal followed by an addition under the same UUID.
  • All or nothing. If any change is invalid, the call returns an error and the store is left as it was. Adding a UUID that already exists, and updating or removing one that does not, are invalid.
  • The response lists a UUID per change. uuids has one entry for each change, in request order: the UUID of the transform that change applied to.
  • What each operation needs:
operation If the UUID exists If it does not transform updated_fields
ADD Error Added The complete transform. The UUID is optional Ignored
REMOVE Removed Error Only the UUID Ignored
UPDATE Masked fields overwritten Error The UUID, plus new values for the masked fields Paths to overwrite. If empty, the stored transform is replaced whole
UPSERT Replaced whole Added The complete transform. The UUID is optional Ignored

Upserts

UPSERT adds the transform, or replaces the stored one whole if its UUID already exists, so a client can write a transform without first checking whether it is there. This is how the visualizer client already treats an add event for a transform it has.

  • An operation, not a flag on ADD. Adding and upserting behave differently, so each has its own value. ADD stays strict.
  • Not expressible otherwise. An update fails when the transform is missing, and a removal followed by an addition fails for the same reason.
  • Makes a retry safe. Repeating an upsert with the same UUID leaves the store in the same state.

Server-assigned UUIDs

An ADD or UPSERT sent without a UUID is given one by the service, and the response reports it. This matches what the builtin store's DoCommand does today. A request of [ADD (no UUID), REMOVE b2xk, ADD Ym94] returns [<assigned>, b2xk, Ym94].

  • Every implementation has to support it. It is part of the contract, so that clients can rely on it.
  • No reference within the same request. A later change cannot update or remove a transform whose UUID the service has not returned yet. Supply the UUID when a batch needs that.
  • Retries can duplicate. If the response is lost and the client retries, an addition without a UUID is added twice. With a client-supplied UUID, a retried ADD fails as "already exists" and a retried UPSERT succeeds harmlessly, so callers that retry should supply one.

Why request order rather than a fixed remove, add, update order

The builtin store's DoCommand applies changes in a fixed order of removals, additions, then updates. That order exists because the command is a JSON object keyed by add, update and remove, which has no order of its own. This request is a list, so it already has one.

  • A fixed order would misapply a valid sequence. For [ADD X, REMOVE X] it would run the removal first, which either fails the batch or leaves X present.
  • Nothing is lost: any fixed-order batch can be sent by ordering the list as removals, additions, updates.

ListTransforms

rpc ListTransforms(ListTransformsRequest) returns (stream ListTransformsResponse) {
  option (google.api.http) = {get: "/viam/api/v1/service/worldstatestore/{name}/list_transforms"};
}

message ListTransformsRequest {
  string name = 1;
  google.protobuf.Struct extra = 99;
}

message ListTransformsResponse {
  repeated common.v1.Transform transforms = 1;
}
  • A snapshot at request time. It holds every transform in the world state when the request was received, and no change made after that.
  • Sent as a stream of batches. The snapshot is every batch taken together. How a service splits transforms into batches carries no meaning.
  • Ends when complete. A stream that ends with an error is not a complete snapshot and should be discarded.
  • Can be slow. A world state can be large, and the RPC comment says so.

Why a stream rather than one response

  • gRPC messages are capped at 32 MB in our Go stack (MaxMessageSize in goutils), and a transform can carry a mesh or a point cloud. A single response would fail outright on a large world.
  • Paging with tokens cannot give a snapshot unless the server keeps one between calls.

A single transform larger than the message limit still fails, as it does with GetTransform today.

Not in this PR

  • A UUID filter on ListTransforms. It always returns everything. A filter can be added to the request later, and needs a rule for a UUID that is not found.
  • Implementations. The RDK server, client and builtin store, and the SDKs, follow in their own PRs. The builtin DoCommand write path will be rebuilt on ApplyTransformChanges.

Compatibility

Additive only: two new RPCs, five new messages and one new enum. No existing message, field or RPC is changed.

Testing

Run locally with buf 1.55.1:

  • buf lint: passes
  • buf breaking --against '.git#branch=main': passes
  • buf format -d: no changes

@viambot viambot added the safe to test committer is a member of this org label Nov 13, 2026
// TransformChange describes a single change to apply to the world state.
message TransformChange {
// The kind of change to apply. TRANSFORM_CHANGE_TYPE_UNSPECIFIED is invalid.
TransformChangeType change_type = 1;

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.

non blocking, but possible extra field here -- replace_if_present on add (so people can do upserts)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's how the visualizer client handles it. If an add event comes through on an existing event, we treat it as an update, so we can define that here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Defined all the change operations as their own enum and added the upsert type, I think that is a cleaner split.

@DTCurrie Devin T. Currie (DTCurrie) added the ready-for-protos add this when you want protos to compile on every commit label Nov 13, 2026
@DTCurrie Devin T. Currie (DTCurrie) removed the ready-for-protos add this when you want protos to compile on every commit label Nov 13, 2026
@viam-overwatch

Copy link
Copy Markdown

Hey Devin T. Currie (@DTCurrie) — this PR has been approved and CI has been green for 3+ business days. Ready to merge?

Auto-comment from overwatch. Will not re-nudge for 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test committer is a member of this org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants